Submission #899367

#TimeUsernameProblemLanguageResultExecution timeMemory
899367MongHwa스트랩 (JOI14_straps)C++17
100 / 100
6 ms604 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; #define X first #define Y second #define INF 0x7f7f7f7f int dp[2005]; vector<pair<int, int>> pos; vector<int> zero; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; fill(dp, dp+n+1, -INF); for(int i = 0; i < n; i++) { int a, b; cin >> a >> b; if(a > 0) pos.push_back({a, b}); else zero.push_back(b); } dp[1] = 0; for(int i = 0; i < (int)pos.size(); i++) { for(int j = n; j >= max(1, n-pos[i].X+1); j--) dp[n] = max(dp[n], dp[j] + pos[i].Y); for(int j = n-1; j >= max(1, pos[i].X-1); j--) dp[j] = max(dp[j], dp[j-pos[i].X+1] + pos[i].Y); } sort(zero.begin(), zero.end(), greater<>()); int ans = 0; int sum = 0; for(int i = 1; i <= n; i++) { if(i <= (int)zero.size() && zero[i-1] >= 0) sum += zero[i-1]; ans = max(ans, dp[i] + sum); } if(!zero.empty()) ans = max(ans, zero[0]); cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...