URAL:1917 Titan Ruins: Deadly Accuracy

 

没做出来,写码能力太差,不想说什么了。

 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int a[1000005]= {0};
int main()
{
    int n,p,mx=-1,x;
    scanf("%d%d",&n,&p);
    for(int i=0; i<n; ++i)
    {
        scanf("%d",&x);
       if(x>p) continue;
        a[x]++;
        mx=max(mx,x);
    }
    mx=min(mx,p);
    int maxn=0,minn=0,s=0;
    for(int i=1; i<=mx; ++i)
    {
        if(!a[i]) continue;
        int j=i;
        while((s+a[j])*j<=p&&j<=mx )
        {
            s+=a[j];
            a[j++]=0;
        }
        if(s)
        {
            maxn+=s;
            minn++;
            s=0;
        }
        else break;
    }
    printf("%d %d\n",maxn,minn);
    return 0;
}


 

你可能感兴趣的:(URAL:1917 Titan Ruins: Deadly Accuracy)