Cod sursa(job #3367730)

Utilizator Daniel150212daniel munteanu Daniel150212 Data 9 octombrie 2026 22:05:26
Problema Transport Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <fstream>
#include <algorithm>
#define int long long
#define f first
#define s second
using namespace std;
ifstream cin("transport.in");
ofstream cout("transport.out");
int v[200005];
int n, k;
bool sepoate(int x){
    int sum=0;
    int nr=1;
    for(int i=0; i<n; i++){
        if(sum+v[i]<=x) sum+=v[i];
        else {
            sum=v[i];
            nr++;
        }
    }
    return nr<=k;
}
int32_t main()
{
    cin>>n>>k;
    int maxx=0;
    for(int i=0; i<n; i++){
        cin>>v[i];
        maxx=max(maxx, v[i]);
    }
    int st=maxx, dr=200000002;
    while(st<dr){
        int mid=st+(dr-st)/2;
        if(sepoate(mid)){
            dr=mid;
        }
        else st=mid+1;
    }
    cout<<dr;
}