Submission #25191

#TimeUsernameProblemLanguageResultExecution timeMemory
25191junodeveloper스트랩 (JOI14_straps)C++14
100 / 100
13 ms17692 KiB
#include<cstdio> #include<iostream> #include<vector> #include<algorithm> #define INF (int)2e9 using namespace std; int e[2002][2002]; pair<int, int> p[2002]; int main() { int n, i; scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d%d", &p[i].first, &p[i].second); p[i].first *= -1; p[i].second *= -1; } sort(p + 1, p + n + 1); for (i = 2; i <= n; i++) e[0][i] = -INF; for (i = 1; i <= n; i++) { int a = -p[i].first; int b = -p[i].second; if (!a) break; for (int j = n; j >= 0; j--) { e[i][j] = e[i - 1][j]; int t = max(0, j - a + 1); if (e[i - 1][t] != -INF) e[i][j] = max(e[i][j], e[i - 1][t] + b); } } int last = i - 1; vector<int> v; for (; i <= n; i++) if (-p[i].second > 0) v.push_back(-p[i].second); int res = -INF, sum = 0; for (i = 0; i <= n; i++) { res = max(res, e[last][i] + sum); if (i < v.size()) sum += v[i]; } printf("%d", res); return 0; }

Compilation message (stderr)

straps.cpp: In function 'int main()':
straps.cpp:37:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (i < v.size()) sum += v[i];
               ^
straps.cpp:11:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
                    ^
straps.cpp:13:49: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &p[i].first, &p[i].second);
                                                 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...