Advertisement
jbn6972

ques

Oct 16th, 2021
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. import sys
  2. import os
  3. if not os.environ.get("ONLINE_JUDGE"):
  4.     sys.stdin = open('./in.txt', 'r')
  5.     sys.stdout = open('./out.txt', 'w')
  6.  
  7. def totalPairs(n, values):
  8.     # Participants code will be here
  9.     res = 0
  10.     # max_val = -sys.maxsize
  11.     for i in range(n-2):
  12.         sub_max = values[i+1]
  13.         for j in range(i+2,n):
  14.             if values[i] > sub_max and values[j] > sub_max:
  15.                 # print(values[i],values[j])
  16.                 res += 1
  17.             sub_max = max(sub_max,values[j])
  18.  
  19.     return res
  20.  
  21.  
  22.  
  23. if __name__ == "__main__":
  24.     n = int(input())
  25.     values = list(map(int, input().split()))
  26.     answer = totalPairs(n, values)
  27.     print(answer+(n-1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement