Advertisement
Dennnhhhickk

Untitled

Nov 2nd, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. // И.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. //#include "stdafx.h"
  5. #include <iostream>
  6. #include <cmath>
  7. #include <iomanip>
  8. #include <algorithm>
  9. #include <cstdlib>
  10. #include <map>
  11. #include <string>
  12. #include <set>
  13. #include <vector>
  14.  
  15. using namespace std;
  16.  
  17. long long a[1000010], d[1000010];
  18. map <long long, long long> b;
  19.  
  20. int main()
  21. {
  22. ios::sync_with_stdio(0);
  23. cin.tie(0);
  24. cout.tie(0);
  25. long long n, data;
  26. cin >> n;
  27. for (int i = 0; i < n; i++)
  28. {
  29. cin >> data;
  30. b[data] = -1;
  31. a[i] = data;
  32. }
  33. d[0] = 0;
  34. for (int i = 1; i < n; i++)
  35. d[i] = d[i - 1] + a[i];
  36. long long ans = -1e15, ansl, ansr;
  37. for (int i = 0; i < n; i++)
  38. {
  39. if (a[i] > ans)
  40. {
  41. ans = a[i];
  42. ansl = i;
  43. ansr = i;
  44. }
  45. if (b[a[i]] == -1)
  46. b[a[i]] = i;
  47. else
  48. if (ans < -d[b[a[i]]] + d[i] + a[b[a[i]]])
  49. {
  50. ans = -d[b[a[i]]] + d[i] + a[b[a[i]]];
  51. ansl = b[a[i]];
  52. ansr = i;
  53. }
  54. }
  55. if (ans != -1e15)
  56. {
  57. cout << ans << endl << ansl + 1 << ' ' << ansr + 1 << endl;
  58. }
  59. //system("pause");
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement