이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n , k;
cin >> n >> k ;
ll teams=n/2;
vector<ll>v;
ll x;
n+=k;
map<ll,ll>mp , occ;
for(int i = 0 ; i < n ; i++)
{
cin >> x;
mp[x]++;
v.push_back(x);
}
sort(v.begin(), v.end());
vector<ll>poten;
set<ll>ss;
for(int i = 0 ; i< 2*k ; i++)
{
for( int j = n-1; j >= n-(2*k) ; j-- )
{
ss.insert(v[i]+v[j]);
occ[v[i]+v[j]]++;
}
}
for(ll u : ss)
{
if(occ[u]>=k)
{
poten.push_back(u);
}
}
vector<ll>ansa;
ll sz=poten.size() , cnt;
for( int i = 0 ; i < sz ; i++)
{
ansa.clear();
ll tmp=teams;
cnt=0;
for(int j = 0 ; v[j]<(poten[i]/2) ; j++ )
{
if(poten[i]-v[j]==v[j])continue;
if(mp[poten[i]-v[j]])
{
tmp--;
ansa.push_back(poten[i]-v[j]);
ansa.push_back(v[j]);
}
else cnt++;
if(tmp==0)
break;
if(cnt==k+1)
break;
}
if(tmp==0)
{
break;
}
}
sort( ansa.begin() , ansa.end());
for(int i = 0 ; i < teams*2 ; i++)
{
cout << ansa[i] << " " ;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |