Cod sursa(job #2251400)

Utilizator DordeDorde Matei Dorde Data 1 octombrie 2018 16:11:01
Problema Transport Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <fstream>

using namespace std;
ifstream f ("transport.in");
ofstream g ("transport.out");
int const NM = 16007;
int v [NM] , n , k;
inline bool check (int nr){
    int S = 0 , step = 0;
    for(int i = 1 ; i <= n ; i){
        S = 0;
        if (v [i] > nr)
            return 0;
        while (i <= n && S + v [i] <= nr)
            S += v [i] , ++ i;
        if (v [i] > nr)
            return 0;
        ++ step;

    }
    if (step <= k)
        return 1;
    return 0;
}
inline int bsearch (){
    int pas = (1 << 13) , found = 0;
    while (pas){
        if (! check (pas + found))
            found += pas;
        pas /= 2;
    }
    return found + 1;
}
int main()
{
    int i;
    f >> n >> k;
    for(i = 1 ; i <= n ; ++ i)
        f >> v [i];
    g << bsearch ();
    return 0;
}