Cod sursa(job #2912973)

Utilizator asdfdAlexandru Andrei asdfd Data 11 iulie 2022 22:03:44
Problema Transport Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <iostream>
#include <fstream>
using namespace std;

int n, k, v[16005], truck_capacity = -100, cnt;

int main() {
    ifstream fin("transport.in");
    ofstream fout("transport.out");
	fin >> n >> k;
	for (int i = 1; i <= n; ++i) {
        fin >> v[i];
        if (v[i] > truck_capacity) {
            truck_capacity = v[i] - 1;
        }
	}
	int paths = 0, truck_copy, good = 0;
	while(paths != k) {
        ++truck_capacity;
        cnt = 0, paths = 0, truck_copy = truck_capacity;
        for (int i = 1; i <= n; ++i) {
            truck_copy = truck_copy - v[i];
            if (truck_copy - v[i + 1] < 0 && i < n) {
                ++paths;
                truck_copy = truck_capacity;
            }
            if (paths == k && i < n) {
                paths = -12;
                break;
            }
            if (paths == k - 1 && truck_copy > 0 && i == n) {
                ++paths;
            }
        }
	}
	fout << truck_capacity;
	return 0;
}