10042022-02-22 10:35:04sjKövek (100 pont)cpp11Wrong answer 27/10068ms13004 KiB
#include<bits/stdc++.h>
using namespace std;
//#define DBG

multiset<int> kovek;
int n;

int main() {
	cin>>n;
	int sum=0;
	vector<int> v(n);
	for(int i=0;i<n;i++) {
		cin>>v[i];
		sum+=v[i];
	}
	for(int e : v) {
		kovek.insert(e-sum/n);
		#ifdef DBG
		cerr<<e-sum/n<<' ';
		#endif
	}
	int depth=0;
	kovek.erase(0);
	while(!kovek.empty()) {
		#ifdef DBG
		cerr<<'\n'<<depth<<'\n';
		#endif
		auto mx=prev(kovek.end());
		#ifdef DBG
		cerr<<*mx<<'\n';
		#endif
		auto nearest=kovek.lower_bound(-(*mx));
		if((*mx)+(*(prev(nearest)))<(*mx)+(*nearest)) nearest=prev(nearest);
		#ifdef DBG
		cerr<<*nearest<<'\n';
		#endif
		if(nearest==kovek.end()) break;
		int nv=(*nearest)+*mx;
		kovek.erase(nearest,next(nearest));
		kovek.erase(mx,next(mx));
		kovek.insert(nv);
		kovek.erase(0);
		depth++;
		#ifdef DBG
		for(const int& e : kovek) cerr<<e<<' ';
		cerr<<'\n';
		#endif
	}
	cout<<depth<<endl;
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base27/100
1Accepted0/02ms1736 KiB
2Wrong answer0/068ms12112 KiB
3Accepted5/51ms2232 KiB
4Accepted5/51ms2236 KiB
5Wrong answer0/51ms2240 KiB
6Wrong answer0/51ms2244 KiB
7Accepted5/51ms2244 KiB
8Accepted5/51ms2248 KiB
9Accepted7/71ms2252 KiB
10Wrong answer0/71ms2256 KiB
11Wrong answer0/81ms2268 KiB
12Wrong answer0/81ms2288 KiB
13Wrong answer0/83ms2560 KiB
14Wrong answer0/87ms3300 KiB
15Wrong answer0/821ms5928 KiB
16Wrong answer0/859ms11492 KiB
17Wrong answer0/868ms13004 KiB