This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "aplusb.h"
#include "bits/stdc++.h"
using namespace std;
bool check(int mid, vector<int> a, vector<int> b, int n){
int cnt = 0;
for(int &i : a)
for(int &j : b){
if(i + j > mid)
break;
else
cnt++;
}
return cnt >= n;
}
vector<int> smallest_sums(int N, vector<int> A, vector<int> B){
vector<int> a = A;
vector<int> b = B;
int n = N;
int l = 0, r = a.back() + b.back();
int id = 0;
while(l <= r){
int mid = (l + r) >> 1;
if(check(mid, a, b, n)){
id = mid;
r = mid - 1;
}
else
l = mid + 1;
}
multiset<int> s;
for(int &i : a)
for(int &j : b){
if(i + j > id)
break;
else
s.insert(i + j);
}
int cnt = 0;
vector<int> ans;
for(int i : s){
if(cnt == n)
break;
cnt++;
ans.push_back(i);
}
return ans;
}
// int main(){
// int n;
// cin >> n;
// vector<int> a(n), b(n);
// for(int &i : a)
// cin >> i;
// for(int &i : b)
// cin >> i;
// // a and b is sorted
// int l = 0, r = a.back() + b.back();
// int id = 0;
// while(l <= r){
// int mid = (l + r) >> 1;
// if(check(mid, a, b, n)){
// id = mid;
// r = mid - 1;
// }
// else
// l = mid + 1;
// }
// multiset<int> s;
// for(int &i : a)
// for(int &j : b){
// if(i + j > id)
// break;
// else
// s.insert(i + j);
// }
// int cnt = 0;
// for(int i : s){
// if(cnt == n)
// break;
// cnt++;
// cout << i << " ";
// }
// cout << "\n";
// return 0;
// }
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |