Submission #1314503

#TimeUsernameProblemLanguageResultExecution timeMemory
1314503muhammad-mutahirTable Tennis (info1cup20_tabletennis)C++20
72 / 100
3110 ms485352 KiB
#include <bits/stdc++.h>
using namespace std;

#define print(l) for(auto i:l) cout<<i<<" ";cout<<endl;
#define input(t,l,n) vector<t>l(n);for(int i = 0;i<n;i++)cin>>l[i];
// #define int long long
#define pb push_back
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define all(l) l.begin(),l.end()
#define pii pair<int,int>
#define fi first
#define se second

const int M = 1e9+7;
const int inf = 1e18;


int bp(int x, int y, int p){
    int res = 1;
    x = x % p;
    while (y > 0) {
 
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
 
int MI(int n, int p){
    return bp(n, p - 2, p);
}
int mul(int x,int y, int p){
    return x * 1ull * y % p;
}
int di(int x,int y, int p){
    return mul(x, MI(y, p), p);
}


int n , m , k , q;

map<int,int>ind,have;
void solve(int testcase_number){
    cin>>n>>k;
    input(int,a,n+k);

    vector<int>sum;
    for(int i = 0;i<=k;i++){
    	for(int j = 0;j<=k;j++){
    		int r = n+k-1-j;
    		if(i!= r){
    			sum.pb(a[i]+a[r]);
    		}
    	}
    }
    for(int i = 0;i<n+k;i++){
    	ind[a[i]] = i;
    	have[a[i]] = 1;
    }

    // print(sum);
    for(auto i:sum){
    	vector<int>vis(n+k+1,0);
    	vector<vector<int>>aa;
    	for(int j = 0;j<n+k;j++){
    		if(i-a[j] == a[j])continue;
    		if( !vis[j] and have[i-a[j]] and !vis[ind[i-a[j]]]){
    			vis[j] = 1;
    			vis[ind[i-a[j]]] = 1;
    			aa.pb({a[j],i-a[j]});
    		}
    		
    	}
    	if(aa.size()>=n/2){
    		vector<int>fans;
    		for(auto i:aa){
    			fans.pb(i[0]);
    			fans.pb(i[1]);
    			if(fans.size() == n)break;
    		}
    		sort(all(fans));
    		print(fans);
    		return;
    	}
    }
    
    




}


signed main(){
    ios::sync_with_stdio(0);//DO NOT USE IN INTERACTIVE
    cin.tie(0), cout.tie(0);
    cout << fixed<<setprecision(9);

    int t = 1;
    // cin>>t;
    for(int i = 1;i<=t;i++){
        solve(i);
    }

}

Compilation message (stderr)

tabletennis.cpp:15:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   15 | const int inf = 1e18;
      |                 ^~~~
#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...