Pagini recente » Cod sursa (job #2135944) | Cod sursa (job #2956332) | Cod sursa (job #228770) | Cod sursa (job #607431) | Cod sursa (job #1033367)
#include <iostream>
#include <fstream>
#define nmax 100005
#define inf (1LL<<40)
#define ll long long
using namespace std;
ll n, k, v[nmax];
bool check(ll x) {
ll levels = 0LL, onLevel = 0LL;
for(int i=n; i>=1; i--)
if(v[i] >= x) levels++;
else onLevel += v[i];
levels += onLevel / x;
return (levels >= k);
}
int main() {
ifstream f("grupuri.in");
ofstream g("grupuri.out");
f>>k>>n;
for(int i=1; i<=n; i++) f>>v[i];
ll lo = -1LL, mid, hi = inf;
while(hi - lo > 1) {
mid = (lo + hi) >> 1LL;
if(check(mid)) lo = mid;
else hi = mid;
}
g<<lo<<"\n";
return 0;
}