Cod sursa(job #3138767)

Utilizator maryyMaria Ciutea maryy Data 22 iunie 2023 00:58:00
Problema Grupuri Scor 4
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <fstream>

using namespace std;
ifstream in("grupuri.in");
ofstream out("grupuri.out");
int v[100001], n, k;
bool SeFormeaza(int g)
{
    int x=0;
    for(int i=1; i<=n; i++)
    {
        x+=min(v[i], g);
    }
    return (g*k<=x);
}
int main()
{
    int st=0, dr=1000000000, g;
    in>>k>>n;
    for(int i=1; i<=n; i++)
    {
        in>>v[i];
    }
    int r=0;
    while(st<dr)
    {
        g=(st+dr)/2;
        if(SeFormeaza(g)==1)
        {
            r=g;
            st=g+1;
        }
        else
        {
            dr=g-1;
        }
    }
    out<<r;
}