Cod sursa(job #1502346)

Utilizator Alexa2001Alexa Tudose Alexa2001 Data 14 octombrie 2015 16:25:37
Problema Grupuri Scor 2
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <fstream>

using namespace std;
int k,n,x,a[100009],i,st,dr,mj;

inline bool OK(int x)
{
    int i;long long nr=0LL;
    for(i=1;i<=n;++i)
    if(a[i]<x) nr+=a[i];
    else nr+=k;

    if(nr/k>=x) return 1;
    return 0;
}
int main()
{
    ifstream f("grupuri.in");
    ofstream g("grupuri.out");

    f>>k>>n;
    for(i=1;i<=n;++i) f>>a[i];

    st=1;dr=n;
    while(st<=dr)
    {
        mj=(st+dr)/2;
        if(OK(mj)) st=mj+1;
        else dr=mj-1;
    }

    g<<dr<<'\n';
    return 0;
}