Mai intai trebuie sa te autentifici.
Cod sursa(job #742981)
Utilizator | Data | 2 mai 2012 16:52:01 | |
---|---|---|---|
Problema | Grupuri | Scor | 16 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.81 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(){
int st = 0;
int dr = nmax;
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;
}