# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
614942 |
2022-07-31T05:38:53 Z |
이동현(#8495) |
Ants and Sugar (JOI22_sugar) |
C++17 |
|
1 ms |
212 KB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int q, l; cin >> q >> l;
vector<vector<int>> a, b;
while(q--){
int t, x, p; cin >> t >> x >> p;
if(t == 1){
a.push_back({x, p});
}
else{
b.push_back({x, p});
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
int ans = 0;
p = 0;
auto aa = a, bb = b;
for(int i = 0; i < (int)aa.size(); ++i){
while(p < (int)bb.size() && (!bb[p][1] || aa[i][0] - bb[p][0] > l)){
++p;
}
if(p < (int)bb.size() && abs(aa[i][0] - bb[p][0]) <= l){
int val = min(bb[p][1], aa[i][1]);
ans += val;
bb[p][1] -= val, aa[i][1] -= val;
}
}
cout << ans << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |