Submission #846004

#TimeUsernameProblemLanguageResultExecution timeMemory
846004Mohamed_Kachef06A Plus B (IOI23_aplusb)C++17
100 / 100
87 ms2628 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
vector<int> smallest_sums(int n , vector<int> a, vector<int> b){
    ll l = 0 , r = 2e9 , md;
    while(l<=r){
        md = (l+r)/2;
        ll cnt =0 ;
        for (int i = 0 ; i<n ; i++){
            if (md >= a[i]) cnt+=lower_bound(b.begin() , b.end() , md - a[i]) - b.begin();
        }
        if (cnt < n) l = md+1;
        else r = md-1;
    }
    ll ans = l-1;
    vector<int> c;
    for (int i = 0 ; i<n ; i++){
        for (int j = 0 ; j<n ; j++){
            if (a[i] + b[j] < ans) c.pb(a[i] + b[j]);
            else break;

        }
    }
    while(c.size() < n) c.pb(ans);
    sort(c.begin() , c.end());
    return c;
}

// signed main(){
//     int n ;     cin >> n;

//     vector<int> a(n) , b(n);
//     for (int i =0 ; i <n ; i++) cin >> a[i];
//     for (int i = 0 ; i<n ; i++) cin >> b[i];
//     vector<int> c = smallest_sums(n , a , b);
//     for (auto i : c) cout << i << ' ';
// }

Compilation message (stderr)

aplusb.cpp: In function 'std::vector<int> smallest_sums(int, std::vector<int>, std::vector<int>)':
aplusb.cpp:25:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |     while(c.size() < n) c.pb(ans);
      |           ~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...