Pagini recente » Cod sursa (job #3279092) | Cod sursa (job #2556859) | Cod sursa (job #3279995) | Cod sursa (job #3279877)
#include <bits/stdc++.h>
using namespace std;
ifstream fcin("grupuri.in");
ofstream fcout("grupuri.out");
const int N = 1e5 + 5;
int v[N];
int n, x, k;
long long s;
int cb(int dr)
{
int st, m, p;
long long sum;
st = 0;
p = 0;
while (st <= dr)
{
m = (st + dr) / 2;
sum = 0;
for (int i = 1; i <= n; i++)
sum += min(v[i], m);
/// sum / k >= m
if (sum >= 1ll * k * m)
{
st = m + 1;
p = m;
}
else
dr = m - 1;
}
return p;
}
int main()
{
fcin >> k >> n;
for (int i = 1; i <= n; i++)
{
fcin >> v[i];
s += v[i];
}
fcout << cb(s / k);
return 0;
}