fork download
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. #define sti string
  4. #define bit(n,i) ((n>>i)&1)
  5. #define itachi ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  6. #define maxn 500005
  7. #define int long long
  8. #define fi first
  9. #define se second
  10. using namespace std;
  11.  
  12. int n,x,y,z;
  13. const int INF = 4e18;
  14.  
  15. signed main(){
  16. itachi
  17. cin>>n>>x>>y>>z;
  18. int sum = 0;
  19. priority_queue<int,vector<int>,greater<int>> thua,thieu;
  20. for(int i=1;i<=n;i++) {
  21. int a,b;
  22. cin>>a>>b;
  23. int cur_cost = i * z;
  24. if(a > b){
  25. for(int zz=0;zz< a- b;zz++){
  26. sum += y;
  27. int change=INF,top;
  28. if(!thieu.empty()){
  29. top = thieu.top();
  30. change = cur_cost + thieu.top() - y;
  31. }
  32. if(change < 0 ){
  33. sum += change;
  34. thieu.pop();
  35. thua.push(-cur_cost - cur_cost - top);
  36. }
  37. else thua.push(-cur_cost - y);
  38. }
  39. }
  40. else if(a<b) {
  41. for(int zz=0;zz<b-a;zz++){
  42. sum += x;
  43. int change=INF,top;
  44. if(!thua.empty()){
  45. top = thua.top();
  46. change = cur_cost + thua.top() - x;
  47. }
  48. if(change < 0 ){
  49. sum += change;
  50. thua.pop();
  51. thieu.push(-cur_cost - cur_cost - top);
  52. }
  53. else thieu.push(-cur_cost - x);
  54. }
  55. }
  56. }
  57. cout<<sum;
  58. return 0;
  59. }
  60.  
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
Standard output is empty