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 int long long
#define sz(a) (int)a.size()
using namespace std;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int q, L;
cin >> q >> L;
int Q = 0;
vector<pair<int, int>> m, s;
while (q--) {
++Q;
int t, x, a;
cin >> t >> x >> a;
if (t == 1) {
m.push_back({x, a});
}
else {
s.push_back({x, a});
}
vector<pair<int, int>> M = m, S = s;
sort(M.begin(), M.end());
sort(S.begin(), S.end());
int r = 0, ans = 0;
for (int i = 0; i < sz(M); ++i) {
while (r < sz(S) && M[i].first - S[r].first > L) {
++r;
}
if (r == sz(S)) break;
while (r < sz(S) && abs(S[r].first - M[i].first) <= L) {
if (M[i].second > S[r].second) {
ans += S[r].second;
M[i].second -= S[r].second;
S[r].second = 0;
++r;
}
else {
ans += M[i].second;
S[r].second -= M[i].second;
M[i].second = 0;
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... |