Created
April 12, 2015 02:22
-
-
Save juanplopes/a6e14bc685bef539e943 to your computer and use it in GitHub Desktop.
B
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> | |
#include <queue> | |
#include <cmath> | |
using namespace std; | |
priority_queue<int> Q, T; | |
int main() { | |
int test=0, tests; cin >> tests; | |
int D; | |
while(cin >> D) { | |
Q = priority_queue<int>(); | |
for(int i=0; i<D; i++) { | |
int temp; cin >> temp; | |
Q.push(temp); | |
} | |
int best = Q.top(); | |
for(int target=1; target<=Q.top(); target++) { | |
cerr << " " << target << " " << Q.top() << endl; | |
T = Q; | |
int steps = 0; | |
while(T.top() > target) { | |
int top = T.top(); T.pop(); | |
T.push(target); | |
T.push(top-target); | |
steps++; | |
best = min(best, T.top()+steps); | |
} | |
} | |
cout << "Case #" << ++test << ": " << best << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment