Cod sursa(job #2615220)

Utilizator CryshanaGanea Carina Cryshana Data 13 mai 2020 20:47:36
Problema Transport Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.27 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;

const int N = 16001;
int v[N], n;

int cautbin ( int curent, long long x){
    int rez = 0, pas = 1 << 13;
    while( pas != 0){
        if( (rez + pas) <= n && v[rez + pas] - v[curent] < x)
            rez += pas;
        pas >>= 1;
    }
    return rez;
}

int main()
{
    ifstream in ("transport.in");
    ofstream out ("transport.out");
    int k;
    in >> n >> k;
    for(int i = 1; i <= n; i++){
        in >> v[i];
        v[i] += v[i-1];
    }
    /*int s = ( v[n]/k ) + 1, d = 0;
    if(s < maxim)
        s = maxim;
    int i = 0;
    while ( i < n){
        i = cautbin(i,s);
        d++;
        if(d > k){
            i = 0;
            s++;
            d = 0;
        }
    }*/
    int pas = 1 << 25;
    int rez = 0;
    while( pas != 0){
        if( rez + pas <= v[n]){
            int i = 0, d = 0, u = 99999;
            while ( i < n && u > 0){
                i = cautbin(i, rez + pas);
                d++;
                u--;
            }
            if( d > k )
                rez += pas;
        }
        pas >>= 1;
    }
	out << rez;
    return 0;
}