Submission #132804

#TimeUsernameProblemLanguageResultExecution timeMemory
132804SamAndCloud Computing (CEOI18_clo)C++17
100 / 100
1243 ms2296 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2003; const long long INF = 100005000000009; struct ban { bool z; int q, x, g; }; bool operator<(const ban& a, const ban& b) { if (a.x < b.x) return true; if (a.x > b.x) return false; return a.z < b.z; } int n, m; ban a[N + N]; long long dp[N * 55]; long long ndp[N * 55]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { a[i].z = true; scanf("%d%d%d", &a[i].q, &a[i].x, &a[i].g); } scanf("%d", &m); for (int i = n + 1; i <= n + m; ++i) { a[i].z = false; scanf("%d%d%d", &a[i].q, &a[i].x, &a[i].g); } sort(a + 1, a + n + m + 1); for (int i = 1; i <= n * 50; ++i) dp[i] = -INF; for (int i = n + m; i >= 1; --i) { memset(ndp, -INF, sizeof ndp); if (a[i].z) { for (int j = 0; j <= n * 50; ++j) { ndp[j] = max(ndp[j], dp[j]); if (j + a[i].q <= n * 50) ndp[j + a[i].q] = max(ndp[j + a[i].q], dp[j] - a[i].g); } } else { for (int j = 0; j <= n * 50; ++j) { ndp[j] = max(ndp[j], dp[j]); if (j - a[i].q >= 0) ndp[j - a[i].q] = max(ndp[j - a[i].q], dp[j] + a[i].g); } } memcpy(dp, ndp, sizeof ndp); } long long ans = 0; for (int j = 0; j <= n * 50; ++j) ans = max(ans, dp[j]); cout << ans << endl; return 0; }

Compilation message (stderr)

clo.cpp: In function 'int main()':
clo.cpp:43:21: warning: overflow in implicit constant conversion [-Woverflow]
         memset(ndp, -INF, sizeof ndp);
                     ^~~~
clo.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
clo.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &a[i].q, &a[i].x, &a[i].g);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &m);
     ~~~~~^~~~~~~~~~
clo.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &a[i].q, &a[i].x, &a[i].g);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...