Cod sursa(job #2329142)

Utilizator lucaperjuLuca Perju Verzotti lucaperju Data 26 ianuarie 2019 13:26:51
Problema Grupuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <fstream>

using namespace std;
ifstream cin ("grupuri.in");
ofstream cout ("grupuri.out");
int v[100003],n,k;
long long sp[100003];
bool verif (long long cat)
{
	int pas=1<<20,pz=0;
	while(pas)
	{
		if(pz+pas<=n && v[pz+pas]<cat)
			pz+=pas;
		pas>>=1;
	}
	long long tot,need;
	tot=cat*1LL*k;
	need=tot-(n-pz)*1LL*cat;
	if(sp[pz]>=need)
		return true;
	return false;
}
int main()
{
    long long i,j,pz=0,pas=1LL<<(40LL);
    long long s=0;
    cin>>k>>n;
    for(i=1;i<=n;++i)
	{
		cin>>v[i];
		sp[i]=sp[i-1]+v[i];
	}
	while(pas)
	{
		if(verif(pz+pas))
			pz+=pas;
		pas>>=1LL;
	}
	cout<<pz;
    return 0;
}