Submission #1019886

# Submission time Handle Problem Language Result Execution time Memory
1019886 2024-07-11T10:15:03 Z Unforgettablepl Ants and Sugar (JOI22_sugar) C++17
6 / 100
4000 ms 1396 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long


int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int q,l;
	cin >> q >> l;
	vector<tuple<int,bool,int>> elements; // Sugar is false
	auto solve = [&](){
		int ans = 0;
		queue<pair<int,int>> sugars;
		sort(elements.begin(),elements.end());
		for(auto[idx,type,amt]:elements){
			if(type==false){sugars.emplace(idx,amt);continue;}
			while(!sugars.empty() and sugars.front().first<idx-2*l)sugars.pop();
			while(!sugars.empty()){
				if(amt>=sugars.front().second){
					amt-=sugars.front().second;
					ans+=sugars.front().second;
					sugars.pop();
				} else {
					ans+=amt;
					sugars.front().second-=amt;
					break;
				}
			}
		}
		return ans;
	};
	for(int i=1;i<=q;i++){
		int type,x,a;cin>>type>>x>>a;
		if(type==1){
			elements.emplace_back(x+l,true,a);
		} else {
			elements.emplace_back(x,false,a);
		}
		cout << solve() << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 82 ms 488 KB Output is correct
7 Correct 58 ms 548 KB Output is correct
8 Correct 19 ms 344 KB Output is correct
9 Correct 12 ms 488 KB Output is correct
10 Correct 158 ms 620 KB Output is correct
11 Correct 173 ms 604 KB Output is correct
12 Correct 164 ms 604 KB Output is correct
13 Correct 184 ms 600 KB Output is correct
14 Correct 148 ms 600 KB Output is correct
15 Correct 151 ms 856 KB Output is correct
16 Correct 145 ms 604 KB Output is correct
17 Correct 144 ms 604 KB Output is correct
18 Correct 153 ms 604 KB Output is correct
19 Correct 160 ms 604 KB Output is correct
20 Correct 146 ms 608 KB Output is correct
21 Correct 167 ms 600 KB Output is correct
22 Correct 145 ms 600 KB Output is correct
23 Correct 178 ms 600 KB Output is correct
24 Correct 156 ms 604 KB Output is correct
25 Correct 181 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Execution timed out 4046 ms 1396 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Execution timed out 4089 ms 1380 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 82 ms 488 KB Output is correct
7 Correct 58 ms 548 KB Output is correct
8 Correct 19 ms 344 KB Output is correct
9 Correct 12 ms 488 KB Output is correct
10 Correct 158 ms 620 KB Output is correct
11 Correct 173 ms 604 KB Output is correct
12 Correct 164 ms 604 KB Output is correct
13 Correct 184 ms 600 KB Output is correct
14 Correct 148 ms 600 KB Output is correct
15 Correct 151 ms 856 KB Output is correct
16 Correct 145 ms 604 KB Output is correct
17 Correct 144 ms 604 KB Output is correct
18 Correct 153 ms 604 KB Output is correct
19 Correct 160 ms 604 KB Output is correct
20 Correct 146 ms 608 KB Output is correct
21 Correct 167 ms 600 KB Output is correct
22 Correct 145 ms 600 KB Output is correct
23 Correct 178 ms 600 KB Output is correct
24 Correct 156 ms 604 KB Output is correct
25 Correct 181 ms 604 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Execution timed out 4046 ms 1396 KB Time limit exceeded
30 Halted 0 ms 0 KB -