Submission #493958

#TimeUsernameProblemLanguageResultExecution timeMemory
493958balbitTable Tennis (info1cup20_tabletennis)C++14
100 / 100
45 ms4532 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define f first #define s second #define pii pair<ll, ll> #define REP(i,n) for (int i = 0; i<n; ++i) #define REP1(i,n) for (int i = 1; i<=n; ++i) #define MX(a,b) a = max(a,b) #define MN(a,b) a = min(a,b) #define ALL(x) (x).begin(), (x).end() #define SZ(x) (int)((x).size()) #define pb push_back #ifdef BALBIT #define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__) template<typename T> void _do( T && x) {cerr<<x<<endl;} template<typename T, typename ...S> void _do( T && x, S && ...y) {cerr<<x<<", "; _do(y...);} #else #define bug(...) #define endl '\n' #endif // BALBIT const int maxn = 2e5+5; int a[maxn]; int n, k; unordered_set<int> tried; void get(int sum); bool test(int sum) { if (tried.count(sum)) return 0; int lp = 0, rp = n-1; int imp = 0; while (lp < rp && imp <= k) { if (a[lp] + a[rp] == sum) { ++lp; --rp; }else if (a[lp] + a[rp] < sum) { ++lp; ++imp; }else{ --rp; ++imp; } } if (imp > k) { tried.insert(sum); return 0; } get(sum); return 1; } void get(int sum) { int lp = 0, rp = n-1; vector<int> ret; while (lp < rp) { if (a[lp] + a[rp] == sum) { ret.pb(lp); ret.pb(rp); ++lp; --rp; }else if (a[lp] + a[rp] < sum) { ++lp; }else{ --rp; } } while (SZ(ret) > n-k) { ret.pop_back(); ret.pop_back(); } sort(ALL(ret)); for (int t : ret) cout<<a[t]<<' '; cout<<endl; exit(0); } signed main(){ ios::sync_with_stdio(0), cin.tie(0); bug(1,2); cin>>n>>k; n+=k; REP(i,n) cin>>a[i]; sort(a, a+n); if (0 && n <= 200) { // brute REP(i,n) { for (int to = i+1; to <n; ++to) { // int to = n-i-1-j; if (i < to && test(a[i] + a[to])) { // get(a[i] + a[to]); } } } assert(0); } while (1) { int i = rand() % n; int j = rand() % (2*k+1); int to = n-i-1-j+k; bug(i,j,to); if (i < to && to < n && test(a[i] + a[to])) { } } }
#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...