Advertisement
kokokozhina

Untitled

Sep 29th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4.  
  5. using namespace std;
  6.  
  7. #define mp make_pair
  8. #define pb push_back
  9.  
  10. const long long INF = 1e9;
  11.  
  12. int main()
  13. {
  14. #ifdef _DEBUG
  15.     freopen("in.txt", "r", stdin);
  16.     freopen("out.txt", "w", stdout);
  17. #endif
  18.     long long n; scanf("%I64d", &n);
  19.     vector<long long> t(n), c(n);
  20.     for(long long i = 0; i < n; i++)
  21.         scanf("%I64d%I64d", &t[i], &c[i]);
  22.  
  23.     vector<vector<long long>> z(n + 1, vector<long long>(4001, INF));
  24.  
  25.     z[1][1999] = 0;
  26.     z[1][2000 + t[0]] = c[0];
  27.     for(long long i = 1; i < n; i++){
  28.         for(long long j = 0; j <= 4000; j++){
  29.             if(z[i][j] != INF){
  30.                 if(j > 0)
  31.                     z[i + 1][j - 1] = min(z[i + 1][j - 1], z[i][j]);
  32.                 z[i + 1][min(4000LL, j + t[i])] = min(z[i + 1][min(4000LL, j + t[i])], z[i][j] + c[i]);
  33.             }
  34.         }
  35.     }
  36.     long long res = INF;
  37.     for(long long i = 2000; i <= 4000; i++)
  38.         if(z[n][i] < res){
  39.             res = z[n][i];
  40.         }
  41.     cout << res << endl;
  42.  
  43.     return 0;  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement