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
import java.util.LinkedHashSet; import java.util.Scanner; public class first { public static void main(String args[]) { Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t--!=0) { int n=s.nextInt(); int arr[]=new int[n]; for(int i=0;i<n;i++) arr[i]=s.nextInt(); int loc=0; for(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
import math def gcd(a,b): if (b == 0): return a return gcd(b, a%b) def lcm(a,b): return (a*b) / gcd(a,b) def bs(arr, l, r, x): while l <= r: mid = l + (r - l)//2; if(arr[mid]==x): return arr[mid] elif(arr[mid]<x): l = mid + 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 cases in range(int(input())): n = int(input()) arr = list(map(int, input().split())) i = n - 1 while i > 0 and arr[i-1] >= arr[i]: i -= 1 while i > 0 and arr[i-1] <= arr[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
#include <bits/stdc++.h> using namespace std; void start() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } template <class T> istream& operator>>(istream& in, vector<T>& a) { for (auto& i : a) in >> i; return in; } template <class T> ostream& operator<<(ostream& out, vector<T>& a) { for (auto& 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
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.*; public class Main { public static void main(String args[] ) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int test = Integer.parseInt(br.readLine()); ...
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()) l = list(map(int, input().split())) if n<3 or sorted(l)==l: print(0) continue indx = ans = 0 for i in range(n-2, -1, -1): if l[i+1] > l[i]: indx = i break for i in range(indx-1, -1, -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())) out = n - 1 while out > 0: if a[out] <= a[out-1]: out -= 1 else: break while out > 0: if a[out] >= a[out-1]: out -= 1 else: 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
t = int(input()) for i in range(t): l = int(input()) p = list(map(int, input().split())) p.reverse() j = 0 # 4 3 3 8 4 5 2 # 2 5 4 8 3 3 4 if l > 1: while j < l - 1 and p[j] <= p[j + 1]: j += 1 while j < l - 1 and p[j] >= p[j + 1]: j += 1 j += 1 print(l - j) else: print(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
try: for i in range(int(input())): size=int(input()) arr=list(map(int,input().split())) j=len(arr)-1 while j-1>=0 and arr[j-1]>=arr[j]: j-=1 while j-1>=0 and arr[j-1]<=arr[j]: j-=1 print(j) 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
for _ in range(int(input())): n = int(input()) arr= [int(x) for x in input().split()] pos = n-1 while (pos > 0 and arr[pos - 1] >= arr[pos]): pos -= 1 while (pos > 0 and arr[pos - 1] <= arr[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
from math import * from collections import * from bisect import * import sys input=sys.stdin.readline t=int(input()) while(t): t-=1 n=int(input()) a=list(map(int,input().split())) b=sorted(a) if(b==a or a[-1::-1]==b): print(0) continue a=a[-1::-1] i=0 r=1 pre=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 i in range(int(input())): n=int(input()) l=list(map(int,input().split())) flag=0 index=0 for j in range(n-1,0,-1): if flag==0: if l[j]>l[j-1]: flag=1 else: if l[j]<l[j-1]: index=j break print(index)
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
nCases = int(input()) for _ in range(nCases): aLen = int(input()) a = [int(x) for x in input().split()] i = aLen - 1 mem = 0 while i >= 0: if a[i] < mem: break mem = a[i] i -= 1 while i >= 0: if a[i] > mem: break mem = 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 i in range(int(input())): n = int(input()) numbers = list(map(int,input().split())) res = n - 1 while res > 0 and numbers[res] <= numbers[res-1]: res -= 1 while res > 0 and numbers[res] >= numbers[res-1]: res -= 1 print(res)
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(input()): n=input() a=[int(i) for i in raw_input().split()] ct=1 flag=0 val=a[n-1] for i in range(n-2,-1,-1): if a[i]>=val and flag==0: ct+=1 val=a[i] elif a[i]<=val: ct+=1 val=a[i] flag=1 else: ...
PYTHON
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
public class Main { public static void main(String[] args) { java.util.Scanner sc = new java.util.Scanner(System.in); int t = sc.nextInt(), n, a[]; while (t--!=0) { n = sc.nextInt(); a = new int[n]; for (int i = 0; i < n; i++) a[i] = sc.nex...
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()) while t!=0: n = int(input()) list1 = list(map(int,input().split())) i = len(list1)-1 while i>=1 and list1[i-1]>=list1[i]: i-=1 while i>=0 and list1[i]>=list1[i-1]: i-=1 if i<0: print(0) else: print(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
from sys import stdin input=stdin.readline for _ in range(int(input())): n=int(input()) lis=list(map(int,input().split())) i=0 j=n-1 g=[] while i<=j: if lis[i]<lis[j]: if len(g)!=0: if g[-1]<=lis[i]: g.append(lis[i]) 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
k=int(input()) for i in range(k): n=int(input()) l=list(map(int,input().split(" "))) pos=n-1 while pos!=0: if l[pos-1]<l[pos]: break pos-=1 while pos!=0: if l[pos-1]>l[pos]: break 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 sys sys.setrecursionlimit(2147483647) input=sys.stdin.readline def calc(arr): flag = 0 length = len(arr) for i in range(length-1): if not flag: if(arr[length - i - 2] < arr[length - i - 1]): flag = 1 else: if(arr[length - i - 2] > arr[length - i - 1]): return length - 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 _ in range(t): n=int(input()) arr=list(map(int,input().strip().split())) a=0 temp=0 for i in range(n-1,0,-1): if((arr[i]<=arr[i-1]) and a==0): continue elif((arr[i]>=arr[i-1]) and a==1): continue elif(arr[i]>arr[i-1] and 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
from sys import * t = int(stdin.readline()) while t > 0: n = int(stdin.readline()) arr = list(map(int,stdin.readline().split())) if arr == sorted(arr): ans = 0 elif arr == sorted(arr, reverse=True): ans = 0 else: count = 0 for i in range(n-1,0,-1): if 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
import java.util.Scanner; /* Name of the class has to be "Main" only if the class is public. */ public class Main { public static void main (String[] args) throws java.lang.Exception { try { Scanner sc = new Scanner(System.in); int t,n,i,k; t=sc.nextInt(); while(t>0) { 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
from sys import stdin input = stdin.readline T = int(input()) def isGood(A, start, end): flag = True for i in range(start, end - 1): if flag: if A[i] > A[i+1]: flag = False else: if A[i] < A[i+1]: return False return True for _ in ran...
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())): x = int(input()) *li, = map(int, input().split()) a = 0 cnt =0 inc = True for i in li[::-1]: if i>=a and inc: cnt +=1 elif i<=a: inc = False cnt +=1 else: break a =i print(x - cnt)
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 __future__ import print_function mod=int(1e9+7) #import resource #resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY]) #import threading #threading.stack_size(2**25) #import sys #sys.setrecursionlimit(10**5) #fact=[1] #for i in range(1,100001): # fact.append((fact[-1]*i)%mod) #ifact...
PYTHON
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()) l=list(map(int,input().split())) if n<=2: print(0) else: diffs=[] for i in range(1,n): if l[i]>l[i-1]: diffs.append(1) elif l[i]==l[i-1]: diffs.append(0) 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
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int,input().split())) if n<=2: print (0) continue last = a[-1] i = n-2 while i>=0: if a[i]>=last: last = a[i] i-=1 else: break 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 i in range(int(input())): p=int(input()) l=list(map(int,input().split())) i=p-1 while i > 0 and l[i-1] >=l[i]: i-=1 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
/** * Date: 17 Jul, 2020 * Link: https://codeforces.com/contest/1385/problem/C * * @author: Prasad Chaudhari * @linkedIn: https://www.linkedin.com/in/prasad-chaudhari-841655a6/ * @git: https://github.com/Prasad-Chaudhari */ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; impo...
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,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
for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) l2=[] if(len(l)==1 or len(l)==2): print(0) else: temp=-1 for i in range(n-1,-1,-1): if(l[i-1]<l[i]): temp=i break ans=0 for i in range(tem...
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, setrecursionlimit, stdout #setrecursionlimit(1000000) #use "python" instead of "pypy" to avoid MLE from collections import deque from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin from heapq import heapify, heappop, heappush, heapreplace, heappushpop def ii(): return in...
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()) for s in range(i): q = int(input()) po = list(map(int, input().split())) res = 0 rrr = 1 curIndex = q - 1 for l in range(0, q-1): if po[curIndex - l - 1] < po[-(l + 1)]: rrr = 0 elif po[curIndex - l - 1] > po[-(l + 1)]: if rrr == 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
# Make It Good t = int(input()) for _ in range(t): k = int(input()) l = list(map(int,input().split())) i = k-1 while (i>0 and l[i-1] >= l[i]): i-=1 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
""" Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools """ q = int(input()) for _ in range(q): n = int(input()) arr = list(map(int, input().split(" "))) if len(arr) <= 2: print(0) continue if arr[-1] > arr[-2]: decreasing = 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
# @oj: codeforces # @id: hitwanyang # @email: 296866643@qq.com # @date: 2020-07-19 19:31 # @url:https://codeforc.es/contest/1385/problem/C import sys,os from io import BytesIO, IOBase import collections,itertools,bisect,heapq,math,string from decimal import * # region fastio BUFSIZE = 8192 BUFSIZE = 8192 class Fast...
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()) nums = list(map(int, input().split())) if n == 1: print (0) else: ct = 0; last = 0 if (len(nums) >= 2) and (nums[-1] <= nums[-2]): for i in range(n-1, -1, -1): c = nums[i] if c >= last: ...
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())): d = int(input()) arr = list(map(int,input().split())) i = d -2 while i>-1 and arr[i]>=arr[i+1]: i = i -1 while i>-1 and arr[i]<=arr[i+1]: i = i -1 print(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 java.util.*; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0){ int n = sc.nextInt(); int[] a = new int[n]; for(int i=0;i<n;i++) a[i] = 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
for _ in range(int(input())): n=int(input()) x=list(map(int, input().split())) a=[]; b=[] for i in range(n-1): if x[i]>x[i+1]: a.append(0) elif x[i]<x[i+1]: a.append(1) else: a.append(-1) if a.count(0)==0: print(0) elif a[-1]==0 or a[-1]==-1: c=False while True: if a==[] or (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
for _ in range(int(input())): n = range(int(input())) a = [int(_) for _ in input().split()] i = len(a) - 2 while i >= 0 and a[i] >= a[i+1]: i -= 1 while i >= 0 and a[i] <= a[i+1]: i -= 1 print(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
#!/usr/bin/env python import os import sys from io import BytesIO, IOBase def main(): for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) i = n - 1 while i > 0 and a[i-1] >= a[i]: i -= 1 while i > 0 and a[i-1] <= 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())) pos=n-1 while pos and a[pos-1]>=a[pos]: pos-=1 while pos 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
for _ in range(int(input())): n=int(input()) a=[int(x) for x in input().split()] flag,cflag=0,False for i in range(n-1,0,-1): if flag==1: if a[i]<a[i-1]: print(i); cflag=True; break elif flag==-1: if a[i]>a[i-1]: flag=1 else: if a[i]>a[i-1]: fl...
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())) s=1 i=n-1 c=0 while i>=1: if l[i]<=l[i-1] and c==0: s+=1 elif l[i]>=l[i-1]: c=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(0,int(input())): n = int(input()) listt = list(map(int,input().split())) i = n-1 while i > 0 and listt[i] <= listt[i-1]: i-=1 while i > 0 and listt[i] >= listt[i-1]: 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
for _ in range(int(input())): n=int(input()) ar=list(map(int,input().split())) fl=0 flg=0 for i in range(n-2,-1,-1): #print("i=",i,ar[i]) if fl==0: #print("cmp",ar[i],ar[i+1]) if ar[i]<ar[i+1]: fl=1 #print(i,"fl") 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
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Thu Jun 18 20:19:55 2020 @author: gurkirpal """ t=int(input()) for _ in range(t): n=int(input()) l=[int(x) for x in input().split()] sam=0 samu=0 for i in range(n-1,0,-1): if(l[i-1]<l[i]): sam=i 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
t=int(input()) for tt in range(t): n=int(input()) a=[int(x) for x in input().split(' ')] a.reverse() inc=1 b=[a[0]] for i in range(1,n): if(inc): if(a[i-1]<=a[i]): b.append(a[i]) else: b.append(a[i]) inc=0 el...
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> const long long pinf = ((long long)2e18); const long long ninf = ((long long)-2e18); const long long mod = 1000000007; using namespace std; long long power(long long x, long long n, long long M) { if (n == 0) return 1; else if (n % 2 == 0) return power((x * x) % M, n / 2, M); else...
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
#!/usr/bin/env pypy3 from sys import stdin, stdout def input(): return stdin.readline().strip() T = int(input()) def ans(A): A += [float("-inf")] i = len(A)-1 while i > 0 and A[i-1] >= A[i]: i -= 1 while i > 0 and A[i-1] <= A[i]: i -= 1 return i for _ in range(T): in...
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
"""Template for Python Competitive Programmers prepared by pa.n.ik, kabeer seth and Mayank Chaudhary """ # to use the print and division function of Python3 from __future__ import division, print_function """value of mod""" MOD = 998244353 mod = 10**9 + 7 """use resource""" # import resource # resource.setrlimit(res...
PYTHON
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=input() a=[int(x) for x in input().split()] count=len(a)-1 if count==0: print(0) continue flag=1 pos=0 temp=a[count] count-=1 while flag: if pos==0 and a[count]<temp: pos=1 if pos==1 and a[count]>temp: ...
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 = [int(i) for i in input().split()] i = n-1 while i-1 >= 0 and a[i-1] >= a[i]: 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
def create_max(arr): mx = [arr[0]] for i in arr[1:]: mx.append(max(mx[-1], i)) return mx n = int(input()) for i in range(n): x = int(input()) arr = [int(i) for i in input().split()] if len(arr)<3: print(0) else: ans = 0 mx1 = [[10**9, -1]] mx2 = cre...
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() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; vector<int> vc; for (int i = 1; i < n; i++) { vc.push_back(a[i] - a[i - 1]); } int ans = 0; int i = vc.size() - 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
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) if(len(a) <= 2): print(0) continue edm = a[-1] cnm = a[-2] lci = 0 lcd = 0 mud = 1 #lci for i in range(n-1,0,-1): if(a[i]<=a[i-1]): lci+=1 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
import java.util.Scanner; public class MakeItGood { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); while(t-- > 0) { int n = scanner.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; 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
for _ in range(int(input())): n = int(input()) a = [int(x) for x in input().split()] ans, tmp = [0], max(a) for i in range(2,n): if a[i-2] > a[i-1] and a[i-1]<=a[i]: if i<n-1: rev = sorted(a[i-1:], reverse=True) fow = sorted(a[i-2:]) ans.append(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
from sys import stdin,stdout # import math # import heapq # # t = 1 # def aint(): ...
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, setrecursionlimit from collections import deque, defaultdict, Counter from heapq import heappush, heappop import math rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() rli = lambda: map(int, stdin.readline().split()) rlf = lambda: map(float, stdin.readline().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
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.lang.reflect.Array; import java.math.BigInteger; import java.util.*; p...
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 collections import defaultdict as dd import sys input=sys.stdin.readline t=int(input()) while t: n=int(input()) #x,y,z=map(int,input().split()) l=list(map(int,input().split())) pre=[-1] mx=l[0] for i in range(1,n): if(l[i]>=mx): pre.append(-1) mx=l[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 _ in range(T): N = int(input()) A = list(map(int, input().split())) pre,cnt = -1,0 for i in range(N-1,0,-1): if A[i]<=A[i-1]: cnt+=1 else: if i==1 and A[1]<=A[0]: cnt = N break le = N-cnt for i in range(le...
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 from sys import maxsize input = stdin.readline # def print(n): # stdout.write(str(n)+'\n') def solve(): pass test = 1 test = int(input().strip()) for t in range(0, test): n = int(input().strip()) # s = list(input().strip()) ...
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() { int t; ; cin >> t; while (t--) { int n; cin >> n; vector<int> arr(n); for (int i = 0; i < n; i++) { cin >> arr[i]; } int j = n - 1; while (j - 1 >= 0 && arr[j] <= arr[j - 1]) j--; while (j - 1 >= 0 && arr[j] >= arr[...
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
def solve(): n = int(input()) b = list(map(int, input().split())) key = True for i in range(n - 2, -1, -1): if key and b[i] < b[i + 1]: key = False elif not key and b[i] > b[i + 1]: print(i + 1) return print(0) for _ in range(int(input())): s...
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())) l = 0 temp = 0 for i in range(n-1,0,-1) : if temp == 0 : if a[i] > a[i-1] : temp += 1 else : if a[i] < a[i-1] : break l += 1 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
t=int(input()) for i in range(t): n=int(input()) a=[int(x) for x in input().split()] prev=n-1 curr=n-2 count1=0 while (curr>=0): if a[curr]>=a[prev]: count1=count1+1 curr=curr-1 prev=prev-1 else: break count2=0 while (curr>=...
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(lst,n): i = 0 while i < n-1 and lst[i] <= lst[i+1]: i += 1 if i == n-1: return 0 i = 0 while i < n-1 and lst[i] >= lst[i+1]: i += 1 if i == n-1: return 0 j = n-1 while j > 0 and lst[j] <= lst[j-1]: j -= 1 while j > 0 and lst[j] >= lst[j-1]: j -= 1 return j for _ in range(int(input(...
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 checker(arr, mid, n): temp = [-1] l, r = mid, n-1 while l < r: if arr[l] <= arr[r]: if arr[l] >= temp[-1]: temp.append(arr[l]) l += 1 else: return False else: if arr[r] >= temp[-1]: temp.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
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; const long double PI = 3.14159265358979; long long binpow(long long x, long long y, long long p) { long long res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; ...
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.io.BufferedReader; import java.io.BufferedWriter; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.StringTokenizer; public class Main { private BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); private BufferedWriter out = new BufferedWriter(ne...
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()) a=list(map(int,input().split())) c=-1 t=0 i=n-1 while(i>0 and a[i]<=a[i-1] ): i=i-1 while(i>0 and a[i]>=a[i-1] ): 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
t=int(input()) while t: t=t-1 n=int(input()) #x,y,z=map(int,input().split()) a=list(map(int,input().split())) if n<=2: print(0) else: j=n-1 while j>0 and a[j-1]>=a[j]: j-=1 while(j>0 and a[j-1]<=a[j]): j-=1 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
import sys import collections def input(): return sys.stdin.readline().rstrip() def split_input(): return [int(i) for i in input().split()] # tests = 1 tests = int(input()) for _ in range(tests): n = int(input()) a = split_input() ind = n - 2 while ind >= 0 and a[ind] <= a[ind + 1]: ind -= 1 ans1 = 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
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse4") using namespace std; const int MOD = 1000000007; const long long INF = 1e18; const int MX = 100001; const double epsilon = 1e-12; const vector<vector<int> > ds = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; int main() { ios_base::sync_with_stdio(0)...
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 range(int(input())): n = int(input()) a = [int(i) for i in input().split()] pos = len(a) - 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
for t in range(int(input())): n = int(input()) arr=list(map(int,input().split())); i= n-1 while arr[i]<=arr[i-1] and i>0 : i-=1 while arr[i]>=arr[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
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const long long M = (long long)1e9 + 7; const double pi = 2 * acos(0.0); const double esp = 1e-9; int Set(int N, int pos) { return N = N | (1 << pos); } int reset(int N, int pos) { return N = N & ~(1 << pos); } bool check(int N, int pos) { return (boo...
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.lang.*; import java.io.*; import java.math.*; public class Prac{ static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; public InputReader(InputStream st) { ...
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=list(map(int,input().split()))[::-1] if n==1: print(0) else: i=1 while i<n and arr[i-1]<=arr[i]: i+=1 if i<n: while i<n and arr[i-1]>=arr[i]: i+=1 print(n-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()) arr=[int(x) for x in input().split()] ans=0 cur=n-1 while(cur!=0 and arr[cur]<=arr[cur-1]): cur-=1 while(cur!=0 and arr[cur]>=arr[cur-1]): cur-=1 print(cur)
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.io.PrintWriter; import java.util.*; public class code { public static void main(String[] args)throws IOException { FastReader sc = new FastReader(); PrintWriter pw = new PrintWriter(System.out); int t = sc.ne...
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.InputStreamReader; import java.util.ArrayList; public class Task3 { private static ArrayList<Integer> integers = new ArrayList<>(); public static void main(String[] args) throws IOException { read(); } private static voi...
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 solve(vector<int>& a, int n) { if (is_sorted(a.begin(), a.end()) || is_sorted(a.rbegin(), a.rend())) return 0; int i = n - 1; while (a[i] <= a[i - 1]) i--; while (a[i] >= a[i - 1]) i--; return max(i, 0); } int main() { int t; cin >> t; while (t--) { ...
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 import math import itertools import functools import collections import operator import fileinput import copy ORDA = 97 # a def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return [int(i) for i in input().split()] def lcm(a, b): return abs(a * b) // math.gcd(a, b) def revn...
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
#Problem 3 for _ in range(int(input())): n=int(input()) li=list(map(int,input().split())) if len(li)==1: print(0) else: index1=-1 index2=-1 for i in range(len(li)-1,0,-1): if li[i-1]<li[i]: index1=i break i-=1 wh...
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(): for t in range(int(input())): n = int(input()) a = [int(i) for i in input().split()] i = n - 2 while i >= 0 and a[i] >= a[i + 1]: i -= 1 peak = i + 1 i = peak - 1 while i >= 0 and a[i] <= a[i + 1]: i -= 1 deep = 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())) i = n-1 c = 0 while i>0: if a[i]<=a[i-1]: c+=1 i-=1 else: break if i==0: print(0) continue else: while i>0: if a[i]>=a[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 io import os input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def solve(): n=int(input()) a=list(map(int,input().split())) temp =0 i =0 j=n-1 l=0 while i<j: if a[i] < a[j]: if a[i] < temp: temp=0 j=n-1 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
t=int(input()) def is_good(lista,n): i=n-1 good=0 while (i>0 and lista[i-1]==lista[i]): i-=1 if lista[i-1]>lista[i]: while (i>0 and lista[i-1]>=lista[i]): i-=1 if (i>0 and lista[i-1]<lista[i]): while (i>0 and lista[i-1]<=lista[i]): i-=1 if lista[i-1]<lista[i]: while (i>0 and lista[i-1]<=lista[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 t 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=pos-1 while pos>0 and a[pos-1]<=a[pos]: 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.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); int T = Integer.parseInt(input.readLine()); for(int t = 0; t < T; t++) { int n = 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
import java.io.*; import java.util.*; public class TEST { static class Reader { final private int BUFFER_SIZE = 1 << 16; Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in))); private DataInputStream din; private byte[] buffer; private int buffe...
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
#https://codeforces.com/problemset/problem/1385/C # 4 3 3 8 4 5 2 #2, 4, 5, 8 #2, 3, 3, 5, 8 # 1 2 3 4 10 4 5 def test_case(): n = int(input()) a = [int(x) for x in input().strip().split(" ")] pos = n - 1 while(pos > 0 and a[pos-1] >= a[pos]): pos -= 1 while(pos > 0 and a[pos -1] <= a [pos]): po...
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 # from math import ceil for i in range(int(input())): n = int(input()) # n, m = list(map(int, input().split())) arr = list(map(int, input().strip().split())) + [-1] # bob = list(map(int, input().strip().split())) # string = list(input()) n += 1 arrow = [] ...
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> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") using namespace std; long long mod = 1e9 + 7; long long power(long long x, long long n, long long mod) { long long res = 1; x %= mod; while (n) { if (n & 1) res = (res * x) % mod;...
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 A[i-1]>=A[i] and i>0: i-=1 while A[i-1]<=A[i] and i>0: i-=1 print(i)
PYTHON3