Advertisement
Guest User

Untitled

a guest
Aug 18th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<algorithm>
  4. using namespace std;
  5. int main() {
  6. int n;
  7. cin >> n;
  8.  
  9. vector<int> v(n);
  10. vector<int> time(n);
  11. for (int i = 0; i < n; i++) {
  12. cin >> v[i];
  13. time[i] = max(1000 - v[i], 1);
  14. }
  15.  
  16. int all_time = 0, pos = 0;
  17. for (int i = 0; ; i++) {
  18. int ind = 0;
  19. for (int j = 0; j < n; j++)
  20. if (time[j] < time[ind])
  21. ind = j;
  22.  
  23. int res = abs(ind - pos);
  24. if (res > time[ind]) {
  25. all_time += time[ind];
  26. break;
  27. }
  28. v[ind]++;
  29.  
  30.  
  31. for (int j = 0; j < n; j++) {
  32. if (j == ind)
  33. continue;
  34. time[j] -= time[ind];
  35. if (time[j] < 0) {
  36. break;
  37. }
  38. }
  39.  
  40. all_time += time[ind];
  41. time[ind] = max(1000 - v[ind], 1);
  42. pos = ind;
  43. }
  44.  
  45. cout << all_time;
  46.  
  47. // system("pause");
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement