Pagini recente » Cod sursa (job #2473540) | Cod sursa (job #447660) | Cod sursa (job #1000339) | Cod sursa (job #2472541) | Cod sursa (job #1023718)
// :: BruteForce ::
#include <fstream>
using namespace std;
ifstream is ("transport.in");
ofstream os ("transport.out");
int a[16001], n, k, sol;
bool Found;
int cnt, s;
int main()
{
is >> n >> k;
for (int i = 1; i <= n; ++i)
{
is >> a[i];
if (a[i] > sol)
sol = a[i];
}
while (Found == false)
{
cnt = 0;
s = 0;
for (int i = 1; i <= n; ++i)
{
s += a[i];
if (s + a[i+1] > sol)
cnt++, s = 0;
}
if (cnt == k-1)
Found = true;
sol++;
}
sol--;
os << sol;
is.close();
os.close();
return 0;
}