Cod sursa(job #2937827)

Utilizator Mihai00700Mihai Ghetu Mihai00700 Data 11 noiembrie 2022 09:27:54
Problema Transport Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <fstream>

using namespace std;
ifstream cin("transport.in");
ofstream cout("transport.out");
int n, t;
const int CMAX = 256e6;
const int N = 16e3;
int v[N];
bool se_poate(int c){
    int cc = 0, nrt = 0;
    for(int i = 0;i<n;i++){
        if(v[i] > cc){
            cc = c;
            nrt++;
        }
        if(nrt > t){
            return false;
        }
        cc -= v[i];
    }
    return true;
}
int main(){
    int rez, dr, st;
    cin>>n>>t;
    st = 1;
    dr = CMAX;
    rez = CMAX + 1;
    for(int i = 0;i<n;i++){
        cin>>v[i];
        st = max(st, v[i]);
    }
    while(st <= dr){
        int m = (st + dr) /2;
        if(se_poate(m)){
            rez = m;
            dr = m- 1;
        }else{
            st = m + 1;
        }
    }
    cout<<rez;
    cin.close();
    cout.close();
    return 0;
}