Guest User

3 USACO

a guest
Apr 5th, 2016
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. //< in.txt > out.txt
  2.  
  3. #include <algorithm>
  4. #include <bitset>
  5. #include <cmath>
  6. #include <cstdio>
  7. #include <cstring>
  8. #include <deque>
  9. #include <iomanip>
  10. #include <iostream>
  11. #include <queue>
  12. #include <map>
  13. #include <numeric>
  14. #include <set>
  15. #include <sstream>
  16. #include <stack>
  17. #include <utility>
  18. #include <vector>
  19. #include <fstream>
  20.  
  21. #define INF 1000000000
  22. #define FOR(i, a, b) for(int i=int(a); i<int(b); i++)
  23. #define FORC(cont, it) for(typeof((cont).begin()) it = (cont).begin(); it != (cont).end(); it++)
  24. #define pb push_back
  25.  
  26. using namespace std;
  27.  
  28. typedef long long ll;
  29. typedef pair<int, int> ii;
  30. typedef vector<int> vi;
  31. typedef vector<ii> vii;
  32. typedef vector<vi> vvi;
  33.  
  34. #define maxN 100000
  35.  
  36. struct Data {
  37.     ll cost;
  38.     bool operator <(const Data &r) const {
  39.         return cost > r.cost;
  40.     }
  41. };
  42.  
  43. ll A[maxN], B[maxN];
  44.  
  45. int main() {
  46.     ifstream in("landscape.in");
  47.     ofstream out("landscape.out");
  48.     ll N, X, Y, Z;
  49.     while (in >> N >> X >> Y >> Z) {
  50.         FOR(i, 0, N) in >> A[i] >> B[i];
  51.         ll acum = 0, ans = 0;
  52.         priority_queue<Data> q1, q2;
  53.         FOR(i, 0, N) {
  54.             while (A[i] > B[i]) {
  55.                 ll toPay = Y;
  56.                 if (!q1.empty()&&q1.top().cost+i*Z<Y) {
  57.                     toPay = q1.top().cost + i*Z;
  58.                     q1.pop();
  59.                 }
  60.                 ans += toPay;
  61.                 q2.push(Data{ -i*Z - toPay });
  62.                 A[i]--;
  63.             }
  64.             while(A[i]<B[i]) {
  65.                 ll toPay = X;
  66.                 if (!q2.empty() && q2.top().cost+i*Z<X) {
  67.                     toPay = q2.top().cost + i*Z;
  68.                     q2.pop();
  69.                 }
  70.                 ans += toPay;
  71.                 q1.push(Data{ -i*Z - toPay });
  72.                 A[i]++;
  73.             }
  74.         }
  75.         out << ans << endl;
  76.     }
  77.     return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment