Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3.  
  4. ifstream fin("secventa.in");
  5. ofstream fout("secventa.out");
  6.  
  7. int n;
  8.  
  9. int main()
  10. {
  11. fin >> n;
  12.  
  13. int x, y, cnt = 1, st, lmax = 0, stMax;
  14. long long sum = 0, sumMax = 0;
  15.  
  16. fin >> x;
  17. sum += x;
  18. for (int i = 2; i <= n; ++i)
  19. {
  20. fin >> y;
  21. if (y % 2 != x % 2)
  22. {
  23. if (cnt == 1)
  24. st = i - 1;
  25. cnt++;
  26. sum += y;
  27. }
  28. else
  29. {
  30. cnt = 1;
  31. sum = y;
  32. }
  33. if (cnt > lmax)
  34. {
  35. lmax = cnt;
  36. sumMax = sum;
  37. stMax = st;
  38. }
  39. else
  40. if (cnt == lmax && sum >= sumMax)
  41. {
  42. sumMax = sum;
  43. stMax = st;
  44. }
  45. x = y;
  46. }
  47.  
  48. fout << stMax << ' ' << stMax + lmax - 1;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement