답안 #824001

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
824001 2023-08-13T11:20:25 Z Mohammed_Atalah Gym Badges (NOI22_gymbadges) C++17
100 / 100
459 ms 66092 KB
/// Template path: /home/mohammed/.config/sublime-text-3/Packages/User

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

// typedef
typedef long long ll;
typedef long double ld;
typedef vector<int> vecint;
typedef vector<char> vecchar;
typedef vector<string> vecstr;
typedef vector<long long> vecll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// Marcos
#define endl ("\n")
#define int long long
#define mod 1000000007
#define pi (3.141592653589)
#define REP(i,a,b) for (int i = a; i < b; i++)
#define RREP(i,a,b) for (int i = a; i > b; i--)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

// Functions
long long squared(long long x) {return (x * x) % mod;}
int factorial(int n) {long long res = 1; for (int i = 1; i <= n; i++) {res = ((res * i) % mod + mod) % mod ;} return res;}
long long power(long long x, long long p) {if (p == 0) {return 1;} if (p % 2 == 1) {return (power(x, p - 1) * x) % mod;} return squared(power(x, p / 2));}

// cout << fixed;
// cout << setprecision(4);


// ---------(^_^)--------- //




void main_solve() {


	int n; cin >> n;
	vector<int> X;
	vector<int> L;

	for (int i = 0 ; i < n ; i ++) {
		int x;	cin >> x;
		X.push_back(x);
	}

	for (int i = 0 ; i < n ; i ++) {
		int x;	cin >> x;
		L.push_back(x + X[i]);
	}

	vector<vector<int>> v;

	for (int i = 0 ; i < n ; i ++) {
		v.push_back({L[i], X[i]});
	}
	sort(v.begin(), v.end());
	int result = 0;
	int curr = 0;
	multiset<int> s;
	for (int i = 0 ; i < n ; i ++) {
		// cout << v[i][0] << ' ' << v[i][1] << endl;
		if (curr > v[i][0] - v[i][1]) {
			auto it  = s.end();
			it--;
			if (v[i][1] < *it) {
				curr -= *it;
				curr += v[i][1];
				s.erase(it);
				s.insert(v[i][1]);
			}



			continue;
		}
		s.insert(v[i][1]);
		curr += v[i][1];
		result++;

	}
	cout << result << endl;
}


int32_t main() {

	fast;
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	// Just another problem (-_-)

	int t;
	t = 1;
	// cin >> t;

	while (t--) {
		main_solve();
	}


}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 0 ms 324 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 216 ms 44784 KB Output is correct
2 Correct 226 ms 44720 KB Output is correct
3 Correct 233 ms 44812 KB Output is correct
4 Correct 224 ms 44828 KB Output is correct
5 Correct 222 ms 44788 KB Output is correct
6 Correct 217 ms 44720 KB Output is correct
7 Correct 225 ms 43512 KB Output is correct
8 Correct 222 ms 44416 KB Output is correct
9 Correct 217 ms 44644 KB Output is correct
10 Correct 230 ms 45156 KB Output is correct
11 Correct 256 ms 53476 KB Output is correct
12 Correct 279 ms 55268 KB Output is correct
13 Correct 258 ms 54616 KB Output is correct
14 Correct 264 ms 55212 KB Output is correct
15 Correct 277 ms 56164 KB Output is correct
16 Correct 230 ms 46536 KB Output is correct
17 Correct 227 ms 47200 KB Output is correct
18 Correct 227 ms 47724 KB Output is correct
19 Correct 230 ms 46000 KB Output is correct
20 Correct 215 ms 44800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 0 ms 324 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 2 ms 852 KB Output is correct
22 Correct 2 ms 852 KB Output is correct
23 Correct 2 ms 852 KB Output is correct
24 Correct 2 ms 852 KB Output is correct
25 Correct 2 ms 852 KB Output is correct
26 Correct 2 ms 848 KB Output is correct
27 Correct 2 ms 772 KB Output is correct
28 Correct 2 ms 736 KB Output is correct
29 Correct 2 ms 844 KB Output is correct
30 Correct 2 ms 812 KB Output is correct
31 Correct 2 ms 840 KB Output is correct
32 Correct 3 ms 852 KB Output is correct
33 Correct 2 ms 844 KB Output is correct
34 Correct 2 ms 852 KB Output is correct
35 Correct 2 ms 852 KB Output is correct
36 Correct 2 ms 852 KB Output is correct
37 Correct 2 ms 848 KB Output is correct
38 Correct 2 ms 852 KB Output is correct
39 Correct 2 ms 852 KB Output is correct
40 Correct 2 ms 852 KB Output is correct
41 Correct 2 ms 852 KB Output is correct
42 Correct 2 ms 852 KB Output is correct
43 Correct 2 ms 840 KB Output is correct
44 Correct 2 ms 848 KB Output is correct
45 Correct 2 ms 852 KB Output is correct
46 Correct 2 ms 980 KB Output is correct
47 Correct 2 ms 980 KB Output is correct
48 Correct 3 ms 976 KB Output is correct
49 Correct 2 ms 980 KB Output is correct
50 Correct 2 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 0 ms 324 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 216 ms 44784 KB Output is correct
22 Correct 226 ms 44720 KB Output is correct
23 Correct 233 ms 44812 KB Output is correct
24 Correct 224 ms 44828 KB Output is correct
25 Correct 222 ms 44788 KB Output is correct
26 Correct 217 ms 44720 KB Output is correct
27 Correct 225 ms 43512 KB Output is correct
28 Correct 222 ms 44416 KB Output is correct
29 Correct 217 ms 44644 KB Output is correct
30 Correct 230 ms 45156 KB Output is correct
31 Correct 256 ms 53476 KB Output is correct
32 Correct 279 ms 55268 KB Output is correct
33 Correct 258 ms 54616 KB Output is correct
34 Correct 264 ms 55212 KB Output is correct
35 Correct 277 ms 56164 KB Output is correct
36 Correct 230 ms 46536 KB Output is correct
37 Correct 227 ms 47200 KB Output is correct
38 Correct 227 ms 47724 KB Output is correct
39 Correct 230 ms 46000 KB Output is correct
40 Correct 215 ms 44800 KB Output is correct
41 Correct 2 ms 852 KB Output is correct
42 Correct 2 ms 852 KB Output is correct
43 Correct 2 ms 852 KB Output is correct
44 Correct 2 ms 852 KB Output is correct
45 Correct 2 ms 852 KB Output is correct
46 Correct 2 ms 848 KB Output is correct
47 Correct 2 ms 772 KB Output is correct
48 Correct 2 ms 736 KB Output is correct
49 Correct 2 ms 844 KB Output is correct
50 Correct 2 ms 812 KB Output is correct
51 Correct 2 ms 840 KB Output is correct
52 Correct 3 ms 852 KB Output is correct
53 Correct 2 ms 844 KB Output is correct
54 Correct 2 ms 852 KB Output is correct
55 Correct 2 ms 852 KB Output is correct
56 Correct 2 ms 852 KB Output is correct
57 Correct 2 ms 848 KB Output is correct
58 Correct 2 ms 852 KB Output is correct
59 Correct 2 ms 852 KB Output is correct
60 Correct 2 ms 852 KB Output is correct
61 Correct 2 ms 852 KB Output is correct
62 Correct 2 ms 852 KB Output is correct
63 Correct 2 ms 840 KB Output is correct
64 Correct 2 ms 848 KB Output is correct
65 Correct 2 ms 852 KB Output is correct
66 Correct 2 ms 980 KB Output is correct
67 Correct 2 ms 980 KB Output is correct
68 Correct 3 ms 976 KB Output is correct
69 Correct 2 ms 980 KB Output is correct
70 Correct 2 ms 980 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 1 ms 212 KB Output is correct
73 Correct 193 ms 45156 KB Output is correct
74 Correct 201 ms 45196 KB Output is correct
75 Correct 206 ms 45260 KB Output is correct
76 Correct 194 ms 45104 KB Output is correct
77 Correct 198 ms 45168 KB Output is correct
78 Correct 217 ms 48096 KB Output is correct
79 Correct 209 ms 48136 KB Output is correct
80 Correct 214 ms 48132 KB Output is correct
81 Correct 211 ms 48120 KB Output is correct
82 Correct 209 ms 48148 KB Output is correct
83 Correct 258 ms 53368 KB Output is correct
84 Correct 245 ms 53404 KB Output is correct
85 Correct 251 ms 53432 KB Output is correct
86 Correct 263 ms 53432 KB Output is correct
87 Correct 258 ms 53440 KB Output is correct
88 Correct 324 ms 58652 KB Output is correct
89 Correct 324 ms 58736 KB Output is correct
90 Correct 307 ms 58640 KB Output is correct
91 Correct 317 ms 58624 KB Output is correct
92 Correct 325 ms 58796 KB Output is correct
93 Correct 341 ms 61920 KB Output is correct
94 Correct 429 ms 61856 KB Output is correct
95 Correct 372 ms 61932 KB Output is correct
96 Correct 375 ms 61820 KB Output is correct
97 Correct 342 ms 61848 KB Output is correct
98 Correct 213 ms 45724 KB Output is correct
99 Correct 195 ms 45724 KB Output is correct
100 Correct 196 ms 45820 KB Output is correct
101 Correct 459 ms 66044 KB Output is correct
102 Correct 428 ms 66092 KB Output is correct