10032022-02-22 10:28:59sjKövek (100 pont)cpp11Wrong answer 27/10065ms13008 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));
		#ifdef DBG
		cerr<<*nearest<<'\n';
		#endif
		if(nearest==kovek.end()) break;
		int nv=(*nearest)+*mx;
		kovek.erase(nearest,next(nearest));
		kovek.erase(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/02ms1776 KiB
2Wrong answer0/065ms12116 KiB
3Accepted5/51ms2236 KiB
4Accepted5/51ms2244 KiB
5Wrong answer0/51ms2252 KiB
6Wrong answer0/51ms2244 KiB
7Accepted5/51ms2256 KiB
8Accepted5/51ms2260 KiB
9Accepted7/71ms2264 KiB
10Wrong answer0/71ms2272 KiB
11Wrong answer0/81ms2280 KiB
12Wrong answer0/81ms2296 KiB
13Wrong answer0/82ms2560 KiB
14Wrong answer0/86ms3308 KiB
15Wrong answer0/820ms5936 KiB
16Wrong answer0/854ms11500 KiB
17Wrong answer0/864ms13008 KiB