Advertisement
chaosagent

USACO 2016 Open Platinum Landscaping

Apr 6th, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <cstdio>
  2. #include <queue>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     FILE *fin = fopen("landscape.in", "r");
  9.     FILE *fout = fopen("landscape.out", "w");
  10.     long long n, x, y, z;
  11.     fscanf(fin, "%lld %lld %lld %lld", &n, &x, &y, &z);
  12.     long long result = 0;
  13.     priority_queue<long long> q1;
  14.     priority_queue<long long> q2;
  15.     for (int i = 0; i < n; i++) {
  16.         int a, b;
  17.         fscanf(fin, "%d %d", &a, &b);
  18.         while (a > b) {
  19.             long long cost = y;
  20.             if (q2.size() && -q2.top() + i * z < y) {
  21.                 cost = -q2.top() + i * z;
  22.                 q2.pop();
  23.             }
  24.             result += cost;
  25.             q1.push(i * z + cost);
  26.             a--;
  27.         }
  28.         while (b > a) {
  29.             long long cost = x;
  30.             if (q1.size() && -q1.top() + i * z < x) {
  31.                 cost = -q1.top() + i * z;
  32.                 q1.pop();
  33.             }
  34.             result += cost;
  35.             q2.push(i * z + cost);
  36.             b--;
  37.         }
  38.     }
  39.     fprintf(fout, "%lld\n", result);
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement