Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- #include <algorithm>
- #include <set>
- #include <map>
- using namespace std;
- map<long long, long long> m;
- int main()
- {
- int n;
- cin >> n;
- vector<long long> v(n);
- for (int i = 0; i < n; ++i)
- {
- cin >> v[i];
- }
- for (int i = 0; i < n; ++i)
- {
- long long time = 0;
- while (v[i] < 1000)
- {
- time += (1000 - v[i]);
- if (m[time] != 0 && m[time] != i + 1)
- {
- m[time] = -228;
- }
- else
- {
- m[time] = i + 1;
- }
- ++v[i];
- }
- m[time] = -i - 1;
- }
- long long pr = 0;
- bool f = false;
- for (int t = 1; t < 1e8; ++t)
- {
- if (m[t] == -228)
- {
- cout << t;
- return 0;
- }
- if (m[t] != 0)
- {
- if (m[t] < 0)
- {
- if ((abs(abs(m[t]) - m[pr])) > abs(t - pr))
- {
- cout << t;
- return 0;
- }
- f = true;
- }
- else if (f && m[t] != m[pr])
- {
- cout << t;
- return 0;
- }
- else if (!f && abs(m[t] - m[pr]) > abs(t - pr))
- {
- cout << t;
- return 0;
- }
- pr = t;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement