Submission #578387

#TimeUsernameProblemLanguageResultExecution timeMemory
578387JohannTwo Dishes (JOI19_dishes)C++14
0 / 100
142 ms9640 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<int> #define vpii vector<pii> #define vtiii vector<tiii> #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; while (a >= 0 || b >= 0) { bool useA; if (a == -1) useA = false; else if (b == -1) useA = true; else { if (total <= S[a]) { useA = true; } else if (total <= T[b]) { useA = false; } else { useA = (A[a] >= B[b]); } } if (useA) { if (total <= S[a]) ans += P[a]; total -= A[a]; --a; } else { if (total <= T[b]) ans += Q[b]; total -= B[b]; --b; } } cout << ans << "\n"; }
#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...