记录编号 |
568265 |
评测结果 |
AAAAAAAAAA |
题目名称 |
烤鸡翅 |
最终得分 |
100 |
用户昵称 |
yrtiop |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.159 s |
提交时间 |
2021-12-22 13:17:40 |
内存使用 |
3.21 MiB |
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn = 3e5 + 5;
int n,a[maxn],c[maxn];
priority_queue<int> q;
int main() {
freopen("wing.in","r",stdin);
freopen("wing.out","w",stdout);
scanf("%d",&n);
for(int i = 1;i <= n;++ i)scanf("%d",&a[i]);
for(int i = 1;i <= n;++ i)scanf("%d",&c[i]);
long long sum = 0;
long long ans = 0;
for(int i = 1;i <= n;++ i) {
sum += a[i];
if(sum >= c[i]) {
++ ans;
sum -= c[i];
q.push(c[i]);
}
else {
if(q.empty())continue ;
int v = q.top();
if(v > c[i]) {
q.pop();
sum += v - c[i];
q.push(c[i]);
}
}
}
printf("%lld",ans);
fclose(stdin);
fclose(stdout);
return 0;
}