Cod sursa(job #3174560)

Utilizator marctudor_ghenceaMarc-Tudor Ghencea marctudor_ghencea Data 24 noiembrie 2023 21:52:44
Problema Transport Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <fstream>

using namespace std;

ifstream cin("transport.in");
ofstream cout("transport.out");

int v[16001];

int main()
{
    int n, k;
    cin >> n >> k;
    int maxi = -1;
    for(int i = 1; i<=n; i++){
        cin >> v[i];
        if(v[i] > maxi){
            maxi = v[i];
        }
    }
    int vol = maxi;
    int s;
    bool exit = false;
    while(exit == false){
        s = 0;
        int transport = 0;
        for(int i = 1; i<=n; i++){
            if(transport + v[i] <= vol){
                transport += v[i];
            }
            else{
                s++;
                transport = 0;
            }
        }
        if(s <= k){
            exit = true;
        }
        else{
            vol++;
        }
    }
    cout << vol << " " << s;
    return 0;
}