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>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define eb emplace_back
#define int LL
using namespace std;
using LL = long long;
using pii = pair<int, int>;
const int MAXN = 1000010;
struct OWO {
int a, s, p;
};
OWO a[MAXN];
OWO b[MAXN];
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
// NYA =^-w-^=
int n, m; cin >> n >> m;
int nowt = 0;
For(i, 1, n) {
auto &owo = a[i];
cin >> owo.a >> owo.s >> owo.p;
assert(owo.p == 1);
nowt += owo.a;
}
For(i, 1, m) {
auto &owo = b[i];
cin >> owo.a >> owo.s >> owo.p;
assert(owo.p == 1);
nowt += owo.a;
}
int i = n, j = m;
int ans = 0;
while(i || j) {
int sel = -1; // 1 for a, 2 for b
if(i == 0) sel = 2;
else if(j == 0) sel = 1;
else if(nowt <= a[i].s) sel = 1;
else if(nowt <= b[j].s) sel = 2;
else if(a[i].a > b[i].a) sel = 1;
else sel = 2;
if(sel == 1) {
ans += (nowt <= a[i].s);
nowt -= a[i].a;
i--;
} else {
ans += (nowt <= b[j].s);
nowt -= b[j].a;
j--;
}
}
cout << ans << "\n";
return 0;
}
# | 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... |