Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- using namespace std;
- #define mp make_pair
- #define pb push_back
- const long long INF = 1e9;
- int main()
- {
- #ifdef _DEBUG
- freopen("in.txt", "r", stdin);
- freopen("out.txt", "w", stdout);
- #endif
- long long n; scanf("%I64d", &n);
- vector<long long> t(n), c(n);
- for(long long i = 0; i < n; i++)
- scanf("%I64d%I64d", &t[i], &c[i]);
- vector<vector<long long>> z(n + 1, vector<long long>(4001, INF));
- z[1][1999] = 0;
- z[1][2000 + t[0]] = c[0];
- for(long long i = 1; i < n; i++){
- for(long long j = 0; j <= 4000; j++){
- if(z[i][j] != INF){
- if(j > 0)
- z[i + 1][j - 1] = min(z[i + 1][j - 1], z[i][j]);
- z[i + 1][min(4000LL, j + t[i])] = min(z[i + 1][min(4000LL, j + t[i])], z[i][j] + c[i]);
- }
- }
- }
- long long res = INF;
- for(long long i = 2000; i <= 4000; i++)
- if(z[n][i] < res){
- res = z[n][i];
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement