Submission #1112491

#TimeUsernameProblemLanguageResultExecution timeMemory
1112491ljtunasA Plus B (IOI23_aplusb)C++17
60 / 100
1123 ms890188 KiB
// author : anhtun_hi , nqg #include <bits/stdc++.h> #define ll long long #define ii pair<ll, ll> #define fi first #define se second #define all(x) x.begin(), x.end() #define reset(h, v) memset(h, v, sizeof h) #define Forv(i, a) for(auto& i : a) #define For(i, a, b) for(int i = a; i <= b; ++i) #define Ford(i, a, b) for(int i = a; i >= b; --i) #define c_bit(i) __builtin_popcountll(i) #define Bit(mask, i) ((mask >> i) & 1LL) #define onbit(mask, i) ((mask) bitor (1LL << i)) #define offbit(mask, i) ((mask) &~ (1LL << i)) using namespace std; namespace std { template <typename T, int D> struct _vector : public vector <_vector <T, D - 1>> { static_assert(D >= 1, "Dimension must be positive!"); template <typename... Args> _vector(int n = 0, Args... args) : vector <_vector <T, D - 1>> (n, _vector <T, D - 1> (args...)) {} }; template <typename T> struct _vector <T, 1> : public vector <T> { _vector(int n = 0, const T& val = T()) : vector <T> (n, val) {} }; template <class A, class B> bool minimize(A &a, B b){return a > b ? a = b, true : false;} template <class A, class B> bool maximize(A &a, B b){return a < b ? a = b, true : false;} } const int dx[] = {0, 0, +1, -1}, dy[] = {-1, +1, 0, 0}, LOG = 20, base = 311, inf = 1e9 + 5; const int MAXN = 1e6 + 5; const ll mod = 1e9 + 7; const ll oo = 1e18; //#define int long long vector<int> smallest_sums(int n, vector<int> a, vector<int> b){ cin >> n; a.resize(n); b.resize(n); For(i, 0, n - 1) cin >> a[i]; For(i, 0, n - 1) cin >> b[i]; int l = a[0] + b[0] - 1, r = a[n - 1] + b[n - 1] + 1; while(r - l > 1){ int mid = l + r >> 1; int cnt = 0; For(i, 0, n - 1){ cnt += upper_bound(all(b), mid - a[i]) - b.begin(); } if (cnt >= n) r = mid; else l = mid; } // cerr << l << '\n'; vector<int> ans; For(i, 0, n - 1){ int j = -1; while(j < n - 1 && a[i] + b[j + 1] <= r) ++j, ans.push_back(a[i] + b[j]); } // Forv(x, ans) cerr << x << ' '; sort(all(ans)), ans.resize(n); return ans; } // int n; vector<int> a, b; // void Solve() { // vector<int> List = // smallest_sums(n, a, b); // Forv(x, List) cout << x << ' '; // } // int32_t main() { // cin.tie(0) -> sync_with_stdio(0); // if(fopen("a.inp", "r")) { // freopen("a.inp", "r", stdin); // freopen("a.out", "w", stdout); // } // int t = 1; // // cin >> t; // for (int test = 1; test <= t; test++) { // Solve(); // } // return 0; // }

Compilation message (stderr)

aplusb.cpp: In function 'std::vector<int> smallest_sums(int, std::vector<int>, std::vector<int>)':
aplusb.cpp:46:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |         int mid = l + r >> 1;
      |                   ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...