QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#48534 | #3997. Candy Machine | _Vans_# | RE | 0ms | 0kb | C++ | 1.2kb | 2022-09-14 15:03:21 | 2022-09-14 15:03:23 |
Judging History
answer
/*
* @Autor: Van
* @Date: 2022-09-14 14:33:22
* @FilePath: \vsCode\.vscode\codes\23training_2\D.cpp
* @LastEditTime: 2022-09-14 15:02:49
* @Description: 贪心(每次删除最大,若ans值减小则结束)
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <unordered_map>
#include <iomanip>
#define pii pair<int,int>
#define ll long long
using namespace std;
const int MAXN=1e6+10;
const int INF=0x7fffffff;
int a[MAXN];
long double sum=0;
int n=0;
int ans=0;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
for(int i=0;i<n;i++) cin>>a[i];
sort(a,a+n);
for(int i=0;i<n;i++)
{
sum+=a[i];
}
for(int i=0;i<n;i++) if(a[i]>sum/n) ans++;
int now=ans,pre=0,back=n;
while(now>=pre)
{
pre=now;now=0;
int maxnum=a[--back];
sum-=maxnum;
for(int i=0;i<back;i++) if(a[i]>sum/back) now++;
}
ans=max(ans,max(now,pre));
cout<<ans<<endl;
system("pause");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Dangerous Syscalls
input:
5 1 2 3 4 5
output:
2