QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#48534#3997. Candy Machine_Vans_#RE 0ms0kbC++1.2kb2022-09-14 15:03:212022-09-14 15:03:23

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-14 15:03:23]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2022-09-14 15:03:21]
  • 提交

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

result: