Cod sursa(job #861084)

Utilizator stoicatheoFlirk Navok stoicatheo Data 20 ianuarie 2013 22:44:25
Problema Grupuri Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 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++){
        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;
 
}