Pagini recente » Cod sursa (job #2613115) | Cod sursa (job #661906) | Cod sursa (job #1394774) | Cod sursa (job #3171857) | Cod sursa (job #2625198)
// tema_sd_mare.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <fstream>
#include <algorithm>
#define N 16000
using namespace std;
ifstream fin("transport.in");
ofstream fout("transport.out");
int n, k, saltele[N];
void citire() {
fin >> n >> k;
for (int i = 0; i < n; i++)fin >> saltele[i];
}
bool verif(int x) {
int nr_transp = 0, rest = 0, i;
for (i = 0; i < n; i++) {
if (rest < saltele[i]) {
nr_transp++;
rest = x;
}
rest -= saltele[i];
}
return (nr_transp <= k);
}
long long cb(long long st, long long dr) {
int sol;
while (st < dr) {
long long m = (st + dr) / 2;
if (verif(m)) {
sol = m;
dr = m - 1;
}
else st = m + 1;
}
return sol;
}
int maxim() {
int maxi = -1, i;
for (i = 0; i < n; i++)
if (maxi < saltele[i])maxi = saltele[i];
return maxi;
}
int main() {
citire();
fout << cb(1, 16000* 16000);
return 0;
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file