Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <set>
  6. #include <map>
  7.  
  8. using namespace std;
  9.  
  10. map<long long, long long> m;
  11.  
  12. int main()
  13. {
  14. int n;
  15. cin >> n;
  16. vector<long long> v(n);
  17. for (int i = 0; i < n; ++i)
  18. {
  19. cin >> v[i];
  20. }
  21.  
  22. for (int i = 0; i < n; ++i)
  23. {
  24. long long time = 0;
  25. while (v[i] < 1000)
  26. {
  27. time += (1000 - v[i]);
  28. if (m[time] != 0 && m[time] != i + 1)
  29. {
  30. m[time] = -228;
  31. }
  32. else
  33. {
  34. m[time] = i + 1;
  35. }
  36. ++v[i];
  37. }
  38. m[time] = -i - 1;
  39. }
  40.  
  41. long long pr = 0;
  42. bool f = false;
  43. for (int t = 1; t < 1e8; ++t)
  44. {
  45. if (m[t] == -228)
  46. {
  47. cout << t;
  48. return 0;
  49. }
  50.  
  51. if (m[t] != 0)
  52. {
  53. if (m[t] < 0)
  54. {
  55. if ((abs(abs(m[t]) - m[pr])) > abs(t - pr))
  56. {
  57. cout << t;
  58. return 0;
  59. }
  60. f = true;
  61. }
  62. else if (f && m[t] != m[pr])
  63. {
  64. cout << t;
  65. return 0;
  66. }
  67. else if (!f && abs(m[t] - m[pr]) > abs(t - pr))
  68. {
  69. cout << t;
  70. return 0;
  71. }
  72. pr = t;
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement