Submission #951055

#TimeUsernameProblemLanguageResultExecution timeMemory
951055masdavA Plus B (IOI23_aplusb)C++17
100 / 100
40 ms5836 KiB
#include<bits/stdc++.h>
using namespace std;

// #define int long long
// #define Int __int128_t
// #define dbg(x) cout<<"["<< #x <<"] : "<<(x)<<endl;
// #define bpc(x) (__builtin_popcountll(x))

int bpow(int a, int b, long long mod=LLONG_MAX){
	int res=1;while(b){if(b%2)res=res*a%mod;a=a*a%mod;b/=2;}return res;
}
int inv(int a, int mod=1e9+7){ return bpow(a, mod-2, mod); }

vector<int> smallest_sums(int n, vector<int>a, vector<int>b){	
	priority_queue<pair<int, pair<int,int>>> pq;
	for(int i = 0; i < n; i++){
		pq.push({-(a[i] + b[0]) ,{i, 0}});
	}
	// for(int i : a) dbg(i);
	// for(int i : b) dbg(i);
	
	vector<int> res;
	while((int)res.size() < n){
		int now = -pq.top().first;
		auto[now_i, now_j] = pq.top().second;

		res.push_back(now);
		pq.pop();
		pq.push({ -(a[now_i] + b[now_j+1]), {now_i, now_j + 1} });
	}
	return res;
}

// signed main(){
// 	vector<int> tmp =smallest_sums(2, {0, 2}, {1, 4});
// 	vector<int> tmp = smallest_sums(3, {0, 2, 2}, {3, 5, 6});
// 	for(int i : tmp){
// 		cout << i << ' ';
// 	}
// 	cout << '\n';
// }
/*

*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...