Cod sursa(job #3272742)

Utilizator aadsafafdfAlexandru Spermezist aadsafafdf Data 30 ianuarie 2025 20:05:33
Problema Transport Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.87 kb
#ifdef LOCAL
#include <bits/stdc++.h>
using namespace std;
ifstream fin("file.in");
ofstream fout("file.out");
#else
#include <bits/stdc++.h>
using namespace std;
ifstream fin("buldo.in");
ofstream fout("buldo.out");
#endif

int n,v[100005],k,macs,inf=300000000;

int drumuri(int cox)
{
    int aux=0,cnt=0,i=1;
    while(i<=n)
    {
        cnt++;
        aux=0;
        while(aux+v[i]<=cox)
        {
            aux+=v[i];
            ++i;
        }
    }
    return cnt;
}

int binsrc()
{
    int l=macs,h=inf,mid;
    while(l<h)
    {
        mid=(l+h)/2;
        if(drumuri(mid)>k)
        {
            l=mid+1;
        }
        else h=mid;
    }
    return h;
}


int main()
{
    fin>>n>>k;
    for(int i=1;i<=n;++i)
    {
        fin>>v[i];
        macs=max(macs,v[i]);
    }
    fout<<binsrc();

    return 0;
}