Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <set>
- #include <queue>
- #include <map>
- #include <vector>
- #include <stack>
- #include <algorithm>
- #define long long long
- using namespace std;
- struct st{
- vector<long> s;
- vector<long> e;
- };
- void work(vector<st> t, vector<long> a, vector<bool> &used, long n, long &ans, long &people, long &time) {
- long ind = 0;
- for(long i = 1; i <= n; i++) {
- for(long j = 0; j < t[i].s.size(); j++) {
- ind = t[i].s[j];
- if(!used[ind]) {
- used[ind] = true;
- people += a[ind];
- }
- }
- for(long j = 0; j < t[i].e.size(); j++) {
- ind = t[i].e[j];
- if(used[ind]) {
- people -= a[ind];
- used[ind] = false;
- }
- }
- if(people > ans) {
- time = i;
- ans = people;
- }
- }
- }
- int main ()
- {
- long n, s, f, ans = 0, people = 0, time = 0;
- cin >> n;
- vector<long> a(n + 1);
- vector<bool> used(n + 1, false);
- vector<st> t(n + 1);
- for(long i = 1; i <= n; i++) {
- cin >> a[i];
- }
- cin >> s >> f;
- for(long i = 1; i <= n; i++) {
- if(s > n) s = 1;
- if(f > n) f = 1;
- t[s].s.push_back(i);
- t[f].e.push_back(i);
- s++;
- f++;
- }
- work(t, a, used, n, ans, people, time);
- work(t, a, used, n, ans, people, time);
- cout << time;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement