This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 sum = 0;
ll ans = 0;
ll points = 0;
int a = 0, b = 0;
while (a < N && sum + A[a] <= S[a]) {
sum += A[a];
points += P[a];
++a;
}
ans = points;
while (b < M) {
if (sum + B[b] <= T[b]) {
sum += B[b];
points += Q[b];
++b;
ans = max(ans, points);
} else {
if (a > 0) {
--a;
sum -= A[a];
points -= P[a];
} else {
break;
}
}
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |