Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我不知道是哪里有错误,我在Dev编译正确,这里就不行了;

Posted by 159788 at 2022-01-25 10:16:28 on Problem 3253
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N=50000;
int N,L[MAX_N];
void solve() {
	ll ans=0;
	while(N>1) {
		int mii1=0,mii2=1;
		if(L[mii1]>L[mii2]) swap(mii1,mii2);
		for(int i=2;i<N;i++) {
			if(L[i]<L[mii1]) {
				mii2=mii1;
				mii1=i;
			} else if(L[i]<L[mii2]) {
				mii2=i;
			}
		}
		int t=L[mii1]+L[mii2];
		ans+=t;
		if(mii1==N-1) swap(mii1,mii2);
		L[mii1]=t;
		L[mii2]=L[N-1];
		N--;
	}
	printf("%lld\n",ans);
}
int main() {
	cin>>N;
	for(int i=0;i<N;i++) {
		cin>>L[i];
	}
	solve();
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator