Created
April 30, 2019 23:30
-
-
Save juanplopes/f1dd2d39773e144e4a3019dc02fdf7fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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