Submission #1065420

#TimeUsernameProblemLanguageResultExecution timeMemory
1065420_rain_Jobs (BOI24_jobs)C++14
0 / 100
2058 ms14884 KiB
#include<bits/stdc++.h> using namespace std; using i64 = long long; #define debug false const int maxn = 3e5; vector<int> graph[maxn+2]; int x[maxn+2] , p[maxn+2]; bool root[maxn+2]; int n; i64 s , pre[maxn+2] , f[maxn+2] , dp[maxn+2]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> s; for (int i = 1; i <= n; ++i){ cin >> x[i] >> p[i]; } for (int i = 1; i <= n; ++i) pre[i] = pre[i - 1] + x[i]; f[0] = s; for (int i = 1; i <= n; ++i){ int pos = i; for (int j = i; j >= 1; --j){ dp[i] = max(dp[i] , dp[j]); if (p[j]==0){ pos = j; break; } } dp[i] = max(dp[i] , f[pos - 1] + pre[i] - pre[pos - 1]); dp[i] = max(dp[i] , f[pos - 1]); f[i] = max(dp[i] , f[i - 1]); } cout << dp[n] - s; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...