Advertisement
cheater2k

Educational Codeforces Round 16 - Problem E

Jan 19th, 2017
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ff(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
  5. #define fod(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
  6. #define ll long long
  7. #define pb push_back
  8. #define x first
  9. #define y second
  10. typedef pair <int, int> ii;
  11. typedef vector <int> vi;
  12. const int N = 10000010, INF = (int)1e9, mod = (int)1e9 + 7;
  13.  
  14. ll n, x, y;
  15. ll f[N];
  16. deque <int> q;
  17.  
  18. int main() {
  19.     ios_base::sync_with_stdio(false); cin.tie(0);
  20.     cin >> n >> x >> y;
  21.     for (int i = 1; i <= n; i++) {
  22.         int t = i % 2; f[i] = f[i-1] + x;
  23.         ll r = 1e17;
  24.         while(!q.empty() && q.front() < ((i + 1) / 2)) q.pop_front();
  25.         if (!q.empty()) r = f[q.front()] + 2 * q.front() * x;
  26.         f[i] = min(f[i], r + y - i * x);
  27.         while(!q.empty() && f[q.back()] + 2 * q.back() * x >= f[i] + 2 * i * x) q.pop_back();
  28.         q.push_back(i);
  29.     }
  30.     cout << f[n] << endl;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement