Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
#include <bits/stdc++.h> using namespace std; void primeSieve(int *prime) { for (int i = 3; i <= 1000000; i += 2) { prime[i] = 1; } for (long long i = 3; i <= 1000000; i += 2) { if (prime[i] == 1) { for (long long j = i * i; j < 1000000; j += i) { prime[j] = 0; } } } prime[2] =...
CPP
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
import sys t = int(sys.stdin.readline()) for _ in range(t): n = int(sys.stdin.readline()) l = list(map(int, sys.stdin.readline().split())) c = l[-1] index = n - 1 u = True while True: if index < 0: break if u: if l[index] >= c: c = l[ind...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
def answer(n,A): count=1 flag=0 for i in range(n-1,0,-1): if A[i]-A[i-1]<=0 and flag==0: count+=1 elif A[i]-A[i-1]>=0: flag=1 count+=1 else: break return n-count t=int(input()) for i in range(t): ...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
import sys input = sys.stdin.readline for nt in range(int(input())): n = int(input()) a = list(map(int,input().split())) if n==1: print (0) continue dec = 0 ind = -1 for i in range(n-2,-1,-1): if a[i]<a[i+1]: dec = 1 elif a[i]>a[i+1] and dec: ind = i break print (ind+1)
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
from math import * # n, k = map(int, input().split()) tests = int(input()) for t in range(tests): n = int(input()) a = list(map(int, input().split())) len = 0 prev = 0 for i in range(n - 1, -1, -1): if a[i] < prev: break len += 1 prev = a[i] if a[i] < pr...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T &ret) { char c; int sgn; if (c = getchar(), c == EOF) return; while (c != '-' && (c < '0' || c > '9')) c = getchar(); sgn = (c == '-') ? -1 : 1; ret = (c == '-') ? 0 : (c - '0'); while (c = getchar(), c >= '0' && c <= '9')...
CPP
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
import math t=int(input()) for w in range(t): n=int(input()) l=[int(i) for i in input().split()] k=l[n-1] c=-1 for i in range(n-1,-1,-1): if(l[i]!=k): c=i break if(c==-1): print(0) else: if(l[c]<k): m=c for i in range(c-...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
def solve(n, nums): if n == 1: return 0 pos = n-1 while nums[pos] <= nums[pos-1] and pos> 0: pos -= 1 while nums[pos] >= nums[pos-1] and pos> 0: pos -= 1 return pos T = int(input()) for t in range(T): n = int(input()) nums = list(map(int,input().split())) print(so...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using namespace std::chrono; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); long long t; cin >> t; while (t--) { long long n; cin >> n; long long arr[n]; for (long long...
CPP
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
if __name__ == "__main__": t = int(input()) for i in range(t): n = int(input()) l = list(map(int, input().split())) i = n-1 while i>0 and l[i-1]>=l[i] : i-=1 ## At Pivot Point while i>0 and l[i-1]<=l[i]: i-=1 print(i)
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
# -*- coding: utf-8 -*- """ Created on Mon Jul 20 20:07:54 2020 @author: Akshay """ t = int(input()) for _ in range(t): n = int(input()) arr = list(map(int,input().split())) pos = n-1 while pos >= 1: if arr[pos-1] >= arr[pos]: pos-=1 else: break while ...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
t = int(input()) for _ in range(t): n = int(input()) a= list(map(int,input().split())) pos = n-1 while (pos > 0 and a[pos - 1] >= a[pos]): pos-=1 while (pos >0 and a[pos - 1] <= a[pos]): pos-=1 print(pos)
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
import java.util.*; import java.io.*; public class Main { public static void main(String args[])throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw=new PrintWriter(System.out); int t=Integer.parseInt(br.readLine()); while(t-->...
JAVA
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
T=int(input()) for _ in range(T): n=int(input()) s=list(map(int,input().split())) count=n-1 if sorted(s)==s: print(0) else: while(count>0) and s[count]<=s[count-1]: count-=1 while(count>0) and s[count]>=s[count-1]: count-=1 print(count)
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
from collections import Counter t = int(input()) MAXX = 2*(10**5)+7 while t: t -=1 n = int(input()) arr = [int(x) for x in input().split()] counter = Counter(arr) # print(counter)/ sarr = sorted(arr) i = 0 res = 0 s,e = 0,n-1 while i < n: # print(counter) if count...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
t=int(input()) for _ in range(t): n=int(input()) list1=list(int(n) for n in input().split()) list1.reverse() for i in range(1,len(list1)): if(list1[i-1]<=list1[i]): pass else: break if(n==1): print(0) else: flag=0 if(i==len(list1)...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 210000; int t, n, ans = 0; int a[MAXN], maxl[MAXN], maxr[MAXN]; void solve() { scanf("%d", &n); ans = 0; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } int maxr = 0, minr = MAXN; for (int i = n; i >= 1; --i) { if (a[i] > minr) { ...
CPP
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> arr(n); for (int i = 0; i < n; i++) { cin >> arr[i]; } vector<int> arr1 = arr; vector<int> arr2 = arr; int res = 0; sort(arr1.begin(), arr1.end()); s...
CPP
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
for test_case in range(int(input())): length = int(input()) arr = list(map(int, input().split())) ans = [] flag = False for x in range(length - 1, 0, -1): if not flag: if arr[x] > arr[x - 1]: flag = True ans.append(arr[x]) else: ...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
def solve(n,ar): ptr = n-1 while ptr > 0 and ar[ptr] <= ar[ptr-1]: ptr -= 1 while ptr > 0 and ar[ptr] >= ar[ptr-1]: ptr -= 1 print(ptr) if __name__ == '__main__': t = int(input()) for _ in range(t): n = int(input()) ar = list(map(int,input().split())) ...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
for _ in range(int(input())): n = int(input()) l = list(map(int,input().split())) if n<3 or sorted(l) == l: print(0) continue elif sorted(l,reverse=True) == l: print(0) continue ind = 0 for i in range(n-2,-1,-1): if l[i+1] > l[i]: ind = i break ans = 0 for i in range(ind-1,-1,-1): if l[...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
for _ in range(int(input())): n = int(input()) a = [*map(int, input().split())] ans = n-1 while ans and a[ans]<=a[ans-1]: ans -= 1 while ans and a[ans]>=a[ans-1]: ans -= 1 print(ans)
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
def good(arr): flag = 0 index = 0 for i in range (len(arr)-1,0,-1): if arr[i] > arr[i-1]: flag = 1 if flag == 1: if arr[i] < arr[i-1]: index = i break return(index) t = int(input()) for i in range (0,t): n = int(input()) a...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
for _ in range(int(input())): n=int(input()) arr=list(map(int,input().split())) val=0 j=(n-1) while j>0: if arr[j]<=arr[j-1]: val+=1 j-=1 else: break if j==0: val+=1 else: i=j while i>0: if arr[i]>=arr[i-...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
i = int(input()) while(i>0): i = i-1 c = int(input()) v = list(map(int,input().strip().split()))[:c] f = 1 while(f < c and v[c-f-1]>= v[c-f]): f =f+1 while (f < c and v[c - f - 1] <= v[c - f]): f = f + 1 print(c-f)
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
for i in range(int(input())): n=int(input()) sa=list(map(int,input().split())) k=n-1 while k>0 and sa[k-1]>=sa[k]:k-=1 while k>0 and sa[k-1]<=sa[k]:k-=1 print(k)
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
#!/usr/local/bin/python3 """ Given an array arr consisting of n integers, you hav eto find the length of the shortest prefix of elems you need to erase to make it a good array. An array is good if you can get a non-decreasing array C by performing the following operation repeatedly: - Take either the first or the e...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
import io import os from collections import Counter, defaultdict, deque def solve(N, A): temp = [A.pop()] while A and A[-1] >= temp[-1]: temp.append(A.pop()) while A and A[-1] <= temp[-1]: temp.append(A.pop()) #print(A, temp[::-1]) return N - len(temp) if __name__ == "__main__":...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
try: for _ in range(int(input())): n=int(input()) arr=[int(i) for i in input().split()] ans=n-1 while ans>0 and arr[ans-1]>=arr[ans]: ans-=1 while ans>0 and arr[ans-1]<=arr[ans]: ans-=1 print(ans) except: pass
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
from collections import Counter t=int(input()) for _ in range(t): n=int(input()) l=list(map(int,input().split())) l.reverse() i=0 while(i<n-1 and l[i+1]>=l[i]): i+=1 while(i<n-1 and l[i+1]<=l[i]): i+=1 print(n-i-1)
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) if n <= 1: print(0) continue x = n-1 flag = 1 while x>0 and a[x-1] >= a[x]: x-=1 while x>0 and a[x-1] <= a[x]: x-=1 print(x)
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
# @author --> ajaymodi # Naive approach import sys # sys.stdin=open("input.in","r") # sys.stdout=open("output.out","w") input=lambda : sys.stdin.readline().strip() char = [chr(i) for i in range(97,123)] CHAR = [chr(i) for i in range(65,91)] mp = lambda:list(map(int,input().split())) INT = lambda:int(input()) rn = lamb...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
for i in range(int(input())): n=int(input()) l= [int(i) for i in input().split()] lis=[] i=n-1 while (i>0) and (l[i]<=l[i-1]): i-=1 j=i while (j>0) and (l[j]>=l[j-1]): j-=1 if (n==0): print(0) else: print(j)
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) i=n-1 while i and a[i-1]>=a[i]: i-=1 while i and a[i-1]<=a[i]: i-=1 print(i)
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
import os import sys from io import BytesIO, IOBase from collections import Counter from collections import deque from collections import OrderedDict import heapq import math import statistics MAX = float('inf') MIN = float('-inf') # Fast IO Template starts BUFSIZE = 8192 class FastIO(IOBase): newline...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
import java.io.*; import java.util.*; public class Abc { public static void main(String[] args) throws IOException{ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for (int i=0;i<t;i++){ sol(sc); } } static void sol(Scanner sc){ int n=sc.nextInt();...
JAVA
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
#include <bits/stdc++.h> using namespace std; int main() { int T; cin >> T; while (T--) { int N; cin >> N; vector<int> nums(N); for (int i = 0; i < N; i++) cin >> nums[i]; int a = nums.size() - 1; while (a > 0 && nums[a] <= nums[a - 1]) a--; while (a > 0 && nums[a] >= nums[a - 1]) a--;...
CPP
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
for _ in " "*int(input()): n,a=int(input()),list(map(int,input().split())) k=n-1 while k>0 and a[k-1]>=a[k]:k-=1 while k>0 and a[k-1]<=a[k]:k-=1 print(k)
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
from sys import stdout from sys import stdin def get(): return stdin.readline().strip() def getf(): return [int(i) for i in get().split()] def put(a, end = "\n"): stdout.write(str(a) + end) def putf(a, sep = " ", end = "\n"): stdout.write(sep.join(map(str, a)) + end) def solve(n, a): if(n < 3): ...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } if (n == 1 || n == 2) { cout << 0 << endl; } else { i...
CPP
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
from collections import deque t = int(input()) k = [] for i in range(t): ans = 0 n = int(input()) a = deque(map(int, input().split())) j = len(a) - 1 while j > 0 and a[j] <= a[j - 1]: ans += 1 j -= 1 while j > 0 and a[j] >= a[j - 1]: ans += 1 j -= 1 k.append(...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
t=int(input()) for _ in range(t): n=int(input()) arr=list(map(int,input().split())) c=False ind=0 for i in range(n-1,0,-1): if(c==False): if(arr[i]>arr[i-1]): c=True else: if(arr[i-1]>arr[i]): ind=i break print(ind)
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
import java.util.*; public class Solution { static String str; public static void main(String[] args) { Scanner input=new Scanner(System.in); int t=input.nextInt(); while (t-->0){ int n=input.nextInt(); int a[]=new int[n]; for (int i = 0; i ...
JAVA
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
from sys import stdin def main(): l = stdin.read().splitlines()[2::2] for i, s in enumerate(l): xx = list(map(int, s.split())) le = len(xx) - 1 if le < 2: l[i] = '0' continue while le: if xx[le - 1] < xx[le]: break ...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
import java.util.*; public class Test { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0;i<t;i++) { int n=sc.nextInt(); int a[]=new int[n]; int ans=0; for(int j=0;j<n;j++) ...
JAVA
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
for u in range(int(input())): n=int(input()) l=list(map(int,input().split())) if(l==sorted(l)): print(0) else: c=0 i=n-1 while(i>0): if(l[i]<=l[i-1]): i=i-1 c=c+1 else: break x=i i=x ...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
/****************************************************************************** Welcome to GDB Online. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. Code, Compile, Run and Debu...
JAVA
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
#include <bits/stdc++.h> using namespace std; const long long int N = 1e5 + 5; void solve() { bool flag = 0; long long int n, ans = 0, temp = 0; cin >> n; long long int a[n]; for (long long int i = 0; i < n; i += 1) cin >> a[i]; for (long long int i = 0; i < n - 1; i += 1) { if (a[i] > a[i + 1]) { ...
CPP
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
import java.util.*; import java.io.*; public class MakeItGood { public static void main(String[] args) { Scanner in = new Scanner(System.in); OutputStream outputStream = System.out; PrintWriter out = new PrintWriter(outputStream); int T; T=in.nextInt(); while((T...
JAVA
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
import java.io.*; import java.util.*; import javax.tools.DocumentationTool.Location; import java.math.*; import java.net.StandardSocketOptions; public class Main { static long sx = 0, sy = 0, mod = (long) (998244353); static ArrayList<Integer>[] a; static ArrayList<Long> p; static HashMap<ArrayList<Integer>, ...
JAVA
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
T = int(input()) for _ in range(T): n = int(input()) a = list(map(int, input().split())) okk = 1 while (okk<n and a[n-okk]<=a[n-okk-1]): okk+=1 while (okk<n and a[n-okk]>=a[n-okk-1]): okk+=1 print(n-okk)
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
T = int(input()) for case in range(T): n = int(input()) a = list(map(int, input().split())) idx = n - 1 while idx > 0 and a[idx - 1] >= a[idx]: idx -= 1 while idx > 0 and a[idx - 1] <= a[idx]: idx -= 1 print(idx)
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
import sys def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) def solve(): n = mint() a = list(mints()) l = -1 r = n - 1 while r - l > 1: c = (l + r) // 2 p = -1 ll = c rr = n-1 ok = True #print(c) while ll <= rr: if l...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
import java.util.*; import java.io.*; public class Main{ public static void main(String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); while(t-- >0){ int n= Integer.parseInt(br.readLine()); int...
JAVA
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
def sol(): n = int(input()) l=list(map(int,input().split())) x = l[::-1] v = n b = 0 for i in range(1,n): if b==0: if x[i] < x[i-1]: b+=1 if b==1: if x[i] > x[i-1]: break v-=1 print(v-1) try: for _ in range(...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.sql.Array; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Map.Entry; import java.util.*; public class a { static long mod = 1000000007L; public static void main(String[] args) thro...
JAVA
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
for _ in range(int(input())): n=int(input()) arr=[int(x) for x in input().split()] ans=-1 temp=1 for i in range(n-1,0,-1): if arr[i]<=arr[i-1]: temp+=1 else: break ans=max(ans,temp) temp=1 for i in range(n-1,0,-1): if arr[i]>=arr[i-1]: ...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
import sys import os from io import BytesIO, IOBase # credits of fastio to PyRival project in Github(https://github.com/cheran-senthil/PyRival) # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() ...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
import java.awt.*; import java.io.*; import java.util.*; import java.util.List; public class C { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } ...
JAVA
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
def solution(arr): p = 0 for i in range(len(arr)-1,0,-1): if arr[i] > arr[i-1] : p = i break # print('Val',p) l = -1 for j in range(p): if arr[j] > arr[j+1]: l = j return l + 1 for _ in range(int(input())): n = int(input()) arr = [...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
#include <bits/stdc++.h> using namespace std; void solve(long n, vector<long> arr) { int fg = 0; for (long i = 0; i < n - 1; i++) { if (arr[i + 1] - arr[i] >= 0) fg = 1; else { fg = 0; break; } } if (fg == 1) { cout << "0" << "\n"; return; } else { long pos =...
CPP
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
#include <bits/stdc++.h> using namespace std; int t, n, a[233333], k; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); scanf("%d", &t); while (t--) { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); k = n; while (a[k - 1] >= a[k] && k > 1) k--; while (a[k - 1] <...
CPP
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
import sys, os, io def rs(): return sys.stdin.readline().rstrip() def ri(): return int(sys.stdin.readline()) def ria(): return list(map(int, sys.stdin.readline().split())) def ws(s): sys.stdout.write(s + '\n') def wi(n): sys.stdout.write(str(n) + '\n') def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n') ...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) peak=n-1 while peak>0 and l[peak-1]>=l[peak]: peak-=1 while peak>0 and l[peak-1]<=l[peak]: peak-=1 print(peak)
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
#import collections #from collections import defaultdict for _ in range(int(input())): n=int(input()) a=[int(x) for x in input().split()] i=n-1 while i>0: if a[i]>a[i-1]: break i-=1 if i==0: print(0) else: while i>0: ...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) k=len(l)-1 done=False while k>0 and l[k]<=l[k-1]: k-=1 while k>0 and l[k]>=l[k-1]: k-=1 print(k)
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
for i in range(int(input())): k = int(input()) lis = list(map(int,input().split())) r = 0 trend = 'ge' eq = 0 while(True): if(len(lis)==2 or len(lis)==1): print(k-len(lis)) break if(r!=len(lis)-1): if(trend == 'ge' and lis[r]<=lis[r+1]): if(lis[r]==lis[r+1]): eq+=...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
t=int(input()) for q in range(t): n=int(input()) l=list(map(int,input().split())) i=n-1 while l[i]<=l[i-1] and i>0: i-=1 while l[i]>=l[i-1] and i>0: i-=1 print(i)
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
t=int(input()) for p in range(t): n=int(input()) l=list(map(int,input().split())) c=1 i=n-1 while(i>0): if l[i]<=l[i-1]: c+=1 i-=1 else: break while(i>0): if l[i]>=l[i-1]: c+=1 i-=1 else: brea...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
for i in range(int(input())): n=int(input()) b=list(map(int,input().split())) l=0 r=n-1 c=[0] d=0 while l<=r: if b[l]<=b[r]: if b[l]>=c[len(c)-1]: c.append(b[l]) l=l+1 else: c=[0] d=l ...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
from sys import stdin, stdout import math,sys from itertools import permutations, combinations from collections import defaultdict,deque,OrderedDict from os import path import bisect as bi import heapq def yes():print('YES') def no():print('NO') if (path.exists('input.txt')): #------------------Sublime-----------...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual soluti...
JAVA
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
#include <bits/stdc++.h> using namespace std; long long int modularExponentiation(long long int n, long long int p, long long int M) { long long int res = 1; while (p) { if (p & 1) res = (res * n) % M; n = (n * n) % M; p >>= 1; } return res; } void solve() { int...
CPP
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
for t in range(int(input())): n = int(input()) a = list(map(int, input().split())) ans = [0] prefix = n-1 while prefix > 0 and a[prefix-1] >= a[prefix]: prefix -= 1 while prefix > 0 and a[prefix-1] <= a[prefix]: prefix -= 1 print(prefix)
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
def check(a, l, r): x = 0 while l < r: if a[l] < a[r]: y = a[l] l += 1 else: y = a[r] r -= 1 if y < x: return False x = y return True t = int(input()) for _ in range(t): n = int(input()) a = [int(x) for x i...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
import java.util.ArrayList; import java.util.Scanner; public class cc113 { public static void main(String[] args) { Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t>0) { int n=s.nextInt(); int[] a=new int[n]; ArrayList<Integer> um=new ArrayList<>(); for(int i=0;i<n;i++) { a[i]=s.nextInt(); ...
JAVA
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
import java.util.*; import java.io.*; public class Rextester { static final FS sc = new FS(); static final PrintWriter pw = new PrintWriter(System.out); static final Util u = new Util(); public static void main(String[] args) { int testCases = sc.nextInt(); while(t...
JAVA
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
numTestCases = int(input()) caseLengths = [] cases = [] for i in range(numTestCases): caseLengths.append(int(input())) cases.append(list(map(int, input().split()))) # bug: 1 1 1 doesn't work -- if the for loop doesn't produce anything, we need to print the length of case in calculate ans def calculateAns...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
#include <bits/stdc++.h> using namespace std; long long v[200005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long tc; cin >> tc; while (tc--) { long long n; cin >> n; for (long long int i = 0; i < n; i++) { cin >> v[i]; } long long i = n - 1, prev...
CPP
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
t=int(input()) while t>0: t-=1 n=int(input()) a=list(map(int,input().split())) i=n-1 while i-1>=0 and a[i]<=a[i-1]: i-=1 while i-1>=0 and a[i-1]<=a[i]: i-=1 print(i)
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
#_________________ Mukul Mohan Varshney _______________# #Template import sys import os import math import copy from math import gcd from bisect import bisect from io import BytesIO, IOBase from math import sqrt,floor,factorial,gcd,log,ceil from collections import deque,Counter,defaultdict from itertools import permut...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
def solve(): n = int(input()) a = list(map(int, input().split())) id = n - 1 while id > 0 and a[id - 1] >= a[id]: id -= 1 while id > 0 and a[id - 1] <= a[id]: id -= 1 print(id) ct = int(input()) while ct > 0: solve() ct -= 1
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
def makeitgood(arr): is_dec = False for i in range(len(arr) - 1, 0, -1): if arr[i] > arr[i-1]: is_dec = True if is_dec and arr[i] < arr[i-1]: return i return 0 t = int(input()) for _ in range(t): n = int(input()) arr = list(map(int, input().split())) pr...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
import math import time from collections import defaultdict,deque from sys import stdin,stdout from bisect import bisect_left,bisect_right t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,stdin.readline().split())) if(n<3): print(0) else: if(a[-1]>a[-2]): assen...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
for i in range(int(input())): n=int(input()) arr=list(map(int,input().split())) ans=0 j=n-2 while j>=0 and arr[j]>=arr[j+1]: j-=1 while j>=0 and arr[j]<=arr[j+1]: j-=1 print(j+1)
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
# -*- coding: utf-8 -*- """ Created on Sun May 31 22:45:01 2020 @author: taolinlin """ t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) b = list(range(n - 1)) for j in range(n-1): b[j] = a[j + 1] - a[j] c = 0 d = 0 ans = 0 for k in range(n...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) pos = n-1 while (pos > 0 and a[pos - 1] >= a[pos]): pos -= 1 while (pos > 0 and a[pos - 1] <= a[pos]): pos -= 1 print(pos)
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long T = 1; cin >> T; while (T--) { long long n; cin >> n; vector<long long> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } long long i = n - 1; wh...
CPP
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
from math import * t=int(input()) while t>0: n=int(input()) a=[int(x) for x in input().split()] decr=0 a.reverse() val=-1 for i in range(1,n): if a[i]<a[i-1]: decr=1 if decr==1 and a[i]>a[i-1]: val=i break if val==-1: print(0) else: print(n-i) t-=1
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split()))[::-1] cur = 0 i = 0 while i < n and a[i] >= cur: cur = a[i] i += 1 if i == n: print(0) continue cur = a[i] while i < n and a[i] <= cur: cur = a[i] ...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
for _ in range(int(input())): N = int(input()) a = list(map(int, input().split())) if len(set(a)) == 1 or a == sorted(a): print(0) continue a.reverse() a = [0] + a if a == sorted(a): print(0) else: Dec = False ans = 0 for i in range(1, N+1): ...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
for _ in range(int(input())): n = int(input()) a = [*map(int, input().split())] i = n - 1 while i > 0: if a[i] > a[i - 1]: break i -= 1 while i > 0: if a[i] < a[i - 1]: break i -= 1 print(i)
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
t=int(input("")) while t>0: n=int(input("")) l=list(map(int,input().split())) x=n-1 flag=0 condition='less' ans=0 while x>0: if flag==0: if(l[x]>l[x-1]): flag=1 elif(l[x]<l[x-1]): flag=2 elif(flag==1): if(l[x...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
import sys from functools import lru_cache, cmp_to_key from heapq import merge, heapify, heappop, heappush # from math import * from collections import defaultdict as dd, deque, Counter as C from itertools import combinations as comb, permutations as perm from bisect import bisect_left as bl, bisect_right as br, bisect...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
def main(): t = int(input()) for i in range(t): n = int(input()) a = list(map(int, input().split())) padanje = False promjena = 0 for j in range(n): if not padanje: if j+2 <= n: if a[-(j+2)] >= a[-(j+1)]: ...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
if __name__ == '__main__': rd = lambda: map(int, input().split()) t, = rd() for _ in range(t): n, = rd() a = list(rd()) right = [0] * len(a) right[-1] = a[-1] for i in range(len(a) - 2, -1, -1): right[i] = max(right[i + 1], a[i]) left = a[0] ...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
for t in range(int(input())): n = int(input()) a = list(map(int,input().split())) pos = n-1 while pos>0 and a[pos]<=a[pos-1]:pos-=1 while pos>0 and a[pos]>=a[pos-1]:pos-=1 print(pos)
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
# region smaller_fastio from sys import stdin, stdout from os import path if path.exists('input.txt'): # ------------------Sublime--------------------------------------# stdin = open('input.txt', 'r') stdout = open('output.txt', 'w') def I(): return int(input()) def In(): return...
PYTHON3
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.stream.IntStream; //Java Program to rearrange numbers in an Array //such that no two numbers are adjacent import java.util.Comparator; import java.util.PriorityQueue; import java.util.ArrayList; import java.u...
JAVA
1385_C. Make It Good
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.InputMismatchException; import java.util.*; import java.io.*; import java.lang.*; public class Main{ public static class InputReader { private InputStream stream; ...
JAVA