QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#61700#2541. Coins and BoxesConstantRE 2ms3472kbC++14758b2022-11-14 16:28:172022-11-14 16:28:29

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-14 16:28:29]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:3472kb
  • [2022-11-14 16:28:17]
  • 提交

answer

#include<bits/stdc++.h>
#define N 100005
#define ll long long
using namespace std;
int n,s1,s2;
ll now,ans=1e18;
inline int read()
{
    int s=0,w=1;char ch=getchar();  
    while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}
    while(isdigit(ch))s=s*10+(ch^48),ch=getchar();
    return s*w;
}
struct node
{
	int p,id;
}a[N];
int cmp(node x,node y){return x.p<y.p;}
int main() 
{
	n=read();
	for(int i=1;i<=n;i++) a[i].p=read(),a[i].id=1;
	for(int i=1;i<=n;i++) a[n+i].p=read();
	sort(a+1,a+n*2+1,cmp);
	for(int i=1;i<=n*2;i++)
	{
		if(s1>s2) now+=3ll*(a[i].p-a[i-1].p);
		else now+=(a[i].p-a[i-1].p);
		if(a[i].id)
		{			
			ans=min(ans,now+2ll*(a[n*2].p-a[i].p));
			s1++;
		}
		else s2++;
	}
	cout<<ans;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3380kb

input:

4
1 6 7 12
3 5 10 11

output:

21

result:

ok answer is '21'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3472kb

input:

2
1 2
1 1000000000

output:

1999999998

result:

ok answer is '1999999998'

Test #3:

score: -100
Runtime Error

input:

100000
967 3246 9492 10300 15195 16650 26911 54855 83695 112841 125511 137160 153051 155859 177924 187843 214838 219388 247276 249612 250188 253873 257830 261805 281312 297030 298332 325904 333218 339683 374111 387794 396645 403705 426710 436137 463368 481801 501933 509267 511332 515225 515629 51686...

output:


result: