# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
816577 |
2023-08-09T05:45:41 Z |
이성호(#10126) |
Ants and Sugar (JOI22_sugar) |
C++17 |
|
4000 ms |
824 KB |
#include <iostream>
#include <algorithm>
#include <vector>
#define int long long
using namespace std;
int L;
int solve(vector<pair<int, int>> ant, vector<pair<int, int>> sugar)
{
int p1 = 0, p2 = 0, ans = 0;
while (p1 < (int)ant.size() && p2 < (int)sugar.size()) {
while (p1 < (int)ant.size() && ant[p1].first < sugar[p2].first - L) p1++;
if (ant[p1].first > sugar[p2].first + L) p2++;
else {
int match = min(ant[p1].second, sugar[p2].second);
ant[p1].second -= match;
sugar[p2].second -= match;
ans += match;
if (!ant[p1].second) p1++;
if (!sugar[p2].second) p2++;
}
}
return ans;
}
signed main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int Q; cin >> Q >> L;
vector<pair<int, int>> ant, sugar;
while (Q--) {
int t, x, a; cin >> t >> x >> a;
if (t == 1) ant.push_back(make_pair(x, a));
else sugar.push_back(make_pair(x, a));
sort(ant.begin(), ant.end());
sort(sugar.begin(), sugar.end());
cout << solve(ant, sugar) << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
4054 ms |
824 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |