Submission #977952

#TimeUsernameProblemLanguageResultExecution timeMemory
977952Kel_MahmutGym Badges (NOI22_gymbadges)C++14
100 / 100
456 ms34088 KiB
#include <bits/stdc++.h>
#define pb push_back
#define all(aa) aa.begin(), aa.end()
using namespace std;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	vector<ll> L(n), X(n);
	for(int i = 0; i < n; i++)
		cin >> X[i];
	for(int i = 0; i < n; i++)
		cin >> L[i];
	vector<array<ll, 3>> G(n);
	for(int i = 0; i < n; i++){
		G[i] = {L[i] + X[i], L[i], X[i]};
	}
	sort(all(G));

	priority_queue<ll> vals;
	ll score = 0, ans = 0;
	for(int i = 0; i < n; i++){
		auto [a, Li, Xi] = G[i];
		if(score <= Li){
			vals.push(Xi);
			score += Xi;
			ans++;
		}
		else if(vals.top() > Xi){
			score -= vals.top(); vals.pop();
			score += Xi; vals.push(Xi); 
		}
	}
	cout << ans << endl;

}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:24:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   24 |   auto [a, Li, Xi] = G[i];
      |        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...