Cod sursa(job #2149292)

Utilizator robx12lnLinca Robert robx12ln Data 2 martie 2018 14:45:14
Problema Grupuri Scor 2
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include<fstream>
using namespace std;
ifstream fin("grupuri.in");
ofstream fout("grupuri.out");
int C[100005], K, N;
long long Sum, Sol;
inline int check( long long X ){
    long long S = 0;
    for( int i = 1; i <= N; i++ )
        S += ( C[i] <= K ) ? C[i] : K;
    if( S >= 1LL * X * K )
        return 1;
    return 0;
}
int main(){
    fin >> K >> N;
    for( int i = 1; i <= N; i++ )
        fin >> C[i], Sum += C[i];
    Sum /= K;
    for( long long step = (1LL<<40); step != 0; step >>= 1 )
        if( Sol + step <= Sum && check( Sol + step ) == 1 )
            Sol += step;
    fout << Sol << "\n";
    return 0;
}