This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ...b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
while (l != r) cout << *l << " ", l++;
cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 100005
#define pii pair<ll, ll>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
int main() {
io
int q, l;
cin >> q >> l;
vector<pii> v1, v2, t2;
while (q--) {
{
int t, x;
ll v;
cin >> t >> x >> v;
if (t == 1) {
v1.push_back({x, v});
} else {
t2.push_back({x, v});
}
}
v2 = t2;
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end());
int ind = 0;
ll ans = 0;
for (int i = 0;i < v1.size();i++) {
ll tmp = v1[i].ss;
while (ind < v2.size()) {
if (v2[ind].ff < v1[i].ff - l) ind++;
else if (v2[ind].ff > v1[i].ff + l) {
break;
} else if (v2[ind].ss < tmp) {
ans += v2[ind].ss;
tmp -= v2[ind].ss;
ind++;
} else {
ans += tmp;
v2[ind].ss -= tmp;
break;
}
}
}
cout << ans << "\n";
}
}
Compilation message (stderr)
sugar.cpp: In function 'int main()':
sugar.cpp:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int i = 0;i < v1.size();i++) {
| ~~^~~~~~~~~~~
sugar.cpp:44:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | while (ind < v2.size()) {
| ~~~~^~~~~~~~~~~
# | 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... |