Submission #39692

#TimeUsernameProblemLanguageResultExecution timeMemory
3969214kg스트랩 (JOI14_straps)C++11
100 / 100
13 ms1136 KiB
#include <stdio.h> #include <algorithm> #define INF 2000000000 #define max2(x,y) (x>y?x:y) #define min2(x,y) (x<y?x:y) using namespace std; int n, dp[2001]; pair<int, int> in[2001]; int main() { int x, y, w, out = 0; scanf("%d", &n); for (int i = 2; i <= n; i++) dp[i] = -INF; for (int i = 1; i <= n; i++) scanf("%d %d", &in[i].first, &in[i].second); sort(in + 1, in + n + 1); for (int k = n; k >= 1; k--) { x = in[k].first - 1, y = in[k].second; if (x < 0) { for (int i = 0; i < n; i++) dp[i] = max2(dp[i], dp[i + 1] + y); } else { for (int i = n; i >= 0; i--) { w = min2(n, i + x); dp[w] = max2(dp[w], dp[i] + y); } } } for (int i = 0; i <= n; i++) out = max2(out, dp[i]); printf("%d", out); }

Compilation message (stderr)

straps.cpp: In function 'int main()':
straps.cpp:13:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
straps.cpp:15:74: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= n; i++) scanf("%d %d", &in[i].first, &in[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...