Pagini recente » Cod sursa (job #1619148) | Cod sursa (job #1371047) | Cod sursa (job #1568990) | Cod sursa (job #483809) | Cod sursa (job #1251866)
#include<stdio.h>
const int NMAX = 100005, VMAX = 1e6;
int k, n, a[NMAX];
bool ok (int gr) {
int s, i;
s = 0;
for(i = 1; i <= n; ++ i) {
if(a[i] > gr)
s += gr;
else
s += a[i];
// fprintf(stderr, " %d", s);
if(s >= gr * k)
return 1;
}
return 0;
}
int bs (int left, int right) {
int mid, last;
while(left <= right) {
mid = (left + right) / 2;
if(ok(mid))
last = mid,
left = mid + 1;
else
right = mid - 1;
}
return last;
}
int main() {
freopen("grupuri.in", "r", stdin);
freopen("grupuri.out", "w", stdout);
int i;
scanf("%d%d", &k, &n);
for(i = 1; i <= n; ++ i)
scanf("%d", &a[i]);
// ok(5);
printf("%d\n", bs(1, VMAX));
return 0;
}