Submission #615484

# Submission time Handle Problem Language Result Execution time Memory
615484 2022-07-31T09:48:12 Z 장태환(#8493) Ants and Sugar (JOI22_sugar) C++17
6 / 100
4000 ms 1852 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<pair<int, int>>a,b;
vector<pair<int, int>>oa, ob;
signed main()
{
	int N, M;
	cin >> N >> M;
	int i;
	for (i = 0; i < N; i++)
	{
		int x, y, c;
		cin >> x >> y >> c;
		if (x == 1)
		{
			a.push_back({ y,c });
		}
		else
		{
			b.push_back({ y,c });
		}
		sort(a.begin(), a.end());
		sort(b.begin(), b.end());
		oa = a;
		ob = b;
		int j;
		int cp = 0;
		int ans = 0;
		for (j = 0; j < a.size(); j++)
		{
			
			int v = a[j].second;
			ans += a[j].second;
			while (cp<b.size()&&b[cp].first<=a[j].first+M)
			{
				if (b[cp].first < a[j].first - M)
				{
					cp++;
					continue;
				}
				if (b[cp].second > a[j].second)
				{
					b[cp].second -= a[j].second;
					a[j].second = 0;
					break;
				}
				else
				{
					
					a[j].second -= b[cp].second;
					b[cp].second = 0;
					cp++;
				}
			}
			ans -= a[j].second;
		}
		a = oa;
		b = ob;
		cout << ans << '\n';
	}
}

Compilation message

sugar.cpp: In function 'int main()':
sugar.cpp:30:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |   for (j = 0; j < a.size(); j++)
      |               ~~^~~~~~~~~~
sugar.cpp:35:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |    while (cp<b.size()&&b[cp].first<=a[j].first+M)
      |           ~~^~~~~~~~~
sugar.cpp:33:8: warning: unused variable 'v' [-Wunused-variable]
   33 |    int v = a[j].second;
      |        ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 64 ms 476 KB Output is correct
7 Correct 55 ms 452 KB Output is correct
8 Correct 13 ms 420 KB Output is correct
9 Correct 11 ms 320 KB Output is correct
10 Correct 130 ms 576 KB Output is correct
11 Correct 132 ms 608 KB Output is correct
12 Correct 135 ms 712 KB Output is correct
13 Correct 118 ms 496 KB Output is correct
14 Correct 147 ms 624 KB Output is correct
15 Correct 178 ms 584 KB Output is correct
16 Correct 152 ms 556 KB Output is correct
17 Correct 151 ms 616 KB Output is correct
18 Correct 159 ms 484 KB Output is correct
19 Correct 122 ms 560 KB Output is correct
20 Correct 149 ms 776 KB Output is correct
21 Correct 126 ms 616 KB Output is correct
22 Correct 150 ms 488 KB Output is correct
23 Correct 132 ms 636 KB Output is correct
24 Correct 158 ms 540 KB Output is correct
25 Correct 124 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 300 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Execution timed out 4090 ms 1852 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Execution timed out 4080 ms 1752 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 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 64 ms 476 KB Output is correct
7 Correct 55 ms 452 KB Output is correct
8 Correct 13 ms 420 KB Output is correct
9 Correct 11 ms 320 KB Output is correct
10 Correct 130 ms 576 KB Output is correct
11 Correct 132 ms 608 KB Output is correct
12 Correct 135 ms 712 KB Output is correct
13 Correct 118 ms 496 KB Output is correct
14 Correct 147 ms 624 KB Output is correct
15 Correct 178 ms 584 KB Output is correct
16 Correct 152 ms 556 KB Output is correct
17 Correct 151 ms 616 KB Output is correct
18 Correct 159 ms 484 KB Output is correct
19 Correct 122 ms 560 KB Output is correct
20 Correct 149 ms 776 KB Output is correct
21 Correct 126 ms 616 KB Output is correct
22 Correct 150 ms 488 KB Output is correct
23 Correct 132 ms 636 KB Output is correct
24 Correct 158 ms 540 KB Output is correct
25 Correct 124 ms 600 KB Output is correct
26 Correct 0 ms 300 KB Output is correct
27 Correct 1 ms 300 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Execution timed out 4090 ms 1852 KB Time limit exceeded
30 Halted 0 ms 0 KB -