Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<algorithm>
- using namespace std;
- int main() {
- int n;
- cin >> n;
- vector<int> v(n);
- vector<int> time(n);
- for (int i = 0; i < n; i++) {
- cin >> v[i];
- time[i] = max(1000 - v[i], 1);
- }
- int all_time = 0, pos = 0;
- for (int i = 0; ; i++) {
- int ind = 0;
- for (int j = 0; j < n; j++)
- if (time[j] < time[ind])
- ind = j;
- int res = abs(ind - pos);
- if (res > time[ind]) {
- all_time += time[ind];
- break;
- }
- v[ind]++;
- for (int j = 0; j < n; j++) {
- if (j == ind)
- continue;
- time[j] -= time[ind];
- if (time[j] < 0) {
- break;
- }
- }
- all_time += time[ind];
- time[ind] = max(1000 - v[ind], 1);
- pos = ind;
- }
- cout << all_time;
- // system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement