Cod sursa(job #264046)

Utilizator jeanFMI - Petcu Ion Cristian jean Data 21 februarie 2009 11:39:39
Problema Grupuri Scor 36
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.47 kb
#include<fstream>
using namespace std;
int v[100010],i,n,k,s,m,d;
unsigned long long S,sum;

int main()
{
ifstream f("grupuri.in");
ofstream g("grupuri.out");

f>>k>>n;
for(i=1;i<=n;i++) {f>>v[i]; S+=v[i];}
d=S/k; s=1;
while(s<=d)
 { m=(s+d)>>1;
   S=0; sum=k*m; i=0;
    while(S<sum&&i<n)
     {  i++;
       if(v[i]<=m) S+=v[i];
          else S+=m;
     }
   if(S>=sum) s=m+1;
    else d=m-1;
  }
g<<m;
f.close();
g.close();
return 0;
}