Submission #157196

#TimeUsernameProblemLanguageResultExecution timeMemory
157196DrumpfTheGodEmperor스트랩 (JOI14_straps)C++14
45 / 100
53 ms32032 KiB
#include <bits/stdc++.h> #define int long long #define bp __builtin_popcountll #define pb push_back #define in(s) freopen(s, "r", stdin); #define out(s) freopen(s, "w", stdout); #define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\ freopen((string(s) + "." + end2).c_str(), "w", stdout); #define fi first #define se second #define bw(i, r, l) for (int i = r - 1; i >= l; i--) #define fw(i, l, r) for (int i = l; i < r; i++) #define fa(i, x) for (auto i: x) using namespace std; const int mod = 1e9 + 7, inf = 1061109567; const long long infll = 4485090715960753727; const int N = 2005; int n, dp[N][N]; struct Line { int a, b; bool operator<(const Line &rhs) const { return a > rhs.a; } } l[N]; signed main() { #ifdef BLU in("blu.inp"); #endif ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; fw (i, 0, n) cin >> l[i].a >> l[i].b; sort(l, l + n); //If we have the subset we want, sort the vertexes in decreasing max children. memset(dp, -63, sizeof dp); dp[0][1] = 0; fw (i, 0, n) fw (j, 1, n + 1) if (dp[i][j] != -infll) { //We can have j more children. dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); dp[i + 1][j - 1 + l[i].a] = max(dp[i + 1][j - 1 + l[i].a], dp[i][j] + l[i].b); } int ans = 0; fw (i, 1, n + 1) fw (j, 0, n + 1) ans = max(ans, dp[i][j]); cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...