Submission #261844

#TimeUsernameProblemLanguageResultExecution timeMemory
261844arnold518Cloud Computing (CEOI18_clo)C++14
100 / 100
553 ms2168 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 4000; const ll INF = 1e18; struct Data { int c, f, v; }; int N, M; Data A[MAXN+10]; ll dp[2][100000+10]; int main() { int i, j; scanf("%d", &N); for(int i=1; i<=N; i++) scanf("%d%d%d", &A[i].c, &A[i].f, &A[i].v), A[i].v*=-1; scanf("%d", &M); for(int i=1; i<=M; i++) scanf("%d%d%d", &A[i+N].c, &A[i+N].f, &A[i+N].v); sort(A+1, A+N+M+1, [&](const Data &p, const Data &q) { if(p.f!=q.f) return p.f>q.f; return p.v<q.v; }); for(int i=1; i<=100000; i++) dp[0][i]=-INF; for(int i=1; i<=N+M; i++) { if(A[i].v<0) { for(int j=0; j<=100000; j++) { dp[i&1][j]=dp[i-1&1][j]; if(j-A[i].c>=0) dp[i&1][j]=max(dp[i&1][j], dp[i-1&1][j-A[i].c]+A[i].v); } } else { for(int j=0; j<=100000; j++) { dp[i&1][j]=dp[i-1&1][j]; if(j+A[i].c<=100000) dp[i&1][j]=max(dp[i&1][j], dp[i-1&1][j+A[i].c]+A[i].v); } } } ll ans=0; for(int i=0; i<=100000; i++) ans=max(ans, dp[N+M&1][i]); printf("%lld\n", ans); }

Compilation message (stderr)

clo.cpp: In function 'int main()':
clo.cpp:41:20: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
     dp[i&1][j]=dp[i-1&1][j];
                   ~^~
clo.cpp:42:52: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
     if(j-A[i].c>=0) dp[i&1][j]=max(dp[i&1][j], dp[i-1&1][j-A[i].c]+A[i].v);
                                                   ~^~
clo.cpp:49:20: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
     dp[i&1][j]=dp[i-1&1][j];
                   ~^~
clo.cpp:50:57: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
     if(j+A[i].c<=100000) dp[i&1][j]=max(dp[i&1][j], dp[i-1&1][j+A[i].c]+A[i].v);
                                                        ~^~
clo.cpp:55:48: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
  for(int i=0; i<=100000; i++) ans=max(ans, dp[N+M&1][i]);
                                               ~^~
clo.cpp:22:6: warning: unused variable 'i' [-Wunused-variable]
  int i, j;
      ^
clo.cpp:22:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
clo.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
clo.cpp:24:68: 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%d", &A[i].c, &A[i].f, &A[i].v), A[i].v*=-1;
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
clo.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &M);
  ~~~~~^~~~~~~~~~
clo.cpp:26:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1; i<=M; i++) scanf("%d%d%d", &A[i+N].c, &A[i+N].f, &A[i+N].v);
                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...