Skip to content

Instantly share code, notes, and snippets.

@juanplopes juanplopes/1579.cpp
Created Apr 30, 2019

Embed
What would you like to do?
#include <iostream>
using namespace std;
int X[200];
int trucks(int P, int maximum) {
int count = 0, current = 0;
for(int i=0; i<P; i++) {
if (X[i] > maximum) return 10000000;
if (current + X[i] > maximum) {
count++;
current=0;
}
current += X[i];
}
if (current > 0) count++;
return count;
}
int lower(int P, int T, int first, int last) {
int count = last - first;
while (count>0) {
int it = first, step=count/2;
it += step;
if (trucks(P, it) > T) {
first=++it;
count-=step+1;
}
else count=step;
}
return first;
}
int main() {
ios_base::sync_with_stdio(false);
int tests; cin >> tests;
int P, T, F;
while(cin >> P >> T >> F) {
for(int i=0; i<P; i++)
cin >> X[i];
int answer = lower(P, T, 0, 100000000);
cout << answer << " $" << answer*F*T << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.