Submission #95322

#TimeUsernameProblemLanguageResultExecution timeMemory
95322Retro3014만두 (JOI14_ho_t2)C++17
100 / 100
15 ms632 KiB
#include <iostream> #include <vector> #include <algorithm> #include <stdio.h> using namespace std; #define INF 1000000000 #define MAX_M 10005 int N, M; vector<int> P; vector<pair<int, int> > B; int DP[MAX_M+1]; int main(){ scanf("%d%d", &M, &N); for(int i=0; i<M; i++){ int x; scanf("%d", &x); P.push_back(x); }sort(P.begin(), P.end()); for(int i=0; i<N; i++){ int x, y; scanf("%d%d", &x, &y); B.push_back(make_pair(x, y)); } for(int i=1; i<=M; i++) DP[i] = INF; for(int i=0; i<B.size(); i++){ for(int j=M-B[i].first; j>=0; j--){ DP[j+B[i].first] = min(DP[j+B[i].first], DP[j]+B[i].second); } if(B[i].first>M){ DP[M] = min(DP[M], B[i].second); } int T = INF; for(int j=M; j>=0; j--){ T = min(T, DP[j]); DP[j] = T; } } int ans = 0; int sum = 0; for(int i=1; i<=M; i++){ sum+=P.back(); P.pop_back(); ans = max(ans, sum-DP[i]); } printf("%d", ans); return 0; }

Compilation message (stderr)

2014_ho_t2.cpp: In function 'int main()':
2014_ho_t2.cpp:28:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<B.size(); i++){
               ~^~~~~~~~~
2014_ho_t2.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &M, &N);
  ~~~~~^~~~~~~~~~~~~~~~
2014_ho_t2.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &x); P.push_back(x);
   ~~~~~^~~~~~~~~~
2014_ho_t2.cpp:25:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &x, &y); B.push_back(make_pair(x, y));
   ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...