Submission #1319424

#TimeUsernameProblemLanguageResultExecution timeMemory
1319424okahak71Table Tennis (info1cup20_tabletennis)C++20
87 / 100
3094 ms4184 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define pb push_back
#define prl pair<ll, ll>
#define pll array<ll, 2>
#define lll array<ll, 3>
#define ss second
#define ff first
#define all(X) X.begin(), X.end()
#define allr(X) X.rbegin(), X.rend()
#define endl '\n'
#define oset tree<ll, null_type,less<ll>, rb_tree_tag, tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;

const ll N = 1e5 + 5;
const ll inf = 1e17;

void _(){
    ll n, k; cin >> n >> k;
    vector<ll>cand; ll og = n; n += k;
    vector<ll>a(n); for(ll &i : a) cin >> i;
    for(ll i = 0; i <= k; i++){
        for(ll j = n - k + i - 1; j < n; j++)// CHECK n - k + i - 1 LOGIC AFTER ACCEPTED
            cand.pb(a[i] + a[j]);
    }
    vector<bool>ch(n);
    for(ll &s : cand){
        ll l = 0, r = n - 1 ,rem = 0;
        deque<ll>lf, rg;
        while(l <= r){
            ll sm = a[l] + a[r];
            if(sm > s) r--, rem++;
            if(sm < s) l++, rem++;
            if(sm == s){
                lf.push_back(a[l++]);
                rg.push_front(a[r--]);
            }
        }
        if(rem == k){
            for(ll &i : lf) cout << i << ' ';
            for(ll &i : rg) cout << i << ' ';
            cout << endl; break;
        }
    }
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); _();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...