fork(1) download
  1.  
  2. ///╭━━━━┳╮╱╱╱╱╱╱╱╭╮╱╱╭━━━╮/////////
  3. ///┃╭╮╭╮┃┃╱╱╱╱╱╱╱┃┃╱╱┃╭━╮┃////////
  4. ///╰╯┃┃╰┫╰━┳━━┳━╮┃╰━╮┃╰━━┳━━┳━╮╭━━╮
  5. ///╱╱┃┃╱┃╭╮┃╭╮┃╭╮┫╭╮┃╰━━╮┃╭╮┃╭╮┫╭╮┃
  6. ///╱╱┃┃╱┃┃┃┃╭╮┃┃┃┃┃┃┃┃╰━╯┃╭╮┃┃┃┃╰╯┃
  7. ///╱╱╰╯╱╰╯╰┻╯╰┻╯╰┻╯╰╯╰━━━┻╯╰┻╯╰┻━╮┃
  8. ///╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╭━╯┃
  9. ///╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╰━━╯
  10.  
  11.  
  12. #include<bits/stdc++.h>
  13. using namespace std;
  14.  
  15. #define endl "\n"
  16. #define maxn 100000
  17.  
  18. int n;
  19.  
  20. struct pt
  21. {
  22. int fr;
  23. int val;
  24. };
  25. pt a[maxn];
  26. bool cmp(pt x, pt y)
  27. {
  28. return x.val < y.val;
  29. }
  30. void process()
  31. {
  32. cin >> n;
  33. for(int i = 1; i <= n ; i++)
  34. {
  35. cin >> a[i].val;
  36. a[i].fr = i;
  37. }
  38. sort(a + 1, a + n + 1, cmp);
  39. int l = 1, r = n;
  40. while(l <= r)
  41. {
  42. if(a[l].fr < a[r].fr)
  43. {
  44. cout << l << " " << r << endl;
  45. cout << a[r].val - a[l].val;
  46. break;
  47. }
  48. if(a[l].fr >= r)
  49. {
  50. l++;
  51. }
  52. else r--;
  53. }
  54. }
  55. int main()
  56. {
  57. ios_base::sync_with_stdio(false);
  58. cin.tie(NULL);cout.tie(NULL);
  59. process();
  60. }
Success #stdin #stdout 0s 5636KB
stdin
Standard input is empty
stdout
Standard output is empty