Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <set>
  4. #include <queue>
  5. #include <map>
  6. #include <vector>
  7. #include <stack>
  8. #include <algorithm>
  9. #define long long long
  10. using namespace std;
  11. struct st{
  12. vector<long> s;
  13. vector<long> e;
  14. };
  15. void work(vector<st> t, vector<long> a, vector<bool> &used, long n, long &ans, long &people, long &time) {
  16. long ind = 0;
  17. for(long i = 1; i <= n; i++) {
  18. for(long j = 0; j < t[i].s.size(); j++) {
  19. ind = t[i].s[j];
  20. if(!used[ind]) {
  21. used[ind] = true;
  22. people += a[ind];
  23. }
  24. }
  25. for(long j = 0; j < t[i].e.size(); j++) {
  26. ind = t[i].e[j];
  27. if(used[ind]) {
  28. people -= a[ind];
  29. used[ind] = false;
  30. }
  31. }
  32. if(people > ans) {
  33. time = i;
  34. ans = people;
  35. }
  36. }
  37. }
  38. int main ()
  39. {
  40. long n, s, f, ans = 0, people = 0, time = 0;
  41. cin >> n;
  42. vector<long> a(n + 1);
  43. vector<bool> used(n + 1, false);
  44. vector<st> t(n + 1);
  45. for(long i = 1; i <= n; i++) {
  46. cin >> a[i];
  47. }
  48. cin >> s >> f;
  49. for(long i = 1; i <= n; i++) {
  50. if(s > n) s = 1;
  51. if(f > n) f = 1;
  52. t[s].s.push_back(i);
  53. t[f].e.push_back(i);
  54. s++;
  55. f++;
  56. }
  57. work(t, a, used, n, ans, people, time);
  58. work(t, a, used, n, ans, people, time);
  59. cout << time;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement