Skip to content

Instantly share code, notes, and snippets.

@juanplopes
Created April 30, 2019 23:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanplopes/f1dd2d39773e144e4a3019dc02fdf7fd to your computer and use it in GitHub Desktop.
Save juanplopes/f1dd2d39773e144e4a3019dc02fdf7fd to your computer and use it in GitHub Desktop.
#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