Submission #578399

#TimeUsernameProblemLanguageResultExecution timeMemory
578399JohannTwo Dishes (JOI19_dishes)C++14
10 / 100
536 ms1048576 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define tiii tuple<int,int,int> #define vi vector<ll> #define vpii vector<pii> #define vtiii vector<tiii> #define vvi vector<vi> #define sz(x) (int) (x).size() #define all(x) (x).begin(), (x).end() const int MAXN = 1e6 + 7; ll N,M; ll A[MAXN],B[MAXN],S[MAXN],T[MAXN],P[MAXN],Q[MAXN]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> N >> M; for (int i = 0; i < N; ++i) cin >> A[i] >> S[i] >> P[i]; for (int i = 0; i < M; ++i) cin >> B[i] >> T[i] >> Q[i]; ll total = accumulate(A, A+N, 0) + accumulate(B, B+M, 0); ll ans = 0; int a = N-1, b = M-1; vvi sums(N+1, vi(M+1, 0)); vvi dp(N+1, vi(M+1, 0)); for (int n = 0; n < N; ++n) { sums[n+1][0] = sums[n][0] + A[n]; dp[n+1][0] = dp[n][0]; if (sums[n+1][0] <= S[n]) dp[n+1][0] += P[n]; } for (int m = 0; m < M; ++m) { sums[0][m+1] = sums[0][m] + B[m]; dp[0][m+1] = dp[0][m]; if (sums[0][m+1] <= T[m]) dp[0][m+1] += Q[m]; } for (int n = 1; n <= N; ++n) { for (int m = 1; m <= M; ++m) { sums[n][m] = sums[n-1][m] + A[n-1]; ll pa = dp[n-1][m]; pa += (sums[n][m] <= S[n-1]) ? P[n-1] : 0; ll pb = dp[n][m-1]; pb += (sums[n][m] <= T[m-1]) ? Q[m-1] : 0; dp[n][m] = max(pa, pb); } } cout << dp[N][M] << "\n"; }

Compilation message (stderr)

dishes.cpp: In function 'int main()':
dishes.cpp:27:8: warning: unused variable 'total' [-Wunused-variable]
   27 |     ll total = accumulate(A, A+N, 0) + accumulate(B, B+M, 0);
      |        ^~~~~
dishes.cpp:29:8: warning: unused variable 'ans' [-Wunused-variable]
   29 |     ll ans = 0;
      |        ^~~
dishes.cpp:30:9: warning: unused variable 'a' [-Wunused-variable]
   30 |     int a = N-1, b = M-1;
      |         ^
dishes.cpp:30:18: warning: unused variable 'b' [-Wunused-variable]
   30 |     int a = N-1, b = M-1;
      |                  ^
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...