Cod sursa(job #2803982)

Utilizator andiRTanasescu Andrei-Rares andiR Data 20 noiembrie 2021 17:55:25
Problema Grupuri Scor 2
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <fstream>

using namespace std;
ifstream fin ("grupuri.in");
ofstream fout ("grupuri.out");
long long n,k,i;
long long l,r,m,x,sol;
long long v[100100];
int main()
{
    fin>>k>>n;
    for (i=0;i<n;i++)
        fin>>v[i];
    l=0;
    r=100000000000;
    while (l<=r)
    {
        m=(l+r)/2;
        x=0;
        for (i=0;i<n;i++)
        {
            if (v[i]<k)
                x+=v[i];
            else x+=k;
        }
        if (x>=m*k)
        {
            l=m+1;
            sol=m;
        }
        else r=m-1;
    }
    fout<<sol;
    return 0;
}