比赛 2024暑假C班集训7 评测结果 AAAAAAAAAA
题目名称 买卖 最终得分 100
用户昵称 darkMoon 运行时间 0.278 s
代码语言 C++ 内存使用 4.68 MiB
提交时间 2024-07-07 08:59:03
显示代码纯文本
  1. #include<bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4. ifstream fin("buy.in");
  5. ofstream fout("buy.out");
  6. auto mread = [](){
  7. int x;
  8. fin >> x;
  9. return x;
  10. };
  11. const int N = 1e5 + 5;
  12. int n = mread(), a[N], b[N];
  13. signed main(){
  14. for(int i = 1; i <= n; i ++)
  15. a[i] = mread();
  16. for(int i = 1; i <= n; i ++)
  17. b[i] = mread();
  18. priority_queue<int, vector<int>, greater<int> > q;
  19. int ans = 0;
  20. for(int i = 1; i <= n; i ++){
  21. q.push(a[i]);
  22. if(b[i] > q.top()){
  23. int tmp = b[i] - q.top();
  24. q.pop();
  25. ans += tmp;
  26. q.push(b[i]);
  27. }
  28. }
  29. fout << ans;
  30. return 0;
  31. }