QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#612528#9440. Train Seatsucup-team3890#WA 1ms7756kbC++141.6kb2024-10-05 11:45:422024-10-05 11:45:42

Judging History

This is the latest submission verdict.

  • [2024-10-05 11:45:42]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 7756kb
  • [2024-10-05 11:45:42]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+99;
int n,m,a[N],ans;
struct node{
	int sum,len;
	int l,r;
	bool operator <(const node&A) const{
		return sum*A.len<A.sum*len;
	}
	node operator +(const node&A){
		return (node){sum+A.sum,len+A.len,min(l,A.l),max(r,A.r)};
	}
};
node sta1[N],sta2[N];
int cnt1,cnt2;
int seq[N],cnt;
void solve(){
	int re=n*(m+1);
	for(int i=1;i<=n;i++)
		re-=seq[i]*(n-i);
	ans=max(ans,re);
	return;
}
signed main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1); a[n+1]=m+1;
	for(int i=n+1;i>=1;i--) a[i]-=a[i-1];
	node now;
	sta1[++cnt1]=(node){a[n+1],1,n+1,n+1};
	for(int i=n;i>=1;i--){
		now=(node){a[i],1,i,i};
		if(sta1[cnt1]<now) sta1[cnt1]=sta1[cnt1]+now;
		else sta1[++cnt1]=now;
	}
	sta2[++cnt2]=(node){a[1],1,1,1};
	for(int i=2;i<=n+1;i++){
		now=(node){a[i],1,i,i};
		if(sta2[cnt2]<now) sta2[cnt2]=sta2[cnt2]+now;
		else sta2[++cnt2]=now;
	}
//	cout<<cnt1<<endl;
//	for(int i=cnt1;i>=1;i--)
//		cout<<sta1[i].l<<" "<<sta1[i].r<<endl;
//	cout<<cnt2<<endl;
//	for(int i=cnt2;i>=1;i--)
//		cout<<sta2[i].l<<" "<<sta2[i].r<<endl;
	int l=1,r=n+1;
	while(cnt1&&cnt2){
		if(sta1[cnt1].r>=sta2[cnt2].l) break;
		if(sta1[cnt1]<sta2[cnt2]){
			while(l<=sta1[cnt1].r)
				seq[++cnt]=a[l++];
			cnt1--;
		}
		else{
			while(r>=sta2[cnt2].l)
				seq[++cnt]=a[r--];
			cnt2--;
		}
	}
//	cout<<l<<" "<<r<<endl;
	for(int i=l;i<=r;i++)
		seq[cnt+i-l+1]=a[i];
	solve();
	for(int i=r;i>=l;i--)
		seq[cnt+r-i+1]=a[i];
	solve();
	cout<<ans;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7680kb

input:

3 10
3 7 10

output:

28

result:

ok "28"

Test #2:

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

input:

5 20
3 10 11 14 17

output:

73

result:

ok "73"

Test #3:

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

input:

10 1000000000
136909656 243332691 643531997 505919307 43553384 657638276 57213246 179732866 357373203 182482400

output:

7649951260

result:

ok "7649951260"

Test #4:

score: 0
Accepted
time: 0ms
memory: 7756kb

input:

1 172024959
118390965

output:

172024960

result:

ok "172024960"

Test #5:

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

input:

2 920065252
24963998 580538879

output:

1815166508

result:

ok "1815166508"

Test #6:

score: 0
Accepted
time: 0ms
memory: 7684kb

input:

3 172078788
90217996 89200357 170380183

output:

432676968

result:

ok "432676968"

Test #7:

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

input:

4 440425711
125318960 91140311 293637977 102491554

output:

1442752023

result:

ok "1442752023"

Test #8:

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

input:

5 322827483
22471802 47973794 3707067 27640905 273307033

output:

1512343852

result:

ok "1512343852"

Test #9:

score: -100
Wrong Answer
time: 1ms
memory: 7732kb

input:

72 630313504
112329946 338670434 45608233 444381955 513206139 543955969 420916952 485920423 598657953 568525637 92887514 375155749 230002387 302266710 539300386 433464422 380969627 445990156 239073197 278937451 50602251 494375406 139348725 11780176 601670777 68418714 591190755 96719555 612628609 778...

output:

22618631856

result:

wrong answer 1st words differ - expected: '25015466409', found: '22618631856'