Cod sursa(job #742982)

Utilizator vendettaSalajan Razvan vendetta Data 2 mai 2012 16:54:55
Problema Grupuri Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <fstream>
#include <iostream>

#define nmax 100005
#define ll long long

using namespace std;

int a[nmax], k, n;

ifstream f("grupuri.in");
ofstream g("grupuri.out");

void citeste(){

    f >> k >> n;

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

}

bool check( ll x ){

    ll s = 0;

    for(int i=1; i<=n; i++){//am x grupuri cu cate k componente
        if (a[i] <= x) s += a[i]*1LL;
            else s += x;
    }

    if (s >= k*x*1LL) return 1;
    return 0;

}

void rezolva(){

    ll st = 0;
    ll dr = nmax*1000000*1LL;
    ll sol = 0;

    while(st <= dr){
        ll mij = (st + dr) / 2;
        if (check(mij)){
            sol = mij;
            st = mij + 1;
        }else dr = mij - 1;
    }

    g << sol << "\n";

}

int main(){

    citeste();
    rezolva();

    f.close();
    g.close();

    return 0;

}