比赛 test2 评测结果 AAAAAAAAAA
题目名称 烤鸡翅 最终得分 100
用户昵称 kZime 运行时间 0.220 s
代码语言 C++ 内存使用 4.18 MiB
提交时间 2017-03-12 20:27:17
显示代码纯文本
/*kZime*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#define MAXN 253333 
#define ll long long


using namespace std;

priority_queue<int> check;
ll ne[MAXN], n, ha, co[MAXN], ans; 
inline ll read() {
	int k = 0, f = 1; char c = getchar();
	for(; !isdigit(c); c = getchar())if(c == '-') f = -1;
	for(; isdigit(c); c = getchar()) k = k * 10 + c - '0';
	return k * f;
}


int main() {
#ifndef LOCAL
	freopen("wing.in", "r", stdin);
	freopen("wing.out", "w", stdout);
#else
	freopen("in.txt", "r", stdin);
#endif
	n = read();
	for(ll i = 1; i <= n; i++)co[i] = read();
	for(ll i = 1; i <= n; i++)ne[i] = read();
	
	for(ll i = 1; i <= n ;i++) {
		ha += co[i];
		ha -= ne[i];
		ans++;
		check.push(ne[i]);
		if(ha < 0) {//没有存货了,考虑更改之前状态 
			if(!check.empty()) {
				ha += check.top();
				ans--;
				check.pop();
			}
		}
	}
	printf("%d",ans);
	return 0;
}