fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define Task "Test"
  5. #define int long long
  6. #define el '\n'
  7. #define cnt_bit_1 __builtin_popcountll
  8. #define float double
  9. #define IO freopen(Task".inp","r",stdin); freopen(Task".out","w",stdout);
  10. #define pii pair<int,int>
  11. #define fi first
  12. #define se second
  13. #define pb push_back
  14.  
  15. const int N=2e5+5;
  16. const int INF=1e18;
  17. const int MOD=1e9+7;
  18.  
  19. int n, a[N];
  20.  
  21. signed main()
  22. {
  23. ios_base::sync_with_stdio(0);
  24. cin.tie(0);
  25. cout.tie(0);
  26.  
  27. // IO
  28.  
  29. cin >> n;
  30.  
  31. for(int i = 1; i <= n; i++)
  32. cin >> a[i];
  33.  
  34. int mn = a[1];
  35. int pos = 1;
  36.  
  37. int best = LLONG_MIN;
  38. int l = 1, r = 2;
  39.  
  40. for(int j = 2; j <= n; j++)
  41. {
  42. if(a[j] - mn > best)
  43. {
  44. best = a[j] - mn;
  45. l = pos;
  46. r = j;
  47. }
  48.  
  49. if(a[j] < mn)
  50. {
  51. mn = a[j];
  52. pos = j;
  53. }
  54. }
  55.  
  56. cout << l << ' ' << r << el;
  57. cout << best << el;
  58.  
  59. return 0;
  60. }
Success #stdin #stdout 0s 5304KB
stdin
Standard input is empty
stdout
1 2
-9223372036854775808