比赛 test2 评测结果 AAAAAAAAAA
题目名称 烤鸡翅 最终得分 100
用户昵称 kZime 运行时间 0.220 s
代码语言 C++ 内存使用 4.18 MiB
提交时间 2017-03-12 20:27:17
显示代码纯文本
  1. /*kZime*/
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <cmath>
  6. #include <vector>
  7. #include <queue>
  8. #include <algorithm>
  9. #define MAXN 253333
  10. #define ll long long
  11.  
  12.  
  13. using namespace std;
  14.  
  15. priority_queue<int> check;
  16. ll ne[MAXN], n, ha, co[MAXN], ans;
  17. inline ll read() {
  18. int k = 0, f = 1; char c = getchar();
  19. for(; !isdigit(c); c = getchar())if(c == '-') f = -1;
  20. for(; isdigit(c); c = getchar()) k = k * 10 + c - '0';
  21. return k * f;
  22. }
  23.  
  24.  
  25. int main() {
  26. #ifndef LOCAL
  27. freopen("wing.in", "r", stdin);
  28. freopen("wing.out", "w", stdout);
  29. #else
  30. freopen("in.txt", "r", stdin);
  31. #endif
  32. n = read();
  33. for(ll i = 1; i <= n; i++)co[i] = read();
  34. for(ll i = 1; i <= n; i++)ne[i] = read();
  35. for(ll i = 1; i <= n ;i++) {
  36. ha += co[i];
  37. ha -= ne[i];
  38. ans++;
  39. check.push(ne[i]);
  40. if(ha < 0) {//没有存货了,考虑更改之前状态
  41. if(!check.empty()) {
  42. ha += check.top();
  43. ans--;
  44. check.pop();
  45. }
  46. }
  47. }
  48. printf("%d",ans);
  49. return 0;
  50. }
  51.  
  52.