Skip to content

Instantly share code, notes, and snippets.

@juanplopes
Created April 12, 2015 02:22
Show Gist options
  • Save juanplopes/a6e14bc685bef539e943 to your computer and use it in GitHub Desktop.
Save juanplopes/a6e14bc685bef539e943 to your computer and use it in GitHub Desktop.
B
#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