Cod sursa(job #3279877)

Utilizator Carnu_EmilianCarnu Emilian Carnu_Emilian Data 24 februarie 2025 17:20:14
Problema Grupuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fcin("grupuri.in");
ofstream fcout("grupuri.out");

const int N = 1e5 + 5;
int v[N];
int n, x, k;
long long s;

int cb(int dr)
{
    int st, m, p;
    long long sum;
    st = 0;
    p = 0;
    while (st <= dr)
    {
        m = (st + dr) / 2;
        sum = 0;
        for (int i = 1; i <= n; i++)
            sum += min(v[i], m);
        /// sum / k >= m
        if (sum >= 1ll * k * m)
        {
            st = m + 1;
            p = m;
        }
        else
            dr = m - 1;
    }
    return p;
}

int main()
{
    fcin >> k >> n;
    for (int i = 1; i <= n; i++)
    {
        fcin >> v[i];
        s += v[i];
    }
    fcout << cb(s / k);
    return 0;
}