1 solutions

  • 0
    @ 2024-2-20 8:38:54
    #include "aplusb.h"
    
    #include <vector>
    #include <set>
    
    std::vector<int> smallest_sums(int N, std::vector<int> A, std::vector<int> B) {
    	std::set<std::pair<int,int>> szet; szet.clear();
    	std::vector<int> pos(N);
    	for(int i=0; i<N; i++){
    		pos[i] = 0;
    		szet.insert({A[i]+B[0],i});
    	}
    
    	std::vector<int> ans(N);
    	for(int i=0; i<N; i++){
    		auto it = szet.begin();
    		ans[i] = (*it).first;
    		int id = (*it).second;
    		szet.erase(szet.begin());
    		if(++pos[id] < N) szet.insert({A[id] + B[pos[id]], id});
    	}
    	return ans;
    }
    

    Information

    ID
    20
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    10
    Tags
    (None)
    # Submissions
    5
    Accepted
    2
    Uploaded By