Submission #886475

# Submission time Handle Problem Language Result Execution time Memory
886475 2023-12-12T08:12:52 Z vjudge1 Gym Badges (NOI22_gymbadges) C++17
51 / 100
2000 ms 35920 KB
#include <bits/stdc++.h>
using namespace std;
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define sp " "
#define endl "\n"
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second 
#define N 500005
#define int long long

const int INF = 1e9 + 7;

int x[N], l[N];

int32_t main(){
	//fileio();
	fastio();


	int n;
	cin>>n;
	for (int i = 1; i <= n; i++){
		cin>>x[i];
	}
	for (int i = 1; i <= n; i++){
		cin>>l[i];
	}

	vector<int> v(n, 0);
	iota(v.begin(), v.end(), 1);
	sort(v.begin(), v.end(), [&](int a, int b){
		if (x[a] == x[b]) return l[a] < l[b];
		return x[a] < x[b];
	});

	int sum = 0;
	int ans = 0;
	multiset<pii> maks;
	for (auto i : v){
		if (sum <= l[i]){
			sum += x[i];
			ans++;
			maks.insert({l[i] + x[i], x[i]});
			continue;
		}
		int tmp = sum;
		auto it = maks.rbegin();
		while(it != maks.rend() && it->st >= tmp + x[i]){
			tmp -= it->nd;
			it++;
			if (tmp <= l[i]){
				sum += x[i];
				ans++;
				maks.insert({l[i] + x[i], x[i]});
				break;
			}
		}
		
	}
	//cout<<endl;
	cout<<ans<<endl;
	cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 2 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2512 KB Output is correct
12 Correct 1 ms 2508 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 130 ms 19908 KB Output is correct
2 Correct 123 ms 19284 KB Output is correct
3 Correct 124 ms 19280 KB Output is correct
4 Correct 125 ms 19352 KB Output is correct
5 Correct 138 ms 19464 KB Output is correct
6 Correct 124 ms 19908 KB Output is correct
7 Correct 119 ms 18584 KB Output is correct
8 Correct 123 ms 19540 KB Output is correct
9 Correct 123 ms 20000 KB Output is correct
10 Correct 124 ms 20564 KB Output is correct
11 Correct 157 ms 32152 KB Output is correct
12 Correct 168 ms 34936 KB Output is correct
13 Correct 159 ms 33764 KB Output is correct
14 Correct 161 ms 34492 KB Output is correct
15 Correct 165 ms 35920 KB Output is correct
16 Correct 129 ms 22700 KB Output is correct
17 Correct 134 ms 23636 KB Output is correct
18 Correct 135 ms 24220 KB Output is correct
19 Correct 130 ms 21912 KB Output is correct
20 Correct 124 ms 20292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 2 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2512 KB Output is correct
12 Correct 1 ms 2508 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 2 ms 2652 KB Output is correct
22 Correct 2 ms 2520 KB Output is correct
23 Correct 2 ms 2520 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2652 KB Output is correct
26 Correct 3 ms 2732 KB Output is correct
27 Correct 2 ms 2652 KB Output is correct
28 Correct 3 ms 2520 KB Output is correct
29 Correct 3 ms 2904 KB Output is correct
30 Correct 3 ms 2648 KB Output is correct
31 Correct 5 ms 2784 KB Output is correct
32 Correct 5 ms 2652 KB Output is correct
33 Correct 5 ms 2652 KB Output is correct
34 Correct 5 ms 2652 KB Output is correct
35 Correct 5 ms 2652 KB Output is correct
36 Correct 8 ms 2648 KB Output is correct
37 Correct 8 ms 2652 KB Output is correct
38 Correct 8 ms 2648 KB Output is correct
39 Correct 8 ms 2844 KB Output is correct
40 Correct 8 ms 2652 KB Output is correct
41 Correct 12 ms 2908 KB Output is correct
42 Correct 12 ms 2908 KB Output is correct
43 Correct 12 ms 2908 KB Output is correct
44 Correct 12 ms 2904 KB Output is correct
45 Correct 13 ms 2908 KB Output is correct
46 Correct 15 ms 2948 KB Output is correct
47 Correct 15 ms 2908 KB Output is correct
48 Correct 16 ms 2904 KB Output is correct
49 Correct 17 ms 2908 KB Output is correct
50 Correct 18 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 2 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2512 KB Output is correct
12 Correct 1 ms 2508 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 130 ms 19908 KB Output is correct
22 Correct 123 ms 19284 KB Output is correct
23 Correct 124 ms 19280 KB Output is correct
24 Correct 125 ms 19352 KB Output is correct
25 Correct 138 ms 19464 KB Output is correct
26 Correct 124 ms 19908 KB Output is correct
27 Correct 119 ms 18584 KB Output is correct
28 Correct 123 ms 19540 KB Output is correct
29 Correct 123 ms 20000 KB Output is correct
30 Correct 124 ms 20564 KB Output is correct
31 Correct 157 ms 32152 KB Output is correct
32 Correct 168 ms 34936 KB Output is correct
33 Correct 159 ms 33764 KB Output is correct
34 Correct 161 ms 34492 KB Output is correct
35 Correct 165 ms 35920 KB Output is correct
36 Correct 129 ms 22700 KB Output is correct
37 Correct 134 ms 23636 KB Output is correct
38 Correct 135 ms 24220 KB Output is correct
39 Correct 130 ms 21912 KB Output is correct
40 Correct 124 ms 20292 KB Output is correct
41 Correct 2 ms 2652 KB Output is correct
42 Correct 2 ms 2520 KB Output is correct
43 Correct 2 ms 2520 KB Output is correct
44 Correct 2 ms 2652 KB Output is correct
45 Correct 2 ms 2652 KB Output is correct
46 Correct 3 ms 2732 KB Output is correct
47 Correct 2 ms 2652 KB Output is correct
48 Correct 3 ms 2520 KB Output is correct
49 Correct 3 ms 2904 KB Output is correct
50 Correct 3 ms 2648 KB Output is correct
51 Correct 5 ms 2784 KB Output is correct
52 Correct 5 ms 2652 KB Output is correct
53 Correct 5 ms 2652 KB Output is correct
54 Correct 5 ms 2652 KB Output is correct
55 Correct 5 ms 2652 KB Output is correct
56 Correct 8 ms 2648 KB Output is correct
57 Correct 8 ms 2652 KB Output is correct
58 Correct 8 ms 2648 KB Output is correct
59 Correct 8 ms 2844 KB Output is correct
60 Correct 8 ms 2652 KB Output is correct
61 Correct 12 ms 2908 KB Output is correct
62 Correct 12 ms 2908 KB Output is correct
63 Correct 12 ms 2908 KB Output is correct
64 Correct 12 ms 2904 KB Output is correct
65 Correct 13 ms 2908 KB Output is correct
66 Correct 15 ms 2948 KB Output is correct
67 Correct 15 ms 2908 KB Output is correct
68 Correct 16 ms 2904 KB Output is correct
69 Correct 17 ms 2908 KB Output is correct
70 Correct 18 ms 2908 KB Output is correct
71 Correct 1 ms 2396 KB Output is correct
72 Correct 1 ms 2396 KB Output is correct
73 Correct 203 ms 21844 KB Output is correct
74 Correct 200 ms 21908 KB Output is correct
75 Correct 198 ms 22100 KB Output is correct
76 Correct 208 ms 21844 KB Output is correct
77 Correct 206 ms 21840 KB Output is correct
78 Execution timed out 2079 ms 24896 KB Time limit exceeded
79 Halted 0 ms 0 KB -