Cod sursa(job #2329155)

Utilizator verde.cristian2005Verde Flaviu-Cristian verde.cristian2005 Data 26 ianuarie 2019 13:39:57
Problema Grupuri Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <fstream>
using namespace std;
ifstream in("grupuri.in");
ofstream out("grupuri.out");
int v[100001],k,n;
bool verif(long long grupe)
{
    long long col=1,comp=0,i;
    for(i=n; i>=1&&v[i]>grupe; i--)
    {
        col++;
    }
    if(col>=k)
        return 1;
    for(; i>=1; i--)
    {
        if(comp+v[i]<grupe)
            comp+=v[i];
        else
        {
            comp=(comp+v[i])%grupe;
            col++;
        }
        if(col>k)
            return 1;
    }
    return 0;
}
void cautbin()
{
    long long pas=1LL<<36,r=0;
    while(pas)
    {
        if(verif(r+pas))
            r+=pas;
        pas/=2;
    }
    out<<r;
}
int main()
{
    in>>k>>n;
    for(int i=1; i<=n; i++)
        in>>v[i];
    cautbin();
    return 0;
}