Cod sursa(job #3319194)

Utilizator andreibancescuAndrei-Stefan Bancescu andreibancescu Data 31 octombrie 2025 01:27:34
Problema Grupuri Scor 36
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <bits/stdc++.h>
using namespace std;

int k, n;
long long a[100005];

int main() {
    ifstream fin("grupuri.in");
    ofstream fout("grupuri.out");

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

    long long st = 0, dr = 1000000000000LL / k + 5, t, sol = 0;
    while(st <= dr) {
        t = (st + dr) / 2;
        long long need = t * k, have = 0;
        for(int i = n; i >= 1 && have < need; i--)
            have += a[i];
        if(have >= need) {
            sol = t;
            st = t + 1;
        } else {
            dr = t - 1;
        }
    }

    fout << sol;
    return 0;
}