Pagini recente » Cod sursa (job #1104896) | Cod sursa (job #601583) | Cod sursa (job #530990) | Cod sursa (job #1713788) | Cod sursa (job #468113)
Cod sursa(job #468113)
#include<fstream>
using namespace std;
bool test(int v);
int n, k, cant[100001];
int main()
{
ifstream fin("grupuri.in");
ofstream fout("grupuri.out");
fin >> k >> n;
for (int i = 1; i <= n; ++i)
fin >> cant[i];
int step, i;
for (step = 1; step << 1 <= 1000000000; step <<= 1);
for (i = 0; step; step >>= 1)
if (i + step <= n && test(i + step))
i += step;
fout << i;
}
bool test(int v)
{
int i, s = 0;
for (i = 1; i <= n; ++i)
if (cant[i] < v) s += cant[i];
else break;
s += v * (n - i + 1);
return s >= v * k;
}