QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#800872 | #8783. Cherry Picking | ucup-team6015# | TL | 0ms | 0kb | C++11 | 848b | 2024-12-06 16:21:42 | 2024-12-06 16:21:42 |
answer
#include <bits/stdc++.h>
std::mt19937 rnd(time(0));
int main()
{
int n;
scanf("%d",&n);
std::vector<int> ori(n),a(n),b(n);
for(int i=0;i<n;i++)
scanf("%d",&ori[i]);
for(int i=0;i<n/2;i++)
a[i]=ori[i];
for(int i=0;i<n/2;i++)
b[i]=ori[i+n/2];
const int N=1e9;
for(;;)
{
int sum=0;
for(int i=0;i<n/2;i++)
sum += a[i];
if(sum == N)
break;
int pos=rnd()%(n/2),j=0;
for(int i=0;i<n/2;i++)
if(abs(N-(sum-a[pos]+b[i]))<abs(N-(sum-a[pos]+b[j])))
j=i;
std::swap(a[pos],b[j]);
}
printf("%d ",n/2);
for(int i=0;i<n/2;i++)
for(int j=0;j<n;j++)
if(a[i] == ori[j])
printf("%d%c",j+1," \n"[i == n/2-1]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
5 2 1 2 3 4 5 01101