# Yukicoder No.9 モンスターのレベル上げ

,

http://yukicoder.me/problems/no/9

## implementation

#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
using namespace std;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
template <class T> void setmax(T & a, T const & b) { if (a < b) a = b; }
template <class T> void setmin(T & a, T const & b) { if (b < a) a = b; }
const int inf = 1e9+7;
int main() {
int n; cin >> n;
vector<int> as(n); repeat (i,n) cin >> as[i];
vector<int> bs(n); repeat (i,n) cin >> bs[i];
int ans = inf;
repeat (offset,n) {
reversed_priority_queue<pair<int, int> > que;
for (int a : as) que.emplace(a, 0);
repeat (i,n) {
int b = bs[(offset + i) % n];
int lvl, cnt; tie(lvl, cnt) = que.top(); que.pop();
que.emplace(lvl + b/2, cnt + 1);
}
int max_cnt = 0;
while (not que.empty()) {
int lvl, cnt; tie(lvl, cnt) = que.top(); que.pop();
setmax(max_cnt, cnt);
}
setmin(ans, max_cnt);
}
cout << ans << endl;
return 0;
}


• Thu Dec 15 14:30:50 JST 2016
• 計算量を書き間違えてたので修正