exec_outcome
stringclasses 1
value | code_uid
stringlengths 32
32
| file_name
stringclasses 111
values | prob_desc_created_at
stringlengths 10
10
| prob_desc_description
stringlengths 63
3.8k
| prob_desc_memory_limit
stringclasses 18
values | source_code
stringlengths 117
65.5k
| lang_cluster
stringclasses 1
value | prob_desc_sample_inputs
stringlengths 2
802
| prob_desc_time_limit
stringclasses 27
values | prob_desc_sample_outputs
stringlengths 2
796
| prob_desc_notes
stringlengths 4
3k
⌀ | lang
stringclasses 5
values | prob_desc_input_from
stringclasses 3
values | tags
listlengths 0
11
| src_uid
stringlengths 32
32
| prob_desc_input_spec
stringlengths 28
2.37k
⌀ | difficulty
int64 -1
3.5k
⌀ | prob_desc_output_spec
stringlengths 17
1.47k
⌀ | prob_desc_output_to
stringclasses 3
values | hidden_unit_tests
stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PASSED
|
192b8a4f1b9c88ad2f469e8e531a3e09
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
public class A{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while (t-- > 0){
int n=sc.nextInt();
long arr[]=new long[n];
long sum=0;
for(int i=0;i<n;i++){
arr[i]=sc.nextInt();
}
String ans="YES";
for(int i=1;i<=n;i++){
sum+=arr[i-1];
int req=(i*(i-1))/2;
if (sum < req) {
ans="NO";
break;
}
}
System.out.println(ans);
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
2eb1d7a808ff8baca7dbef1b127037e1
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
//package div2_702;
import java.util.Scanner;
public class ShiftingStacks {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int t=in.nextInt();
while(t>0) {
t--;
int n=in.nextInt();
long h[]=new long[n];
boolean isPossible=true;
for(int i=0;i<n;i++) {
h[i]=in.nextLong();
}
for(int i=0;i<n-1;i++) {
if(h[i]>=i) {
h[i+1]+=h[i]-i;
}
else {
isPossible=false;
break;
}
}
if(h[n-1]<n-1) {
isPossible=false;
}
if(isPossible) {
System.out.println("yes");
}
else {
System.out.println("no");
}
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
bf22a9e6a1a25aba27d15dcaec07139c
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class FastInput {
public static void main(String[] args) {
FastReader in = new FastReader();
int t= in.nextInt();
while(t-->0) {
int n = in.nextInt();
long arr[] = new long[n];
int need =0;
long sum = 0;
String ans = "YES";
for(int i =0;i<n;++i) {
arr[i] = in.nextLong();
}
for(int i=0;i<n;i++){
need+=i;
sum+=arr[i];
if(need>sum){
ans = "NO";
break;
}
}
System.out.println(ans);
}
}
static class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br = new BufferedReader (new InputStreamReader(System.in));
}
String next(){
while(st==null|| !st.hasMoreElements()){
try{
st = new StringTokenizer(br.readLine());
} catch(IOException e){
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
String nextLine(){
String str ="";
try{
str = br.readLine();
}
catch(IOException e ){
e.printStackTrace();
}
return str;
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
05407795cc7bdcc12b8cc03d33bfca75
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import javax.swing.event.ListDataEvent;
import javax.swing.plaf.FontUIResource;
import java.lang.reflect.Array;
import java.util.*;
import java.lang.*;
import java.io.*;
public class Codechef {
public static void main(String[] args) throws java.lang.Exception {
out = new PrintWriter(new BufferedOutputStream(System.out));
sc = new FastReader();
int test = sc.nextInt();
for (int t = 0; t < test; t++) {
int n = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
boolean ok = true;
long sum = 0, needed = 0;
for (int i = 0; i < n; i++) {
needed += i;
sum += arr[i];
if (sum < needed) {
ok = false;
break;
}
}
if (!ok) {
out.println("NO");
}else {
out.println("YES");
}
}
out.close();
}
public static FastReader sc;
public static PrintWriter out;
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
853f0a5d485a804fae6078e7a848cc14
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import javax.swing.event.ListDataEvent;
import javax.swing.plaf.FontUIResource;
import java.lang.reflect.Array;
import java.util.*;
import java.lang.*;
import java.io.*;
public class Codechef {
public static void main(String[] args) throws java.lang.Exception {
out = new PrintWriter(new BufferedOutputStream(System.out));
sc = new FastReader();
int test = sc.nextInt();
for (int t = 0; t < test; t++) {
int n = sc.nextInt();
long[] arr = new long[n];
long sum = 0;
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
sum += arr[i];
}
if (sum < n * (n - 1) / 2) {
out.println("NO");
continue;
}
if (n <= 1) {
out.println("YES");
continue;
}
boolean ok = true;
arr[1] += arr[0];
arr[0] = 0;
for (int i = 2; i < n; i++) {
if (arr[i - 1] < i - 1) {
ok = false;
break;
}
arr[i] += arr[i - 1] - i + 1;
arr[i - 1] = i - 1;
}
for (int i = 1; i < n; i++) {
if (arr[i] <= arr[i - 1]) {
ok = false;
}
}
if (!ok) {
out.println("NO");
continue;
}
out.println("YES");
}
out.close();
}
public static FastReader sc;
public static PrintWriter out;
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
2eaa2a424a660ee9b733da7e7aefbe4c
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class A {
private static PrintWriter out;
private static class FS {
StringTokenizer st;
BufferedReader br;
public FS() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public String next() {
while (st == null || !st.hasMoreElements()) {
try {st = new StringTokenizer(br.readLine());}
catch (IOException e) {e.printStackTrace();}
}
return st.nextToken();
}
public String nextLine() {
String s = null;
try {s = br.readLine();}
catch (IOException e) {e.printStackTrace();}
return s;
}
public int nextInt() {return Integer.parseInt(next());}
public long nextLong() {return Long.parseLong(next());}
public double nextDouble() {return Double.parseDouble(next());}
}
public static void main(String[] args) {
FS sc = new FS();
out = new PrintWriter(new BufferedOutputStream(System.out));
int t = sc.nextInt();
while (t-- > 0) {
long n = sc.nextInt();
long s = 0;
boolean f = true;
for (int i = 0; i < n; ++i) if ((s += sc.nextInt() - i) < 0) f = false;
if (f) out.println("yes");
else out.println("no");
}
out.close();
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
fe106ca5d3b6bb9535d413f2610b7ff9
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
import java.io.*;
/**
* Created on: Feb 18, 2021
* Questions: https://codeforces.com/contest/1486/problem/A
*/
public class ShiftingStacks {
public static void main(String[] args) {
Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
int test = sc.nextInt();
while (test-- > 0) {
int n = sc.nextInt();
long carry = 0;
boolean possible = true;
for (int j = 0; j < n; j++) {
long cur = sc.nextInt();
carry += cur - j;
if (carry < 0) {
possible = false;
}
}
System.out.println(possible ? "YES" : "NO");
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
32c4628b46297f48fc0271105021c810
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.io.*;
import java.util.*;
import java.lang.*;
public class Main {
public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
static long MOD = (long) (1e9 + 7);
//static int MOD = 998244353;
static long MOD2 = MOD * MOD;
static FastReader sc = new FastReader();
static int pInf = Integer.MAX_VALUE;
static int nInf = Integer.MIN_VALUE;
static long ded = (long)(1e17)+9;
public static void main(String[] args) throws Exception {
int test = 1;
test = sc.nextInt();
for (int i = 1; i <= test; i++){
//out.print("Case #"+i+": ");
solve();
}
out.flush();
out.close();
}
static void solve() throws Exception {
int n = sc.nextInt();
int[] a = new int[n];
long sum = 0L;
for(int i = 0; i < n; i++){
a[i] = sc.nextInt();
}
long left = 0;
for(int i = 0; i < n; i++){
if(a[i]>=i){
left += (a[i]-i);
}
else{
int diff = (i-a[i]);
if(left>=diff){
left -= diff;
}else{
out.println("NO");
return;
}
}
}
out.println("YES");
}
static int query(int l,int r){
out.println("? "+l+" "+r);
out.flush();
return sc.nextInt();
}
static class Pair implements Comparable<Pair> {
int x;
long y;
int idx;
public Pair(int x, long y) {
this.x = x;
this.y = y;
}
@Override
public int compareTo(Pair o) {
if ((this.x == o.x)) {
//return (this.y - o.y);
}
return (this.x - o.x);
}
}
public static long mul(long a, long b) {
return ((a % MOD) * (b % MOD)) % MOD;
}
public static long add(long a, long b) {
return ((a % MOD) + (b % MOD)) % MOD;
}
public static long c2(long n) {
if ((n & 1) == 0) {
return mul(n / 2, n - 1);
} else {
return mul(n, (n - 1) / 2);
}
}
//Shuffle Sort
static final Random random = new Random();
static void ruffleSort(int[] a) {
int n = a.length;//shuffle, then sort
for (int i = 0; i < n; i++) {
int oi = random.nextInt(n); int temp= a[oi];
a[oi] = a[i];
a[i] = temp;
}
Arrays.sort(a);
}
//Brian Kernighans Algorithm
static long countSetBits(long n) {
if (n == 0) return 0;
return 1 + countSetBits(n & (n - 1));
}
//Euclidean Algorithm
static long gcd(long A, long B) {
if (B == 0) return A;
return gcd(B, A % B);
}
//Modular Exponentiation
static long fastExpo(long x, long n) {
if (n == 0) return 1;
if ((n & 1) == 0) return fastExpo((x * x) % MOD, n / 2) % MOD;
return ((x % MOD) * fastExpo((x * x) % MOD, (n - 1) / 2)) % MOD;
}
//AKS Algorithm
static boolean isPrime(long n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i <= Math.sqrt(n); i += 6)
if (n % i == 0 || n % (i + 2) == 0) return false;
return true;
}
public static long modinv(long x) {
return modpow(x, MOD - 2);
}
public static long modpow(long a, long b) {
if (b == 0) {
return 1;
}
long x = modpow(a, b / 2);
x = (x * x) % MOD;
if (b % 2 == 1) {
return (x * a) % MOD;
}
return x;
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
8d446805e29c0e1ef07946562f824402
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class main {
static FastScanner sc;
static PrintWriter pw;
static void pn(Object o){pw.println(o);}
static void p(Object o){pw.print(o);}
public static void main(String[] args) {
// Scanner sc = new Scanner(System.in);
sc = new FastScanner();
pw = new PrintWriter(System.out);
int t = sc.ni();
while(t-->0)
{
int n = sc.ni(),a[] = new int[n];
long sum=0,fg=0;
for(int i=0;i<n;i++)
{
a[i]=sc.ni();
sum += a[i];
if(sum<(i+1)*i/2)fg=1;
}
if(fg==1)pn("No");
else pn("Yes");
}
pw.close();
}
// static int solution(int n,int k)
// {
// for(int i=n;i>=1;i--)a.add(i);
// for(int i=1;i<=n;i++)
// {
// x=i;
// if(a.get(i-1)!=x)
// {
// if(x==n+1)
// { x=1;
// b.add(x);
// }
// }
// else
// {
// if(x==n+1)
// { x=1;
// b.add(x++);
// }
// }
// }
// return b.get(k-1);
static int gcd(int a,int b)
{
if(b!=0)return gcd(b,a%b);
else return a;
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in), 32768);
st = null;
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int ni() {
return Integer.parseInt(next());
}
int[] intArray(int N) {
int[] ret = new int[N];
for (int i = 0; i < N; i++)
ret[i] = ni();
return ret;
}
long nl() {
return Long.parseLong(next());
}
long[] longArray(int N) {
long[] ret = new long[N];
for (int i = 0; i < N; i++)
ret[i] = nl();
return ret;
}
double nd() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
a96a375b15cf32af601196423ce011ae
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.awt.*;
import java.io.*;
import java.util.*;
import java.util.List;
public class Hell {
public static void main(String[] args) throws Exception {
FastReader sc = new FastReader();
int t=sc.nextInt();
while (t-->0){
int n=sc.nextInt();
long arr[]=new long[n];
long sum=0;
boolean ok=true;
for (int i=0;i<n;i++){
arr[i]=sc.nextInt();
}
if (n==1){
System.out.println("YES");
continue;
}
for (int i=1;i<n;i++){
if (i-1<arr[i-1]){
arr[i]+=arr[i-1]-(i-1);
arr[i-1]=i-1;
}
// System.out.println(arr[i-1]);
// System.out.println(arr[i]);
}
for (int i=1;i<n;i++){
if (arr[i]<=arr[i-1])ok=false;
}
if (!ok) System.out.println("NO");
else System.out.println("YES");
}
}
public static long maximumArea(int arr[]){
int n=arr.length;
long suf[]=new long[n];
suf[n-1]=arr[n-1];
for (int i=n-2;i>=0;i--){
suf[i]=arr[i]*(n-i);
}
for(int i=n-2;i>=0;i--){
suf[i]=Math.max(suf[i], suf[i+1]);
}
long ans=0;
for (int i=0;i<n-1;i++){
ans=Math.max((long) arr[i]*(i+1)+suf[i+1], ans);
}
return ans;
}
public static int[] itemsCollected(int t[]){
int n = t.length;
int i=0, j=n-1;
long sumi=0, sumj=0;
while (i<=j){
while (i<=j && sumi<=sumj){
sumi+=t[i];
i++;
}
while (i<=j && sumi>sumj){
sumj+=t[j];
j--;
}
}
return new int[]{i, n-j-1};
}
public static long minimumCost(int c[], int q[]){
PriorityQueue<Point> pq=new PriorityQueue<Point>(new Comparator<Point>() {
@Override
public int compare(Point o1, Point o2) {
return o1.c-o2.c;
}
});
int n=c.length;
long ans=0;
for (int i=0;i<n;i++){
pq.add(new Point(c[i], q[i]));
Point pop=pq.poll();
ans+=pop.c;
if (pop.q-1==0)continue;
pq.add(new Point(pop.c, pop.q-1));
}
return ans;
}
static class Point{
int c, q;
Point(int c, int q){
this.c=c;
this.q=q;
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
2acc67ab1af9e6b6574d6ad8112b6e38
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
public class p1486a{
public static void main(String []args)
{
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
while(t-->0)
{
int n = scan.nextInt();
int a[] = new int[n];
for(int i=0;i<n;i++)
{
a[i] = scan.nextInt();
}
long sum=0;
long c=0;
int flag=1;
for(int i=0;i<n;i++)
{
sum +=a[i];
c+=i;
if(sum<c)
{
flag=0;
break;
}
}
if(flag==0)
System.out.println("NO");
else
System.out.println("YES");
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
c0a52145cf664228329d5019036b8b6d
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class Solver1 {
public static void main(String[] args) {
FastReader in = new FastReader();
int t = in.nextInt();
while (t-- > 0) {
solve(in);
}
}
public static void solve(FastReader in) {
int n = in.nextInt();
int[] h = new int[n];
long sum = 0;
for (int i = 0; i < n; i++) {
h[i] = in.nextInt();
}
for (int i = 0; i < n; i++) {
sum += h[i];
if (sum < i) {
System.out.println("NO");
return;
}
sum -= i;
}
System.out.println("YES");
}
public static class FastReader {
BufferedReader br;
StringTokenizer st;
private FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static class FastWriter {
private static final int BUF_SIZE = 1 << 13;
private final byte[] buf = new byte[BUF_SIZE];
private final OutputStream out;
private int ptr = 0;
private FastWriter() {
out = null;
}
public FastWriter(OutputStream os) {
this.out = os;
}
public FastWriter(String path) {
try {
this.out = new FileOutputStream(path);
} catch (FileNotFoundException e) {
throw new RuntimeException("FastWriter");
}
}
public FastWriter write(byte b) {
buf[ptr++] = b;
if (ptr == BUF_SIZE)
innerflush();
return this;
}
public FastWriter write(char c) {
return write((byte) c);
}
public FastWriter write(char[] s) {
for (char c : s) {
buf[ptr++] = (byte) c;
if (ptr == BUF_SIZE)
innerflush();
}
return this;
}
public FastWriter write(String s) {
s.chars().forEach(c -> {
buf[ptr++] = (byte) c;
if (ptr == BUF_SIZE)
innerflush();
});
return this;
}
private static int countDigits(int l) {
if (l >= 1000000000)
return 10;
if (l >= 100000000)
return 9;
if (l >= 10000000)
return 8;
if (l >= 1000000)
return 7;
if (l >= 100000)
return 6;
if (l >= 10000)
return 5;
if (l >= 1000)
return 4;
if (l >= 100)
return 3;
if (l >= 10)
return 2;
return 1;
}
public FastWriter write(int x) {
if (x == Integer.MIN_VALUE) {
return write((long) x);
}
if (ptr + 12 >= BUF_SIZE)
innerflush();
if (x < 0) {
write((byte) '-');
x = -x;
}
int d = countDigits(x);
for (int i = ptr + d - 1; i >= ptr; i--) {
buf[i] = (byte) ('0' + x % 10);
x /= 10;
}
ptr += d;
return this;
}
private static int countDigits(long l) {
if (l >= 1000000000000000000L)
return 19;
if (l >= 100000000000000000L)
return 18;
if (l >= 10000000000000000L)
return 17;
if (l >= 1000000000000000L)
return 16;
if (l >= 100000000000000L)
return 15;
if (l >= 10000000000000L)
return 14;
if (l >= 1000000000000L)
return 13;
if (l >= 100000000000L)
return 12;
if (l >= 10000000000L)
return 11;
if (l >= 1000000000L)
return 10;
if (l >= 100000000L)
return 9;
if (l >= 10000000L)
return 8;
if (l >= 1000000L)
return 7;
if (l >= 100000L)
return 6;
if (l >= 10000L)
return 5;
if (l >= 1000L)
return 4;
if (l >= 100L)
return 3;
if (l >= 10L)
return 2;
return 1;
}
public FastWriter write(long x) {
if (x == Long.MIN_VALUE) {
return write("" + x);
}
if (ptr + 21 >= BUF_SIZE)
innerflush();
if (x < 0) {
write((byte) '-');
x = -x;
}
int d = countDigits(x);
for (int i = ptr + d - 1; i >= ptr; i--) {
buf[i] = (byte) ('0' + x % 10);
x /= 10;
}
ptr += d;
return this;
}
public FastWriter write(double x, int precision) {
if (x < 0) {
write('-');
x = -x;
}
x += Math.pow(10, -precision) / 2;
// if(x < 0){ x = 0; }
write((long) x).write(".");
x -= (long) x;
for (int i = 0; i < precision; i++) {
x *= 10;
write((char) ('0' + (int) x));
x -= (int) x;
}
return this;
}
public FastWriter writeln(char c) {
return write(c).writeln();
}
public FastWriter writeln(int x) {
return write(x).writeln();
}
public FastWriter writeln(long x) {
return write(x).writeln();
}
public FastWriter writeln(double x, int precision) {
return write(x, precision).writeln();
}
public FastWriter write(int... xs) {
boolean first = true;
for (int x : xs) {
if (!first)
write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter write(long... xs) {
boolean first = true;
for (long x : xs) {
if (!first)
write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter writeln() {
return write((byte) '\n');
}
public FastWriter writeln(int... xs) {
return write(xs).writeln();
}
public FastWriter writeln(long... xs) {
return write(xs).writeln();
}
public FastWriter writeln(char[] line) {
return write(line).writeln();
}
public FastWriter writeln(char[]... map) {
for (char[] line : map)
write(line).writeln();
return this;
}
public FastWriter writeln(String s) {
return write(s).writeln();
}
private void innerflush() {
try {
out.write(buf, 0, ptr);
ptr = 0;
} catch (IOException e) {
throw new RuntimeException("innerflush");
}
}
public void flush() {
innerflush();
try {
out.flush();
} catch (IOException e) {
throw new RuntimeException("flush");
}
}
public FastWriter print(byte b) {
return write(b);
}
public FastWriter print(char c) {
return write(c);
}
public FastWriter print(char[] s) {
return write(s);
}
public FastWriter print(String s) {
return write(s);
}
public FastWriter print(int x) {
return write(x);
}
public FastWriter print(long x) {
return write(x);
}
public FastWriter print(double x, int precision) {
return write(x, precision);
}
public FastWriter println(char c) {
return writeln(c);
}
public FastWriter println(int x) {
return writeln(x);
}
public FastWriter println(long x) {
return writeln(x);
}
public FastWriter println(double x, int precision) {
return writeln(x, precision);
}
public FastWriter print(int... xs) {
return write(xs);
}
public FastWriter print(long... xs) {
return write(xs);
}
public FastWriter println(int... xs) {
return writeln(xs);
}
public FastWriter println(long... xs) {
return writeln(xs);
}
public FastWriter println(char[] line) {
return writeln(line);
}
public FastWriter println(char[]... map) {
return writeln(map);
}
public FastWriter println(String s) {
return writeln(s);
}
public FastWriter println() {
return writeln();
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
9ae8f8d4ad36d8e45f3ce59273d9ee4b
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class CodeForces {
public static void main(String[] args) {
// TODO Auto-generated method stub
FastScanner fs=new FastScanner();
int t=fs.nextInt();
while(t-->0) {
int n=fs.nextInt();
int arr[]=fs.readArray(n);
long sum[]=new long[n];
sum[0]=arr[0];
for(int i=1;i<n;i++) {
sum[i]+=sum[i-1]+arr[i];
}
boolean pbs=true;
for(int i=n;i>0;i--) {
if(!solve(i,sum[i-1])) {
pbs=false;
break;
}
}
if(pbs)
System.out.println("YEs");
else System.out.println("NO");
}
}
private static boolean solve(int n,long sum) {
long size=(long)n;
if(sum<size*(size-1)/2)
return false;
return true;
}
static void mysort(int[] a) {
//ruffle
int n=a.length;
Random r=new Random();
for (int i=0; i<a.length; i++) {
int oi=r.nextInt(n), temp=a[i];
a[i]=a[oi];
a[oi]=temp;
}
//then sort
Arrays.sort(a);
}
// Use this to input code since it is faster than a Scanner
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
9fe5c3766a5cad3e4ab3aa39df634702
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.*;
public class A {
public static void main(String[] args) {
FastScanner fs = new FastScanner();
int T = fs.nextInt();
outer: while (T-- > 0) {
int n = fs.nextInt();
int[] arr = fs.readArray(n);
long available = 0;
available = arr[0];
for (int i = 1; i < n; i++) {
// if (available + arr[i] < i) {
// System.out.println("NO");
// continue outer;
// }
if (arr[i] < i) {
available -= i - arr[i];
if (available < 0) {
System.out.println("NO");
continue outer;
}
} else {
available += arr[i] - i;
}
}
System.out.println("YES");
}
}
static final int mod = 1_000_000_007;
static long mul(long a, long b) {
return a * b % mod;
}
static long fact(int x) {
long ans = 1;
for (int i = 2; i <= x; i++)
ans = mul(ans, i);
return ans;
}
static long fastPow(long base, long exp) {
if (exp == 0)
return 1;
long half = fastPow(base, exp / 2);
if (exp % 2 == 0)
return mul(half, half);
return mul(half, mul(half, base));
}
static long modInv(long x) {
return fastPow(x, mod - 2);
}
static long nCk(int n, int k) {
return mul(fact(n), mul(modInv(fact(k)), modInv(fact(n - k))));
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
class Cool {
int m;
int n;
Cool(int m, int n) {
this.m = m;
this.n = n;
}
}
class SortCool implements Comparator<Cool> {
@Override
public int compare(Cool ob1, Cool ob2) {
return ob1.m - ob2.m;
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
d715c5dcc37515cdf8b8e98422343c8e
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
import java.io.*;
import java.lang.*;
public class cc1 {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(
new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() { return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next()); }
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader sc = new FastReader();
int t = sc.nextInt();
while(t-->0) {
int n = sc.nextInt();
int a[] = new int[n];
long sum = 0;
long k = (long)(n*(n-1))/2;
int p = 0;
boolean b = true;;
for(int i=0; i<n; i++) {
a[i] = sc.nextInt();
sum+=a[i];
if(sum<((long)(i+1)*i)/2) {
b = false;
}
}
if(n<=1) {
System.out.println("YES");
continue;
}
if(sum>=k && b) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
ab1d5db88871a7cc78e51778929b9b67
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.io.PrintWriter;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// System.out.println(sc.nextByte());
PrintWriter pw = new PrintWriter(System.out);
// napolean(sc,pw);
// paint(sc,pw);
// tean(sc,pw);
// ugu(sc,pw);
blockheight(sc,pw);
// for(int j=0;j<8;j++){
// String s=sc.next();
// for(int k=0;k<8;k++){
//
// System.out.println(s.charAt(k));
// }
// }
pw.close();
}
private static void blockheight(Scanner scanner, PrintWriter printWriter){
int testcase=scanner.nextInt();
for(int i=0;i<testcase;i++){
int size=scanner.nextInt();
long[] arr=new long[size];
for(int j=0;j<size;j++){
arr[j]=scanner.nextLong();
}
long requiredblocks=0;
long totalblocks=arr[0];
boolean possible=true;
for(int j=1;j<size;j++){
requiredblocks=requiredblocks+j;
// System.out.println(requiredblocks);
totalblocks+=arr[j];
if (requiredblocks>totalblocks){
System.out.println("NO");
possible=false;
break;
}
}
if (possible){
System.out.println("YES");
}
}
}}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
f03ddc7871a592a97df82207622651ce
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class shifting {
static FastReader in = new FastReader();
static final Random random = new Random();
static long mod = 1000000007L;
static HashMap<String,Integer>map = new HashMap<>();
public static boolean isIncreasing(long [] arr, int n){
if(n<2){
return true;
}
arr[1] = arr[1] + arr[0];
arr[0] = 0;
boolean is_increasing = true;
for(int i=1;i<n;i++){
long req = arr[i-1] + 1;
if(arr[i]<req){
return false;
}
long remain = arr[i] - req;
arr[i] = req;
if(i+1<n){
arr[i+1] = arr[i+1] + remain;
}
}
return true;
}
public static void main(String args[]) throws IOException {
int t = in.nextInt();
loop:
while (t-->0) {
int n = in.nextInt();
long[] arr = in.readlongarray(n);
boolean is_increasing = isIncreasing(arr,n);
if(is_increasing){
print("YES");
}
else{
print("NO");
}
}
}
static int max(int a, int b)
{
if(a<b)
return b;
return a;
}
static void ruffleSort(int[] a) {
int n=a.length;
for (int i=0; i<n; i++) {
int oi=random.nextInt(n), temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
static < E > void print(E res)
{
System.out.println(res);
}
static int gcd(int a,int b)
{
if(b==0)
{
return a;
}
return gcd(b,a%b);
}
static int lcm(int a, int b)
{
return (a / gcd(a, b)) * b;
}
static int abs(int a)
{
if(a<0)
return -1*a;
return a;
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
int [] readintarray(int n) {
int res [] = new int [n];
for(int i = 0; i<n; i++)res[i] = nextInt();
return res;
}
long [] readlongarray(int n) {
long res [] = new long [n];
for(int i = 0; i<n; i++)res[i] = nextLong();
return res;
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
e5ab73b2fc79c1e0a096a72a2d328d4e
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.io.InterruptedIOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import javax.swing.plaf.synth.SynthOptionPaneUI;
public class Main {
private static long gcd(long a, long b)
{
while (b > 0)
{
long temp = b;
b = a % b; // % is remainder
a = temp;
}
return a;
}
private static long lcm(long a, long b)
{
return a * (b / gcd(a, b));
}
static long binpow(long a,long b) {
long M=1000000007;
long res=1;
while(b>0) {
if(b%2==1) {
res=(res*a)%M;
}
a=(a*a)%M;
b/=2;
}
return res;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc1=new Scanner(System.in);
int t=sc1.nextInt();
while(t-->0) {
int n=sc1.nextInt();
long[] num=new long[n];
for(int i=0;i<n;i++) {
num[i]=sc1.nextLong();
}
long sum=0;
for(int i=0;i<n-1;i++) {
if(num[i]>i) {
long k=num[i]-i;
num[i+1]=num[i+1]+k;
num[i]=num[i]-k;
}
}
//for(int i=0;i<n;i++)System.out.print(num[i]+" ");
//num[n-1]+=sum;
boolean flag=false;
for(int i=0;i<n-1;i++) {
if(num[i]>=num[i+1]) {
flag=true;
break;
}
}
if(flag)System.out.println("NO");
else System.out.println("YES");
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
fc942b07ef92e0e7626426b29de63c75
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.Scanner;
public class Stacks{
static Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
int testCases=scan.nextInt();
for(int t=0; t<testCases; t++){
int arrayLength=scan.nextInt();
if(stacksPossible(arrayLength)){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}
public static boolean stacksPossible(int arrayLength){
long totalStacksIHave=0;
long stacksIShouldHave=0;
for(int i=0; i<arrayLength; i++){
stacksIShouldHave+=i;
totalStacksIHave+=scan.nextLong();
if(totalStacksIHave<stacksIShouldHave){
scan.nextLine();
return false;
}
}
return true;
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
8437572a227ddd184c6bfb777297c7f2
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.math.BigInteger;
import java.util.Scanner;
public class Problem1486A {
public static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
int tc = scanner.nextInt();
while (tc-->0) {
int size = scanner.nextInt();
int[] array = new int[size];
long sum = 0;
long sum1= 0;
boolean isPossible = true;
for (int i = 0; i < array.length; i++) {
array[i] = scanner.nextInt();
sum += array[i];
sum1 +=i;
if (sum<sum1) {
isPossible = false;
}
}
if (isPossible) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
95d06b2d305c4254843246b697fb776f
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
//package codeforces;
import java.math.BigInteger;
import java.util.*;
public class Codeforces {
String getMaxCount(String []a) {
Map<String, Integer> m = new HashMap<>();
for (int i = 0; i < a.length; i++) {
if (m.containsKey(a[i])) {
m.put(a[i], m.get(a[i]) + 1);
} else {
m.put(a[i], 1);
}
}
int max = Collections.max(m.values());
for (int i = 0; i < a.length; i++) {
if (max == m.get(a[i])) {
return a[i];
}
}
return "-1";
}
long factorial(long a){
if (a==0)
return 1;
else
return a*factorial(a-1);
}
int gcd(int a,int b){
if (a==0){
return b;
}
return gcd(b%a,a);
}
boolean isPrime(int num){
boolean flag = false;
for (int i = 2; i <= num / 2; ++i) {
if (num % i == 0) {
flag = true;
break;
}
}
if (!flag)
return true;
else
return false;
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
Codeforces cf=new Codeforces();
long t=sc.nextLong();
while (t-- >0){
long n=sc.nextLong();
int []a=new int[(int)n];
long sum=0,need=0;
// long k=(n*(n-1))/2;
boolean flag=false;
for (int i=0;i<n;i++) {
a[i] = sc.nextInt();
sum += a[i];
need += i;
if (sum < ((i*(i+1L))/2)) {
flag = true;
}
}
if (flag){
System.out.println("NO");
}
else{
System.out.println("YES");
}
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
97573eedfd50ecacb675c7df3fe403ed
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
//package shifting_stacks;
//Level - 900
//Link: https://codeforces.com/problemset/problem/1486/A
import java.util.*;
public class Main {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
solution();
}
}
public static void solution() {
int n = sc.nextInt();
int[] mas = new int[n];
long sum = 0, need = 0;
for (int i = 0; i < n; i++) {
mas[i] = sc.nextInt();
}
for (int i = 0; i < n; ++i) {
need += i;
sum += mas[i];
if (sum < need) {
System.out.println("NO");
return;
}
}
System.out.println("YES");
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
4af67df8d908f85cfe2c06681b9c0006
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.Scanner;
public class shiftingStacks {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
try{
int t = scn.nextInt();
while(t-- > 0){
int n = scn.nextInt();
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = scn.nextInt();
}
if(isSorted(arr)){
System.out.println("YES");
}
else{
boolean flag = false;
long[] preSum = new long[n];
preSum[0] = arr[0];
for (int i = 1; i < n; i++) {
preSum[i] = preSum[i-1] + arr[i];
}
long sum = 0;
for (int i = 0; i < n; i++) {
sum += i;
if(sum > preSum[i]){
System.out.println("NO");
flag = true;
break;
}
}
if(flag == false){
System.out.println("YES");
}
}
}
}
catch (Exception e){
return;
}
}
public static boolean isSorted(long[] arr){
for (int i = 0; i < arr.length-1; i++) {
if(arr[i] >= arr[i+1]){
return false;
}
}
return true;
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
563272a52715c56118bbf2de21ed0a96
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.awt.image.renderable.ContextualRenderedImageFactory;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.LinkedTransferQueue;
public class codeforces {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0){
int n = sc.nextInt();
long[] a = new long[n];
long sum = 0;
long minSum = 0;
boolean ans = true;
for (int i = 0; i < n; i++) {
a[i] = sc.nextLong();
}
for (int i = 0; i < n; i++) {
sum += a[i];
minSum += i;
if( sum - minSum < 0 ){
ans = false;
break;
}
}
if(ans) System.out.println("YES");
else System.out.println("NO");
}
}}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
ff375dcb9f824f860fdd4c10066f696b
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class Solution
{
static class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br=new BufferedReader(new InputStreamReader(System.in));
}
String next(){
while(st==null || !st.hasMoreTokens()){
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
double nextDouble(){
return Double.parseDouble(next());
}
String nextLine(){
String str="";
try {
str=br.readLine().trim();
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
}
static class FastWriter {
private final BufferedWriter bw;
public FastWriter() {
this.bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
public void print(Object object) throws IOException {
bw.append("" + object);
}
public void println(Object object) throws IOException {
print(object);
bw.append("\n");
}
public void close() throws IOException {
bw.close();
}
}
public static void main(String[] args){
solve();
}
public static void solve(){
FastReader in = new FastReader();
FastWriter out = new FastWriter();
int t = in.nextInt();
String[] answers = new String[t];
for(int i =0; i < t; i++){
int n = 0, it = 1, ref = 0;
long sum = 0;
boolean b = true;
n = in.nextInt();
long[] array = new long[n];
for(int j =0; j < n; j++){
array[j] = in.nextLong();
sum += array[j];
if(sum >= ref){
ref += it;
it++;
}
else{
answers[i] = "NO";
b = false;
}
}
if(b){
answers[i] = "YES";
}
}
try{
for(String y: answers){
out.println(y);
}
out.close();
} catch(Exception e){}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
cbab0de9a5006763b5fbf397b404ab0b
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
//package round703.a;
import java.io.*;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Queue;
public class Solution {
InputStream is;
FastWriter out;
String INPUT = "";
void solve()
{
for (int T = ni(); T > 0; T--) {
go();
}
}
void go() {
int n = ni();
int[] a = na(n);
long sum = 0;
for (int i = 0; i < n; i++) {
sum += a[i];
sum -= i;
if (sum < 0) {
out.println("NO");
return;
}
}
out.println("YES");
}
void run() throws Exception
{
is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new FastWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
tr(System.currentTimeMillis()-s+"ms");
}
public static void main(String[] args) throws Exception { new Solution().run(); }
private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
private int readByte()
{
if(lenbuf == -1)throw new InputMismatchException();
if(ptrbuf >= lenbuf){
ptrbuf = 0;
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
if(lenbuf <= 0)return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
private double nd() { return Double.parseDouble(ns()); }
private char nc() { return (char)skip(); }
private String ns()
{
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n)
{
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b))){
buf[p++] = (char)b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private int[] na(int n)
{
int[] a = new int[n];
for(int i = 0;i < n;i++)a[i] = ni();
return a;
}
private long[] nal(int n)
{
long[] a = new long[n];
for(int i = 0;i < n;i++)a[i] = nl();
return a;
}
private char[][] nm(int n, int m) {
char[][] map = new char[n][];
for(int i = 0;i < n;i++)map[i] = ns(m);
return map;
}
private int[][] nmi(int n, int m) {
int[][] map = new int[n][];
for(int i = 0;i < n;i++)map[i] = na(m);
return map;
}
private int ni() { return (int)nl(); }
private long nl()
{
long num = 0;
int b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
public static class FastWriter
{
private static final int BUF_SIZE = 1<<13;
private final byte[] buf = new byte[BUF_SIZE];
private final OutputStream out;
private int ptr = 0;
private FastWriter(){out = null;}
public FastWriter(OutputStream os)
{
this.out = os;
}
public FastWriter(String path)
{
try {
this.out = new FileOutputStream(path);
} catch (FileNotFoundException e) {
throw new RuntimeException("FastWriter");
}
}
public FastWriter write(byte b)
{
buf[ptr++] = b;
if(ptr == BUF_SIZE)innerflush();
return this;
}
public FastWriter write(char c)
{
return write((byte)c);
}
public FastWriter write(char[] s)
{
for(char c : s){
buf[ptr++] = (byte)c;
if(ptr == BUF_SIZE)innerflush();
}
return this;
}
public FastWriter write(String s)
{
s.chars().forEach(c -> {
buf[ptr++] = (byte)c;
if(ptr == BUF_SIZE)innerflush();
});
return this;
}
private static int countDigits(int l) {
if (l >= 1000000000) return 10;
if (l >= 100000000) return 9;
if (l >= 10000000) return 8;
if (l >= 1000000) return 7;
if (l >= 100000) return 6;
if (l >= 10000) return 5;
if (l >= 1000) return 4;
if (l >= 100) return 3;
if (l >= 10) return 2;
return 1;
}
public FastWriter write(int x)
{
if(x == Integer.MIN_VALUE){
return write((long)x);
}
if(ptr + 12 >= BUF_SIZE)innerflush();
if(x < 0){
write((byte)'-');
x = -x;
}
int d = countDigits(x);
for(int i = ptr + d - 1;i >= ptr;i--){
buf[i] = (byte)('0'+x%10);
x /= 10;
}
ptr += d;
return this;
}
private static int countDigits(long l) {
if (l >= 1000000000000000000L) return 19;
if (l >= 100000000000000000L) return 18;
if (l >= 10000000000000000L) return 17;
if (l >= 1000000000000000L) return 16;
if (l >= 100000000000000L) return 15;
if (l >= 10000000000000L) return 14;
if (l >= 1000000000000L) return 13;
if (l >= 100000000000L) return 12;
if (l >= 10000000000L) return 11;
if (l >= 1000000000L) return 10;
if (l >= 100000000L) return 9;
if (l >= 10000000L) return 8;
if (l >= 1000000L) return 7;
if (l >= 100000L) return 6;
if (l >= 10000L) return 5;
if (l >= 1000L) return 4;
if (l >= 100L) return 3;
if (l >= 10L) return 2;
return 1;
}
public FastWriter write(long x)
{
if(x == Long.MIN_VALUE){
return write("" + x);
}
if(ptr + 21 >= BUF_SIZE)innerflush();
if(x < 0){
write((byte)'-');
x = -x;
}
int d = countDigits(x);
for(int i = ptr + d - 1;i >= ptr;i--){
buf[i] = (byte)('0'+x%10);
x /= 10;
}
ptr += d;
return this;
}
public FastWriter write(double x, int precision)
{
if(x < 0){
write('-');
x = -x;
}
x += Math.pow(10, -precision)/2;
// if(x < 0){ x = 0; }
write((long)x).write(".");
x -= (long)x;
for(int i = 0;i < precision;i++){
x *= 10;
write((char)('0'+(int)x));
x -= (int)x;
}
return this;
}
public FastWriter writeln(char c){
return write(c).writeln();
}
public FastWriter writeln(int x){
return write(x).writeln();
}
public FastWriter writeln(long x){
return write(x).writeln();
}
public FastWriter writeln(double x, int precision){
return write(x, precision).writeln();
}
public FastWriter write(int... xs)
{
boolean first = true;
for(int x : xs) {
if (!first) write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter write(long... xs)
{
boolean first = true;
for(long x : xs) {
if (!first) write(' ');
first = false;
write(x);
}
return this;
}
public FastWriter writeln()
{
return write((byte)'\n');
}
public FastWriter writeln(int... xs)
{
return write(xs).writeln();
}
public FastWriter writeln(long... xs)
{
return write(xs).writeln();
}
public FastWriter writeln(char[] line)
{
return write(line).writeln();
}
public FastWriter writeln(char[]... map)
{
for(char[] line : map)write(line).writeln();
return this;
}
public FastWriter writeln(String s)
{
return write(s).writeln();
}
private void innerflush()
{
try {
out.write(buf, 0, ptr);
ptr = 0;
} catch (IOException e) {
throw new RuntimeException("innerflush");
}
}
public void flush()
{
innerflush();
try {
out.flush();
} catch (IOException e) {
throw new RuntimeException("flush");
}
}
public FastWriter print(byte b) { return write(b); }
public FastWriter print(char c) { return write(c); }
public FastWriter print(char[] s) { return write(s); }
public FastWriter print(String s) { return write(s); }
public FastWriter print(int x) { return write(x); }
public FastWriter print(long x) { return write(x); }
public FastWriter print(double x, int precision) { return write(x, precision); }
public FastWriter println(char c){ return writeln(c); }
public FastWriter println(int x){ return writeln(x); }
public FastWriter println(long x){ return writeln(x); }
public FastWriter println(double x, int precision){ return writeln(x, precision); }
public FastWriter print(int... xs) { return write(xs); }
public FastWriter print(long... xs) { return write(xs); }
public FastWriter println(int... xs) { return writeln(xs); }
public FastWriter println(long... xs) { return writeln(xs); }
public FastWriter println(char[] line) { return writeln(line); }
public FastWriter println(char[]... map) { return writeln(map); }
public FastWriter println(String s) { return writeln(s); }
public FastWriter println() { return writeln(); }
}
public void trnz(int... o)
{
for(int i = 0;i < o.length;i++)if(o[i] != 0)System.out.print(i+":"+o[i]+" ");
System.out.println();
}
// print ids which are 1
public void trt(long... o)
{
Queue<Integer> stands = new ArrayDeque<>();
for(int i = 0;i < o.length;i++){
for(long x = o[i];x != 0;x &= x-1)stands.add(i<<6|Long.numberOfTrailingZeros(x));
}
System.out.println(stands);
}
public void tf(boolean... r)
{
for(boolean x : r)System.out.print(x?'#':'.');
System.out.println();
}
public void tf(boolean[]... b)
{
for(boolean[] r : b) {
for(boolean x : r)System.out.print(x?'#':'.');
System.out.println();
}
System.out.println();
}
public void tf(long[]... b)
{
if(INPUT.length() != 0) {
for (long[] r : b) {
for (long x : r) {
for (int i = 0; i < 64; i++) {
System.out.print(x << ~i < 0 ? '#' : '.');
}
}
System.out.println();
}
System.out.println();
}
}
public void tf(long... b)
{
if(INPUT.length() != 0) {
for (long x : b) {
for (int i = 0; i < 64; i++) {
System.out.print(x << ~i < 0 ? '#' : '.');
}
}
System.out.println();
}
}
private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
740b5cfd8d43b748ee8ddb1b30e26398
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.io.File;
import java.io.IOException;
import java.util.*;
public class Solution {
private static int[] auf = new int[51];
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
StringBuilder stringBuilder = new StringBuilder();
int t = scanner.nextInt();
int[] hills = new int[101];
for (int z = 0 ; z < t ; ++z) {
int n = scanner.nextInt();
for (int i = 0 ; i < n ; ++i) hills[i] = scanner.nextInt();
if (solve(hills, n)) stringBuilder.append("YES");
else stringBuilder.append("NO");
stringBuilder.append('\n');
}
System.out.println(stringBuilder);
}
private static boolean solve(int[] hills, int n) {
long accum = 0;
for (int i = 0 ; i < n ; ++i) {
int cur = hills[i] - i;
accum += cur;
if (accum < 0) return false;
}
return true;
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
0ffded9ac3d55d585d87f0e05282b226
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
public class main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int T = scanner.nextInt();
while (T!=0) {
int n = scanner.nextInt();
long cur_sum = 0, need = 0;
boolean ok = true;
for (int i = 0; i < n; i++) {
long x = scanner.nextInt();
cur_sum += x;
need += i;
if (cur_sum < need) {
ok = false;
}
}
System.out.println(ok ? "YES\n" : "NO\n");
T--;
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
0a3d03f3a0c53ebc8561f7e80c001ed3
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class S {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
float nextFloat() {
return Float.parseFloat(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
char nextChar() {
char c = ' ';
try {
c = (char) br.read();
} catch (Exception e) {
e.printStackTrace();
}
return c;
}
}
public static void main(String[] args) {
FastReader sc = new FastReader();
int ntc = sc.nextInt();
while(ntc -- > 0){
int N = sc.nextInt();
int [] h = new int[N];
for(int i= 0; i<N; i++){
h[i] = sc.nextInt();
}
boolean isPossible = true;
long sum = 0L;
for(int i = 0; i<N; i++){
sum+= (long) h[i];
long min = (i * 1L * (i + 1))/2;
if(sum < min){
isPossible = false;
}
}
if(!isPossible){
System.out.println("NO");
}else {
System.out.println("YES");
}
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
83e3e6fd0efa99962b9b1f3ab6c19cfb
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
public class A{
// author: Tarun Verma
static FastScanner sc = new FastScanner();
static int inf = Integer.MAX_VALUE;
static long mod = 1000000007;
static boolean isPalindrom(char[] arr, int i, int j) {
boolean ok = true;
while (i <= j) {
if (arr[i] != arr[j]) {
ok = false;
break;
}
i++;
j--;
}
return ok;
}
static int max(int a, int b) {
return Math.max(a, b);
}
static int min(int a, int b) {
return Math.min(a, b);
}
static long max(long a, long b) {
return Math.max(a, b);
}
static long min(long a, long b) {
return Math.min(a, b);
}
static int abs(int a) {
return Math.abs(a);
}
static long abs(long a) {
return Math.abs(a);
}
static void swap(long arr[], int i, int j) {
long temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
static void swap(int arr[], int i, int j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
static int maxArr(int arr[]) {
int maxi = Integer.MIN_VALUE;
for (int x : arr)
maxi = max(maxi, x);
return maxi;
}
static int minArr(int arr[]) {
int mini = Integer.MAX_VALUE;
for (int x : arr)
mini = min(mini, x);
return mini;
}
static long maxArr(long arr[]) {
long maxi = Long.MIN_VALUE;
for (long x : arr)
maxi = max(maxi, x);
return maxi;
}
static long minArr(long arr[]) {
long mini = Long.MAX_VALUE;
for (long x : arr)
mini = min(mini, x);
return mini;
}
static long gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
static long gcd(long a, long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
static void ruffleSort(int[] a) {
int n = a.length;
Random r = new Random();
for (int i = 0; i < a.length; i++) {
int oi = r.nextInt(n);
int temp = a[i];
a[i] = a[oi];
a[oi] = temp;
}
Arrays.sort(a);
}
public static int binarySearch(int a[], int target) {
int left = 0;
int right = a.length - 1;
int mid = (left + right) / 2;
int i = 0;
while (left <= right) {
if (a[mid] <= target) {
i = mid + 1;
left = mid + 1;
} else {
right = mid - 1;
}
mid = (left + right) / 2;
}
return i;
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
int[][] read2dArray(int n, int m) {
int arr[][] = new int[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
arr[i][j] = nextInt();
}
}
return arr;
}
ArrayList<Integer> readArrayList(int n) {
ArrayList<Integer> arr = new ArrayList<Integer>();
for (int i = 0; i < n; i++) {
int a = nextInt();
arr.add(a);
}
return arr;
}
long nextLong() {
return Long.parseLong(next());
}
}
static class pair {
int fr, sc;
pair(int fr, int sc) {
this.fr = fr;
this.sc = sc;
}
}
////////////////////////////////////////////////////////////////////////////////////
////////////////////DO NOT TOUCH BEFORE THIS LINE //////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
public static void solve() {
long n = sc.nextLong();
long sum = 0;
long arr[] = new long[(int) n];
for(int i =0;i<n;i++) {
sum += sc.nextLong();
arr[i] = sum;
}
// for(long i : arr) {
// System.out.print(i + " ");
// }System.out.println();
for(int i =1;i<n;i++) {
if(arr[i] < (i * (i+1) / 2)){
System.out.println("NO");
return;
}
}
System.out.println("YES");
}
public static void main(String[] args) {
int t = 1;
t = sc.nextInt();
outer: for (int tt = 0; tt < t; tt++) {
solve();
}
}
////////////////////////////////////////////////////////////////////////////////////
//////////////////THIS IS THE LAST CHANCE!!!!!//////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
cf169157b4f3eaccd261cd833c8a82a6
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class Main {
static BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(System.out));
static StringTokenizer tok;
public static void main(String[] args) throws Exception {
solution();
}
public static void solution() throws Exception {
int TestCase = Integer.parseInt(rd.readLine());
for(int TT=0;TT<TestCase;TT++) {
int n = Integer.parseInt(rd.readLine());
tok = new StringTokenizer(rd.readLine());
boolean pass = true;
long[] arr = new long[n];
arr[0] = Long.parseLong(tok.nextToken());
for(int i=1;i<n;i++) arr[i] = arr[i-1] + Long.parseLong (tok.nextToken());
for(int i=0;i<n;i++) {
if(arr[i] < ((i+1)*i)/2) {
pass = false;
break;
}
}
if(pass) wr.write("YES");
else wr.write("NO");
wr.newLine();
}
wr.flush();
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
882c5781e5215342ad78cc408a6fcf02
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
public class A {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
long t = in.nextLong();
while(t-->0) {
int n = in.nextInt();
int h[] = new int[n];
for(int i = 0; i < n; i++) h[i] = in.nextInt();
long sum = 0, flag = 0;
for(int i = 0; i < n; i++) {
sum += h[i] - i;
if(sum < 0) {
System.out.println("NO");
flag++;
break;
}
}
if(flag == 0) System.out.println("YES");
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
43495ceb1d3f3263ea131de7a18c7213
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
// import java.util.Vector;
import java.util.*;
import java.lang.Math;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import javax.management.Query;
import java.io.*;
import java.math.BigInteger;
import java.io.FileWriter;
public class Main {
static int mod = 1000000007;
static class Edge {
int to;
long time, k;
public Edge(int to, long time, long k) {
this.to = to;
this.time = time;
this.k = k;
}
}
static class Pair implements Comparator<Pair> {
long x;
long y;
// Constructor
public Pair(long x, long y) {
this.x = x;
this.y = y;
}
public Pair() {
}
@Override
public int compare(Main.Pair o1, Main.Pair o2) {
// System.out.println("fuck1");
// return((int)(-o1.y+o2.y));
if (o1.y > o2.y)
return -1;
if (o1.y < o2.y)
return 1;
if (o1.y == o2.y) {
if (o1.x < o2.x)
return -1;
else
return 1;
}
return 0;
}
}
// class to define user defined conparator
static class Compare implements Comparator<Pair> {
public int compare(Pair p1, Pair p2) {
// System.out.println("fuck");
if (p1.x == p2.x) {
if (p1.y > p2.y) {
return 1;
} else if (p1.y == p2.y) {
return 0;
} else {
return -1;
}
}
if (p1.x > p2.x)
return 1;
else
return -1;
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] intArr(int n) {
int res[] = new int[n];
for (int i = 0; i < n; i++)
res[i] = nextInt();
return res;
}
long[] longArr(int n) {
long res[] = new long[n];
for (int i = 0; i < n; i++)
res[i] = nextLong();
return res;
}
}
static FastReader f = new FastReader();
static boolean isPrime(long n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (long i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
static int LowerBound(int a[], int x) { // smallest index having value >= x
int l = -1, r = a.length;
while (l + 1 < r) {
int m = (l + r) >>> 1;
if (a[m] >= x)
r = m;
else
l = m;
}
return r;
}
static int UpperBound(int a[], int x) {// biggest index having value <= x
int l = -1, r = a.length;
while (l + 1 < r) {
int m = (l + r) >>> 1;
if (a[m] <= x)
l = m;
else
r = m;
}
return l + 1;
}
static long gcd(long a, long b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
static long lcm(long a, long b) {
return (a * b) / gcd(a, b);
}
static long power(long x, long y, long p) {
long res = 1;
x = x % p;
while (y > 0) {
if (y % 2 == 1)
res = (res * x) % p;
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
static long power(long x, long y) {
long res = 1;
while (y > 0) {
if (y % 2 == 1)
res = (res * x);
y >>= 1;
x = (x * x);
}
return res;
}
static int power(int x, int y) {
int res = 1;
while (y > 0) {
if (y % 2 == 1)
res = (res * x);
y >>= 1;
x = (x * x);
}
return res;
}
static int ceil(int x, int y) {
return (x % y == 0 ? x / y : (x / y + 1));
}
static long ceil(long x, long y) {
return (x % y == 0 ? x / y : (x / y + 1));
}
/*
* ===========Modular Operations==================
*/
static long modInverse(long n, long p) {
return power(n, p - 2, p);
}
static long modAdd(long a, long b) {
return (a % mod + b % mod) % mod;
}
static long modMul(long a, long b) {
return ((a % mod) * (b % mod)) % mod;
}
static long nCrModPFermat(int n, int r) {
long p = 1000000007;
if (r == 0)
return 1;
long[] fac = new long[n + 1];
fac[0] = 1;
for (int i = 1; i <= n; i++)
fac[i] = fac[i - 1] * i % p;
return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;
}
/*
* ===============================================
*/
List<Integer> removeDup(ArrayList<Integer> list) {
List<Integer> newList = list.stream().distinct().collect(Collectors.toList());
return newList;
}
static void ruffleSort(long[] a) {
int n = a.length;
Random r = new Random();
for (int i = 0; i < a.length; i++) {
int oi = r.nextInt(n);
long temp = a[i];
a[i] = a[oi];
a[oi] = temp;
}
Arrays.sort(a);
}
static void ruffleSort(int[] a) {
int n = a.length;
Random r = new Random();
for (int i = 0; i < a.length; i++) {
int oi = r.nextInt(n);
int temp = a[i];
a[i] = a[oi];
a[oi] = temp;
}
Arrays.sort(a);
}
/*
* ===========Dynamic prog Recur Section===========
*/
static int DP[][];
static ArrayList<ArrayList<Integer>> g;
static int count = 0;
static void makeG(int head, int a[], boolean vis[], int leftLim, int rightLim) {
if (head == -1) {
return;
}
vis[head] = true;
// System.out.println(head);
int maxL = 0, posL = -1, maxR = 0, posR = -1;
for (int i = leftLim; i < head; i++) {
if (vis[i])
continue;
if (maxL < a[i]) {
maxL = a[i];
posL = i;
}
}
for (int i = head + 1; i < rightLim; i++) {
if (vis[i])
continue;
if (maxR < a[i]) {
maxR = a[i];
posR = i;
}
}
// System.out.println(posL+" "+posR);
if (posL != -1) {
g.get(head).add(posL);
g.get(posL).add(head);
makeG(posL, a, vis, leftLim, head);
}
if (posR != -1) {
g.get(head).add(posR);
g.get(posR).add(head);
makeG(posR, a, vis, head, rightLim);
}
}
/*
* ====================================Main=================================
*/
public static void main(String args[]) throws Exception {
BufferedWriter w = new BufferedWriter(new OutputStreamWriter(System.out));
Random rand = new Random();
int t = 1;
t = f.nextInt();
while (t-- != 0) {
int n = f.nextInt();
long a[] = new long[n];
a = f.longArr(n);
int flag=1;
// Arrays.sort(a);
for(int i=0;i<n-1;i++){
if(a[i]>i){
a[i+1]+=a[i]-i;
a[i]=i;
}
}
for(int i=0;i<n-1;i++){
if(a[i]>=a[i+1]){
flag=0;break;
}
}
w.write((flag==1)?"YES\n":"NO\n");
}
w.flush();
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
04deab4873036d4a8402992d7154d1f6
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st;
String s=br.readLine();
int T=Integer.parseInt(s);
int n;
boolean ck=false;
long sum,temp;
for(int t=0;t<T;t++) {
s=br.readLine();
n=Integer.parseInt(s);
s=br.readLine();
st=new StringTokenizer(s);
sum=0;
ck=true;
for(int i=0;i<n;i++) {
temp=Long.parseLong(st.nextToken());
sum+=temp;
if(sum<i*(i+1)/2) {
ck=false;
break;
}
}
if(n==1||ck) bw.write("YES\n");
else bw.write("NO\n");
}
bw.flush();
bw.close();
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
0420a46baeb5d01159aea17a01a756f9
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
public class Codeforces {
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();
}
long current=a[0];
for(int i=1;i<n;i++)
{
current+=a[i]-i;
if(current<0)
{
break;
}
}
if(current<0)
{
System.out.println("NO");
}else
{
System.out.println("YES");
}
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
bf7aa992f30b2abfc84a3914b4c11b9b
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
int[] arr=new int[n];
for(int i=0;i<n;i++){
arr[i]=sc.nextInt();
}
long sum=0;
long need=0;
boolean flag=true;
for(int i=0;i<n;i++){
sum+=arr[i];
need+=i;
if(sum<need){
flag=false;
break;
}
}
if(flag){
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
af6843e1e51984c077574e1790e0d14d
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
//package start;
import java.io.*;
import java.lang.*;
import java.math.BigInteger;
import java.util.*;
import java.util.function.BiFunction;
public class Main extends IO {
public static void main(String[] args) throws Exception {
long quantity = readLong();
mainCycle:
for (long i = 0; i < quantity; i++){
long size = readInt();
long[] base = readArrayLong(" ");
long count = base[0];
for (int j = 1; j < size; j++){
if (base[j] < j && (j - base[j] > count)){
writeString("no", "\n");
continue mainCycle;
}else if (base[j] < j){
count -= j - base[j];
base[j] = j;
}
if (base[j] > j){
count += base[j] - j;
}
}
writeString("YES", "\n");
}
print();
}
}
class math {
protected static long remains = 0x3B9ACA07; // 1000000007
static Integer[] convertBase(int value, int toBase) {
if (toBase == 1) {
throw new InputMismatchException("base = 1");
}
List<Integer> result = new ArrayList<>();
while (value / toBase >= 1) {
result.add(0, value % toBase);
value /= toBase;
}
result.add(0, value % toBase);
return result.toArray(Integer[]::new);
}
protected static int gcd(int a, int b) { // NOD
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
protected static long gcd(long a, long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
protected static float gcd(float a, float b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
protected static double gcd(double a, double b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
protected static double lcm(double a, double b) { // NOK
return a / gcd(a, b) * b;
}
protected static float lcm(float a, float b) { // NOK
return a / gcd(a, b) * b;
}
protected static int lcm(int a, int b) { // NOK
return a / gcd(a, b) * b;
}
protected static long lcm(long a, long b) {
return a / gcd(a, b) * b;
}
protected static long mult(long a, long b) {
return ((a % remains) * (b % remains)) % remains;
}
protected static long binpow(long base, long power) {
long res = 1;
while (power != 0)
if ((power & 1) == 1) {
res = mult(res, base);
power--;
} else {
base = mult(base, base);
power >>= 1;
}
return res;
}
protected static double log(double value, int base) {
return Math.log(value) / Math.log(base);
}
protected static long factorial(int number) {
if (number < 0) {
return 0;
}
return solveFactorial(number);
}
private static long solveFactorial(int number) {
if (number > 0) {
return solveFactorial(number - 1) * number;
}
return 1;
}
static boolean[] solveEratosfen(int count) {
boolean[] isPrimes = new boolean[count];
Arrays.fill(isPrimes, true);
isPrimes[0] = false;
isPrimes[1] = false;
for (int i = 2; i < isPrimes.length; i++) {
if (isPrimes[i]) {
for (int j = 2; i * j < isPrimes.length; j++) {
isPrimes[i * j] = false;
}
}
}
return isPrimes;
}
}
class Int implements Comparable<Integer> {
protected int value;
Int(int value) {
this.value = value;
}
public Int add(int value) {
this.value += value;
return this;
}
@Override
public int compareTo(Integer o) {
return (this.value < o) ? -1 : ((this.value == o) ? 0 : 1);
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Integer) {
return value == (Integer) obj;
}
return false;
}
@Override
public int hashCode() {
return value;
}
@Override
protected void finalize() throws Throwable {
super.finalize();
}
}
class Fraction<T extends Number> extends Pair {
private Fraction(T dividend, T divider) {
super(dividend, divider);
reduce();
}
protected static <T extends Number> Fraction<T> createFraction(T dividend, T divider) {
return new Fraction<>(dividend, divider);
}
protected void reduce() {
if (getFirstElement() instanceof Integer) {
Integer Dividend = (Integer) getFirstElement();
Integer Divider = (Integer) getSecondElement();
int gcd = math.gcd(Dividend, Divider);
setFirst(Dividend / gcd);
setSecond(Divider / gcd);
} else if (getFirstElement() instanceof Long) {
Long Dividend = (Long) getFirstElement();
Long Divider = (Long) getSecondElement();
long gcd = math.gcd(Dividend, Divider);
setFirst(Dividend / gcd);
setSecond(Divider / gcd);
} else if (getFirstElement() instanceof Float) {
Float Dividend = (Float) getFirstElement();
Float Divider = (Float) getSecondElement();
float gcd = math.gcd(Dividend, Divider);
setFirst(Dividend / gcd);
setSecond(Divider / gcd);
} else if (getFirstElement() instanceof Double) {
Double Dividend = (Double) getFirstElement();
Double Divider = (Double) getSecondElement();
double gcd = math.gcd(Dividend, Divider);
setFirst(Dividend / gcd);
setSecond(Divider / gcd);
}
}
protected void addWithoutReturn(Fraction number) throws UnsupportedOperationException {
add(number, 0);
}
private Fraction add(Fraction number, int function) throws UnsupportedOperationException {
if (getFirstElement() instanceof Integer && number.getFirstElement() instanceof Integer) {
Integer Dividend = (Integer) getFirstElement();
Integer Divider = (Integer) getSecondElement();
Integer Dividend1 = (Integer) number.getFirstElement();
Integer Divider1 = (Integer) number.getSecondElement();
Integer lcm = math.lcm(Divider, Divider1);
if (function == 0) {
setFirst((lcm / Divider) * Dividend + (lcm / Divider1) * Dividend1);
setSecond(lcm);
reduce();
return null;
}
Fraction result = Fraction.createFraction((lcm / Divider) * Dividend + (lcm / Divider1) * Dividend1, lcm);
result.reduce();
return result;
} else if (getFirstElement() instanceof Long && number.getFirstElement() instanceof Long) {
Long Dividend = (Long) getFirstElement();
Long Divider = (Long) getSecondElement();
Long Dividend1 = (Long) number.getFirstElement();
Long Divider1 = (Long) number.getSecondElement();
Long lcm = math.lcm(Divider, Divider1);
if (function == 0) {
setFirst((lcm / Divider) * Dividend + (lcm / Divider1) * Dividend1);
setSecond(lcm);
reduce();
return null;
}
Fraction result = Fraction.createFraction((lcm / Divider) * Dividend + (lcm / Divider1) * Dividend1, lcm);
result.reduce();
return result;
} else if (getFirstElement() instanceof Float && number.getFirstElement() instanceof Float) {
Float Dividend = (Float) getFirstElement();
Float Divider = (Float) getSecondElement();
Float Dividend1 = (Float) number.getFirstElement();
Float Divider1 = (Float) number.getSecondElement();
Float lcm = math.lcm(Divider, Divider1);
if (function == 0) {
setFirst((lcm / Divider) * Dividend + (lcm / Divider1) * Dividend1);
setSecond(lcm);
reduce();
return null;
}
Fraction result = Fraction.createFraction((lcm / Divider) * Dividend + (lcm / Divider1) * Dividend1, lcm);
result.reduce();
return result;
} else if (getFirstElement() instanceof Double && number.getFirstElement() instanceof Double) {
Double Dividend = (Double) getFirstElement();
Double Divider = (Double) getSecondElement();
Double Dividend1 = (Double) number.getFirstElement();
Double Divider1 = (Double) number.getSecondElement();
Double lcm = math.lcm(Divider, Divider1);
if (function == 0) {
setFirst((lcm / Divider) * Dividend + (lcm / Divider1) * Dividend1);
setSecond(lcm);
reduce();
return null;
}
Fraction result = Fraction.createFraction((lcm / Divider) * Dividend + (lcm / Divider1) * Dividend1, lcm);
result.reduce();
return result;
} else {
throw new UnsupportedOperationException();
}
}
protected Fraction addWithReturn(Fraction number) {
return add(number, 1);
}
protected void multiplyWithoutReturn(Fraction number) throws UnsupportedOperationException {
multiply(number, 0);
}
protected Fraction multiplyWithReturn(Fraction number) throws UnsupportedOperationException {
return multiply(number, 1);
}
private Fraction multiply(Fraction number, int function) throws UnsupportedOperationException {
if (getFirstElement() instanceof Integer && number.getFirstElement() instanceof Integer) {
Integer first = (Integer) getFirstElement() * (Integer) number.getFirstElement();
Integer second = (Integer) getSecondElement() * (Integer) number.getSecondElement();
if (function == 0) {
setFirst(first);
setSecond(second);
reduce();
return null;
}
Fraction answer = Fraction.createFraction(first, second);
answer.reduce();
return answer;
} else if (getFirstElement() instanceof Long && number.getFirstElement() instanceof Long) {
Long first = (Long) getFirstElement() * (Long) number.getFirstElement();
Long second = (Long) getSecondElement() * (Long) number.getSecondElement();
if (function == 0) {
setFirst(first);
setSecond(second);
reduce();
return null;
}
Fraction answer = Fraction.createFraction(first, second);
answer.reduce();
return answer;
} else if (getFirstElement() instanceof Float && number.getFirstElement() instanceof Float) {
Float first = (Float) getFirstElement() * (Float) number.getFirstElement();
Float second = (Float) getSecondElement() * (Float) number.getSecondElement();
if (function == 0) {
setFirst(first);
setSecond(second);
reduce();
return null;
}
Fraction answer = Fraction.createFraction(first, second);
answer.reduce();
return answer;
} else if (getFirstElement() instanceof Double && number.getFirstElement() instanceof Double) {
Double first = (Double) getFirstElement() * (Double) number.getFirstElement();
Double second = (Double) getSecondElement() * (Double) number.getSecondElement();
if (function == 0) {
setFirst(first);
setSecond(second);
reduce();
return null;
}
Fraction answer = Fraction.createFraction(first, second);
answer.reduce();
return answer;
} else {
throw new UnsupportedOperationException();
}
}
}
class Pair<T, T1> implements Cloneable {
private T first;
private T1 second;
Pair(T obj, T1 obj1) {
first = obj;
second = obj1;
}
protected static <T, T1> Pair<T, T1> createPair(T element, T1 element1) {
return new Pair<>(element, element1);
}
protected T getFirstElement() {
return first;
}
protected T1 getSecondElement() {
return second;
}
protected void setFirst(T element) {
first = element;
}
protected void setSecond(T1 element) {
second = element;
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Pair)) {
return false;
}
Pair pair = (Pair) obj;
return first.equals(pair.first) && second.equals(pair.second);
}
@Override
public int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + (first == null ? 0 : first.hashCode());
return 31 * hashCode + (second == null ? 0 : second.hashCode());
}
@Override
public Object clone() {
return Pair.createPair(first, second);
}
}
class Graph {
private int[][] base;
private boolean[] used;
private int quantity;
private Integer[] ancestor;
public int[][] getBase() {
return base;
}
public boolean[] getUsed() {
return used;
}
public int getQuantity() {
return quantity;
}
public Integer[] getAncestor() {
return ancestor;
}
public void setBase(int[][] base) {
this.base = base;
}
protected void start(int length) {
used = new boolean[length];
ancestor = new Integer[length];
Arrays.fill(ancestor, -1);
quantity = 0;
}
protected void edgesMatrixToDefault(int length, int inputQuantity, boolean readConsole, int[][] value) throws Exception {
base = new int[length][];
List<ArrayList<Integer>> inputBase = new ArrayList<>();
for (int i = 0; i < length; i++) {
inputBase.add(new ArrayList<>());
}
for (int i = 0; i < inputQuantity; i++) {
int[] input = readConsole ? IO.readArrayInt(" ") : value[i];
inputBase.get(input[0] - 1).add(input[1] - 1);
inputBase.get(input[0] - 1).add(input[2]); // price
inputBase.get(input[1] - 1).add(input[0] - 1);
inputBase.get(input[1] - 1).add(input[2]); // price
}
for (int i = 0; i < length; i++) {
base[i] = inputBase.get(i).stream().mapToInt(Integer::intValue).toArray();
}
start(length);
}
protected void adjacencyMatrixToDefault(int length, int not, boolean readConsole, int[][] value) throws Exception {
this.base = new int[length][];
List<Integer> buffer = new ArrayList<>();
for (int i = 0; i < length; i++) {
int[] InputArray = readConsole ? IO.readArrayInt(" ") : value[i];
for (int index = 0; index < length; index++) {
if (i != index && InputArray[index] != not) {
buffer.add(index);
// buffer.add(InputArray[index]); // price
}
}
this.base[i] = buffer.stream().mapToInt(Integer::intValue).toArray();
buffer.clear();
}
start(length);
}
protected int dfs(int position) throws Exception {
used[position] = true;
int next;
int count = 0;
for (int index = 0; index < base[position].length; index += 2) {
next = base[position][index];
if (!used[next]) {
ancestor[next] = position;
count += dfs(next);
}
/*else {
if (next != ancestor[position]) { // if cycle
throw new Exception();
}
}*/
}
if (base[position].length == 2 && base[position][0] == ancestor[position]) {
return 1;
}
return count;
}
protected int dijkstra(int start, int stop, int size) {
start--;
stop--;
int[] dist = new int[size];
for (int i = 0; i < size; i++) {
if (i != start) {
dist[i] = Integer.MAX_VALUE;
}
ancestor[i] = start;
}
Queue<int[]> queue = new PriorityQueue<>(Comparator.comparingInt((int[] ints) -> ints[1]));
queue.add(new int[]{start, 0});
int position;
int[] getQueue;
while (queue.size() != 0) {
getQueue = queue.poll();
position = getQueue[0];
if (getQueue[1] > dist[position]) {
continue;
}
for (int index = 0; index < this.base[position].length; index += 2) {
if (dist[position] + this.base[position][index + 1] < dist[this.base[position][index]] && !this.used[this.base[position][index]]) {
dist[this.base[position][index]] = dist[position] + this.base[position][index + 1];
this.ancestor[this.base[position][index]] = position;
queue.add(new int[]{this.base[position][index], dist[this.base[position][index]]});
}
}
used[position] = true;
}
return dist[stop] == Integer.MAX_VALUE ? -1 : dist[stop];
}
protected static boolean solveFloydWarshall(int[][] base, int length, int not) {
for (int k = 0; k < length; k++) {
for (int i = 0; i < length; i++) {
for (int j = 0; j < length; j++) {
if (base[i][k] == not || base[k][j] == not) {
continue;
}
int total = base[i][k] + base[k][j];
if (base[i][j] != not) {
base[i][j] = Math.min(base[i][j], total);
} else {
base[i][j] = total;
}
}
}
}
for (int index = 0; index < length; index++) {
if (base[index][index] != 0) { // if cycle
return false;
}
}
return true;
}
protected static Pair<Long, int[][]> solveKruskal(int[][] edgesMatrix, final int countVertex, final int indexSort) {
int[][] answer = new int[countVertex - 1][2];
long sum = 0;
Arrays.sort(edgesMatrix, Comparator.comparingInt(value -> value[indexSort]));
SystemOfDisjointSets dsu = new SystemOfDisjointSets(countVertex);
for (int i = 0; i < countVertex; i++) {
dsu.makeSet(i);
}
int index = 0;
for (int[] value : edgesMatrix) {
if (dsu.mergeSets(value[0], value[1])) {
sum += value[indexSort];
answer[index] = new int[]{value[0], value[1]};
index++;
}
}
if (index < countVertex - 1) {
return Pair.createPair(null, null);
}
return Pair.createPair(sum, answer);
}
static class SegmentTree {
private int[] segmentArray;
private BiFunction<Integer, Integer, Integer> function;
protected void setSegmentArray(int[] segmentArray) {
this.segmentArray = segmentArray;
}
protected int[] getSegmentArray() {
return segmentArray.clone();
}
protected void setFunction(BiFunction<Integer, Integer, Integer> function) {
this.function = function;
}
protected BiFunction<Integer, Integer, Integer> getFunction() {
return function;
}
SegmentTree() {
}
SegmentTree(int[] startBase, int neutral, BiFunction<Integer, Integer, Integer> function) {
this.function = function;
int length = startBase.length;
int[] base;
if ((length & (length - 1)) != 0) {
int pow = 0;
while (length > 0) {
length >>= 1;
pow++;
}
pow--;
base = new int[2 << pow];
System.arraycopy(startBase, 0, base, 0, startBase.length);
Arrays.fill(base, startBase.length, base.length, neutral);
} else {
base = startBase;
}
segmentArray = new int[base.length << 1]; // maybe * 4
Arrays.fill(segmentArray, neutral);
inDepth(base, 1, 0, base.length - 1);
}
private void inDepth(int[] base, int position, int low, int high) {
if (low == high) {
segmentArray[position] = base[low];
} else {
int mid = (low + high) >> 1;
inDepth(base, position << 1, low, mid);
inDepth(base, (position << 1) + 1, mid + 1, high);
segmentArray[position] = function.apply(segmentArray[position << 1], segmentArray[(position << 1) + 1]);
}
}
protected int getValue(int left, int right, int neutral) {
return findValue(1, 0, ((segmentArray.length) >> 1) - 1, left, right, neutral);
}
private int findValue(int position, int low, int high, int left, int right, int neutral) {
if (left > right) {
return neutral;
}
if (left == low && right == high) {
return segmentArray[position];
}
int mid = (low + high) >> 1;
return function.apply(findValue(position << 1, low, mid, left, Math.min(right, mid), neutral),
findValue((position << 1) + 1, mid + 1, high, Math.max(left, mid + 1), right, neutral));
}
protected void replaceValue(int index, int value) {
update(1, 0, (segmentArray.length >> 1) - 1, index, value);
}
private void update(int position, int low, int high, int index, int value) {
if (low == high) {
segmentArray[position] = value;
} else {
int mid = (low + high) >> 1;
if (index <= mid) {
update(position << 1, low, mid, index, value);
} else {
update((position << 1) + 1, mid + 1, high, index, value);
}
segmentArray[position] = function.apply(segmentArray[position << 1], segmentArray[(position << 1) + 1]);
}
}
}
static class SegmentTreeGeneric<T> {
private Object[] segmentArray;
private BiFunction<T, T, T> function;
protected void setSegmentArray(T[] segmentArray) {
this.segmentArray = segmentArray;
}
protected Object getSegmentArray() {
return segmentArray.clone();
}
protected void setFunction(BiFunction<T, T, T> function) {
this.function = function;
}
protected BiFunction<T, T, T> getFunction() {
return function;
}
SegmentTreeGeneric() {
}
SegmentTreeGeneric(T[] startBase, T neutral, BiFunction<T, T, T> function) {
this.function = function;
int length = startBase.length;
Object[] base;
if ((length & (length - 1)) != 0) {
int pow = 0;
while (length > 0) {
length >>= 1;
pow++;
}
pow--;
base = new Object[2 << pow];
System.arraycopy(startBase, 0, base, 0, startBase.length);
Arrays.fill(base, startBase.length, base.length, neutral);
} else {
base = startBase;
}
segmentArray = new Object[base.length << 1]; // maybe * 4
Arrays.fill(segmentArray, neutral);
inDepth(base, 1, 0, base.length - 1);
}
private void inDepth(Object[] base, int position, int low, int high) {
if (low == high) {
segmentArray[position] = base[low];
} else {
int mid = (low + high) >> 1;
inDepth(base, position << 1, low, mid);
inDepth(base, (position << 1) + 1, mid + 1, high);
segmentArray[position] = function.apply((T) segmentArray[position << 1], (T) segmentArray[(position << 1) + 1]);
}
}
protected T getValue(int left, int right, T neutral) {
return findValue(1, 0, ((segmentArray.length) >> 1) - 1, left, right, neutral);
}
private T findValue(int position, int low, int high, int left, int right, T neutral) {
if (left > right) {
return neutral;
}
if (left == low && right == high) {
return (T) segmentArray[position];
}
int mid = (low + high) >> 1;
return function.apply(findValue(position << 1, low, mid, left, Math.min(right, mid), neutral),
findValue((position << 1) + 1, mid + 1, high, Math.max(left, mid + 1), right, neutral));
}
protected void replaceValue(int index, T value) {
update(1, 0, (segmentArray.length >> 1) - 1, index, value);
}
private void update(int position, int low, int high, int index, T value) {
if (low == high) {
segmentArray[position] = value;
} else {
int mid = (low + high) >> 1;
if (index <= mid) {
update(position << 1, low, mid, index, value);
} else {
update((position << 1) + 1, mid + 1, high, index, value);
}
segmentArray[position] = function.apply((T) segmentArray[position << 1], (T) segmentArray[(position << 1) + 1]);
}
}
}
}
class SystemOfDisjointSets {
private int[] rank;
private int[] dsu;
SystemOfDisjointSets(int size) {
this.rank = new int[size];
this.dsu = new int[size];
}
protected void makeSet(int value) {
dsu[value] = value;
rank[value] = 0;
}
protected int findSet(int value) {
if (value == dsu[value]) {
return value;
}
return dsu[value] = findSet(dsu[value]);
}
protected boolean mergeSets(int first, int second) {
first = findSet(first);
second = findSet(second);
if (first != second) {
if (rank[first] < rank[second]) {
int number = first;
first = second;
second = number;
}
dsu[second] = first;
if (rank[first] == rank[second]) {
rank[first]++;
}
return true;
}
return false;
}
}
interface Array {
void useArray(int[] a);
}
interface Method<T> {
void use(T value);
}
class BigNumber {
private static int size = 100;
private static int[] pr = new int[size];
private static int[][] r = new int[size][size];
private int[] a = new int[size];
static void init() {
for (int x = 1000_000_000, i = 0; i < size; ++x)
if (BigInteger.valueOf(x).isProbablePrime(100))
pr[i++] = x;
for (int i = 0; i < size; ++i)
for (int j = i + 1; j < size; ++j)
r[i][j] = BigInteger.valueOf(pr[i]).modInverse(
BigInteger.valueOf(pr[j])).intValue();
}
public BigNumber() {
}
public BigNumber(int n) {
for (int i = 0; i < size; ++i)
a[i] = n % pr[i];
}
public BigNumber(BigInteger n) {
for (int i = 0; i < size; ++i)
a[i] = n.mod(BigInteger.valueOf(pr[i])).intValue();
}
public BigNumber add(BigNumber n) {
BigNumber result = new BigNumber();
for (int i = 0; i < size; ++i)
result.a[i] = (a[i] + n.a[i]) % pr[i];
return result;
}
public BigNumber subtract(BigNumber n) {
BigNumber result = new BigNumber();
for (int i = 0; i < size; ++i)
result.a[i] = (a[i] - n.a[i] + pr[i]) % pr[i];
return result;
}
public BigNumber multiply(BigNumber n) {
BigNumber result = new BigNumber();
for (int i = 0; i < size; ++i)
result.a[i] = (int) (((long) a[i] * n.a[i]) % pr[i]);
return result;
}
public BigInteger bigIntegerValue(boolean can_be_negative) {
BigInteger result = BigInteger.ZERO,
mult = BigInteger.ONE;
int[] x = new int[size];
for (int i = 0; i < size; ++i) {
x[i] = a[i];
for (int j = 0; j < i; ++j) {
long cur = (long) (x[i] - x[j]) * r[j][i];
x[i] = (int) ((cur % pr[i] + pr[i]) % pr[i]);
}
result = result.add(mult.multiply(BigInteger.valueOf(x[i])));
mult = mult.multiply(BigInteger.valueOf(pr[i]));
}
if (can_be_negative)
if (result.compareTo(mult.shiftRight(1)) >= 0)
result = result.subtract(mult);
return result;
}
}
class FastSort {
enum TypeSort {
RANDOM,
SHELL,
HEAP,
MERGE,
STRAIGHT_MERGE,
INSERTION
}
protected static int[] sort(int[] array, TypeSort typeSort) {
sort(array, typeSort, array.length);
return array;
}
protected static int[] sortClone(int[] array, TypeSort typeSort) {
int[] base = array.clone();
sort(base, typeSort, array.length);
return base;
}
private static void sort(int[] array, TypeSort typeSort, int length) {
if (typeSort == null || typeSort == TypeSort.RANDOM) {
Random random = new Random();
int index = random.nextInt(4) + 1;
typeSort = TypeSort.values()[index];
}
switch (typeSort) {
case SHELL:
ShellSort(array);
break;
case HEAP:
HeapSort(array);
break;
case MERGE:
MergeSort(array, 0, length - 1);
break;
case STRAIGHT_MERGE:
straightMergeSort(array, length);
break;
case INSERTION:
insertionSort(array);
break;
}
}
private static void straightMergeSort(int[] array, int size) {
if (size == 0) {
return;
}
int length = (size >> 1) + ((size % 2) == 0 ? 0 : 1);
Integer[][] ZeroBuffer = new Integer[length + length % 2][2];
Integer[][] FirstBuffer = new Integer[0][0];
for (int index = 0; index < length; index++) {
int ArrayIndex = index << 1;
int NextArrayIndex = (index << 1) + 1;
if (NextArrayIndex < size) {
if (array[ArrayIndex] > array[NextArrayIndex]) {
ZeroBuffer[index][0] = array[NextArrayIndex];
ZeroBuffer[index][1] = array[ArrayIndex];
} else {
ZeroBuffer[index][0] = array[ArrayIndex];
ZeroBuffer[index][1] = array[NextArrayIndex];
}
} else {
ZeroBuffer[index][0] = array[ArrayIndex];
}
}
boolean position = false;
int pointer0, pointer, pointer1, number = 4, NewPointer, count;
Integer[][] NewBuffer;
Integer[][] OldBuffer;
length = (size >> 2) + ((size % 4) == 0 ? 0 : 1);
while (true) {
pointer0 = 0;
count = (number >> 1) - 1;
if (!position) {
FirstBuffer = new Integer[length + length % 2][number];
NewBuffer = FirstBuffer;
OldBuffer = ZeroBuffer;
} else {
ZeroBuffer = new Integer[length + length % 2][number];
NewBuffer = ZeroBuffer;
OldBuffer = FirstBuffer;
}
for (int i = 0; i < length; i++) {
pointer = 0;
pointer1 = 0;
NewPointer = pointer0 + 1;
if (length == 1) {
for (int g = 0; g < size; g++) {
if (pointer > count || OldBuffer[pointer0][pointer] == null) {
array[g] = OldBuffer[NewPointer][pointer1];
pointer1++;
} else if (pointer1 > count || OldBuffer[NewPointer][pointer1] == null) {
if (OldBuffer[pointer0][pointer] == null) {
continue;
}
array[g] = OldBuffer[pointer0][pointer];
pointer++;
} else if (OldBuffer[pointer0][pointer] >= OldBuffer[NewPointer][pointer1]) {
array[g] = OldBuffer[NewPointer][pointer1];
pointer1++;
} else {
array[g] = OldBuffer[pointer0][pointer];
pointer++;
}
}
return;
}
for (int g = 0; g < number; g++) {
if (pointer > count || OldBuffer[pointer0][pointer] == null) {
if (OldBuffer[NewPointer][pointer1] == null) {
continue;
}
NewBuffer[i][g] = OldBuffer[NewPointer][pointer1];
pointer1++;
} else if (pointer1 > count || OldBuffer[NewPointer][pointer1] == null) {
if (OldBuffer[pointer0][pointer] == null) {
continue;
}
NewBuffer[i][g] = OldBuffer[pointer0][pointer];
pointer++;
} else if (OldBuffer[pointer0][pointer] >= OldBuffer[NewPointer][pointer1]) {
NewBuffer[i][g] = OldBuffer[NewPointer][pointer1];
pointer1++;
} else {
NewBuffer[i][g] = OldBuffer[pointer0][pointer];
pointer++;
}
}
pointer0 += 2;
}
position = !position;
length = (length >> 1) + length % 2;
number <<= 1;
}
}
private static void ShellSort(int[] array) {
int j;
for (int gap = (array.length >> 1); gap > 0; gap >>= 1) {
for (int i = gap; i < array.length; i++) {
int temp = array[i];
for (j = i; j >= gap && array[j - gap] > temp; j -= gap) {
array[j] = array[j - gap];
}
array[j] = temp;
}
}
}
private static void HeapSort(int[] array) {
for (int i = (array.length >> 1) - 1; i >= 0; i--)
shiftDown(array, i, array.length);
for (int i = array.length - 1; i > 0; i--) {
swap(array, 0, i);
shiftDown(array, 0, i);
}
}
private static void shiftDown(int[] array, int i, int n) {
int child;
int tmp;
for (tmp = array[i]; leftChild(i) < n; i = child) {
child = leftChild(i);
if (child != n - 1 && (array[child] < array[child + 1]))
child++;
if (tmp < array[child])
array[i] = array[child];
else
break;
}
array[i] = tmp;
}
private static int leftChild(int i) {
return (i << 1) + 1;
}
private static void swap(int[] array, int i, int j) {
int temp = array[i];
array[i] = array[j];
array[j] = temp;
}
private static void MergeSort(int[] array, int low, int high) {
if (low < high) {
int mid = (low + high) >> 1;
MergeSort(array, low, mid);
MergeSort(array, mid + 1, high);
merge(array, low, mid, high);
}
}
private static void merge(int[] array, int low, int mid, int high) {
int n = high - low + 1;
int[] Temp = new int[n];
int i = low, j = mid + 1;
int k = 0;
while (i <= mid || j <= high) {
if (i > mid)
Temp[k++] = array[j++];
else if (j > high)
Temp[k++] = array[i++];
else if (array[i] < array[j])
Temp[k++] = array[i++];
else
Temp[k++] = array[j++];
}
for (j = 0; j < n; j++)
array[low + j] = Temp[j];
}
private static void insertionSort(int[] elements) {
for (int i = 1; i < elements.length; i++) {
int key = elements[i];
int j = i - 1;
while (j >= 0 && key < elements[j]) {
elements[j + 1] = elements[j];
j--;
}
elements[j + 1] = key;
}
}
}
class IO {
private static BufferedReader read;
private static boolean fileInput = false;
private static BufferedWriter write;
private static boolean fileOutput = false;
public static void setFileInput(boolean fileInput) {
IO.fileInput = fileInput;
}
public static void setFileOutput(boolean fileOutput) {
IO.fileOutput = fileOutput;
}
private static void startInput() {
try {
read = new BufferedReader(fileInput ? new FileReader("input.txt") : new InputStreamReader(System.in));
} catch (Exception error) {
}
}
private static void startOutput() {
try {
write = new BufferedWriter(fileOutput ? new FileWriter("output.txt") : new OutputStreamWriter(System.out));
} catch (Exception error) {
}
}
protected static int readInt() throws IOException {
if (read == null) {
startInput();
}
return Integer.parseInt(read.readLine());
}
protected static long readLong() throws IOException {
if (read == null) {
startInput();
}
return Long.parseLong(read.readLine());
}
protected static String readString() throws IOException {
if (read == null) {
startInput();
}
return read.readLine();
}
protected static int[] readArrayInt(String split) throws IOException {
if (read == null) {
startInput();
}
return Arrays.stream(read.readLine().split(split)).mapToInt(Integer::parseInt).toArray();
}
protected static long[] readArrayLong(String split) throws IOException {
if (read == null) {
startInput();
}
return Arrays.stream(read.readLine().split(split)).mapToLong(Long::parseLong).toArray();
}
protected static String[] readArrayString(String split) throws IOException {
if (read == null) {
startInput();
}
return read.readLine().split(split);
}
protected static void writeArray(int[] array, String split, boolean enter) {
if (write == null) {
startOutput();
}
try {
int length = array.length;
for (int index = 0; index < length; index++) {
write.write(Integer.toString(array[index]));
if (index + 1 != length) {
write.write(split);
}
}
if (enter) {
writeEnter();
}
} catch (Exception error) {
}
}
protected static void writeArray(Integer[] array, String split, boolean enter) {
if (write == null) {
startOutput();
}
try {
int length = array.length;
for (int index = 0; index < length; index++) {
write.write(Integer.toString(array[index]));
if (index + 1 != length) {
write.write(split);
}
}
if (enter) {
writeEnter();
}
} catch (Exception error) {
}
}
protected static void writeArray(long[] array, String split, boolean enter) {
if (write == null) {
startOutput();
}
try {
int length = array.length;
for (int index = 0; index < length; index++) {
write.write(Long.toString(array[index]));
if (index + 1 != length) {
write.write(split);
}
}
if (enter) {
writeEnter();
}
} catch (Exception error) {
}
}
protected static void writeArray(Long[] array, String split, boolean enter) {
if (write == null) {
startOutput();
}
try {
int length = array.length;
for (int index = 0; index < length; index++) {
write.write(Long.toString(array[index]));
if (index + 1 != length) {
write.write(split);
}
}
if (enter) {
writeEnter();
}
} catch (Exception error) {
}
}
public static void writeArray(String[] array, String split, boolean enter) {
if (write == null) {
startOutput();
}
try {
write.write(String.join(split, array));
if (enter) {
writeEnter();
}
} catch (Exception ignored) {
}
}
public static void writeArray(char[] array, String split, boolean enter) {
if (write == null) {
startOutput();
}
try {
int length = array.length;
for (int index = 0; index < length; index++) {
write.write(array[index]);
if (index + 1 != length) {
write.write(split);
}
}
if (enter) {
writeEnter();
}
} catch (Exception ignored) {
}
}
protected static void writeArray(boolean[] array, String split, boolean enter) {
if (write == null) {
startOutput();
}
try {
int length = array.length;
for (int index = 0; index < length; index++) {
write.write(Boolean.toString(array[index]));
if (index + 1 != length) {
write.write(split);
}
}
if (enter) {
writeEnter();
}
} catch (Exception ignored) {
}
}
protected static void writeInt(int number, String end) {
if (write == null) {
startOutput();
}
try {
write.write(Integer.toString(number));
write.write(end);
} catch (Exception ignored) {
}
}
protected static void writeInt(Integer number, String end) {
if (write == null) {
startOutput();
}
try {
write.write(Integer.toString(number));
write.write(end);
} catch (Exception ignored) {
}
}
protected static void writeLong(long number, String end) {
if (write == null) {
startOutput();
}
try {
write.write(Long.toString(number));
write.write(end);
} catch (Exception ignored) {
}
}
protected static void writeLong(Long number, String end) {
if (write == null) {
startOutput();
}
try {
write.write(Long.toString(number));
write.write(end);
} catch (Exception ignored) {
}
}
protected static void writeString(String word, String end) {
if (write == null) {
startOutput();
}
try {
write.write(word);
write.write(end);
} catch (Exception ignored) {
}
}
protected static void writeBoolean(boolean value, String end) {
if (write == null) {
startOutput();
}
try {
write.write(value ? "true" : "false");
write.write(end);
} catch (Exception ignored) {
}
}
protected static void writeBoolean(Boolean value, String end) {
if (write == null) {
startOutput();
}
try {
write.write(value ? "true" : "false");
write.write(end);
} catch (Exception ignored) {
}
}
protected static void writeChar(char word, String end) {
if (write == null) {
startOutput();
}
try {
write.write(word);
write.write(end);
} catch (Exception ignored) {
}
}
protected static void writeChar(Character word, String end) {
if (write == null) {
startOutput();
}
try {
write.write(word);
write.write(end);
} catch (Exception ignored) {
}
}
protected static void writeEnter() {
if (write == null) {
startOutput();
}
try {
write.newLine();
} catch (Exception ignored) {
}
}
protected static void print(boolean exit) throws IOException {
if (exit) {
print();
} else {
write.flush();
}
}
protected static void print() throws IOException {
if (write == null) {
return;
}
write.flush();
if (read != null) {
read.close();
}
write.close();
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
5d2474b5443d7e5ecdb96403265a519d
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.Scanner;
public class Round703_1 {
public static void main(String[] args) {
Scanner o=new Scanner(System.in);
int t=o.nextInt();
while(t>0) {
int n=o.nextInt();
int ar[]=new int[n];
long s=0;
for(int i=0;i<n;i++) {
ar[i]=o.nextInt();
}
long prefix[]=new long[n];
prefix[0]=ar[0];
for(int i=1;i<n;i++) {
prefix[i]=prefix[i-1]+ar[i];
}
boolean a=true;
for(int i=0;i<n;i++) {
long v=i*(i+1);
if(prefix[i]<v/2) {
a=false;
break;
}
}
if(a)
System.out.println("YES");
else
System.out.println("NO");
t--;
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
0ec7ce840f8fb08518536dd8a0eb2e6e
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
/*==============================================
Name : Shadman Shariar ||
Email : shadman.shariar@northsouth.edu ||
University : North South University (NSU) ||
Facebook : shadman.shahriar.007 ||
==============================================*/
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int t = input.nextInt();
for (int i = 0; i < t; i++) {
int n = input.nextInt();
int [] arr = new int [n];
for (int j = 0; j < arr.length; j++) {
arr[j] = input.nextInt();
}
long sum =0 ;
boolean bool = true ;
for (int j = 0; j < arr.length; j++) {
if (arr[j] >= j ) {
sum += (arr[j] - j) ;
}
else {
sum -= (j-arr[j]);
if (sum <0) {
bool = false ;
break;
}
}
}
if (bool) {
System.out.println("YES");
}
else {
System.out.println("NO");
}
}
input.close();
System.exit(0);
}
public static int fibon(int n) {
if (n <= 1) {
return n;
}
int[] array = new int[n + 1];
array[0] = 0;
array[1] = 1;
for (int i = 2; i <= n; i++) {
array[i] = array[i - 2] + array[i - 1];
}
return array[n];
}
public static int sumofdigits(int n) {
int sum = 0;
while (n != 0) {
sum = sum + n % 10;
n = n / 10;
}
return sum;
}
public static int reversedigits(int num) {
int rev_num = 0;
while (num > 0) {
rev_num = rev_num * 10 + num % 10;
num = num / 10;
}
return rev_num;
}
public static int binarysearch(int arr[], int l, int r, int x) {
if (r >= l) {
int mid = l + (r - l) / 2;
if (arr[mid] == x)
return mid;
if (arr[mid] > x)
return binarysearch(arr, l, mid - 1, x);
return binarysearch(arr, mid + 1, r, x);
}
return -1;
}
public static long gcd(long a, long b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
public static long lcm(long a, long b) {
return (a / gcd(a, b)) * b;
}
public static void rangeofprimenumber(int a, int b) {
int i, j, flag;
for (i = a; i <= b; i++) {
if (i == 1 || i == 0)
continue;
flag = 1;
for (j = 2; j <= i / 2; ++j) {
if (i % j == 0) {
flag = 0;
break;
}
}
if (flag == 1)
System.out.println(i);
}
}
public static boolean isprime(long n) {
if (n <= 1)
return false;
else if (n == 2)
return true;
else if (n % 2 == 0)
return false;
for (long i = 3; i <= Math.sqrt(n); i += 2) {
if (n % i == 0)
return false;
}
return true;
}
public static int factorial(int n) {
return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
public static int[] reversearrayinrange(int arr[], int start, int end) {
int temp;
while (start < end) {
temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
}
return arr;
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
64384435f63cb5e727dc3a2dbe401138
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
public class Solution{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int test = scan.nextInt();
while(test-- > 0){
long n = scan.nextLong();
long[] arr = new long[(int)n];
for(int i=0;i<n;i++){
arr[i] = scan.nextInt();
}
int k = 0;
for(int i=0;i<n-1;i++){
if(arr[i] > i ){
arr[i+1] += arr[i] - i;
arr[i] -= arr[i] -i;
}
}
boolean bool = false;
for(int i=0;i<n-1;i++){
if(arr[i] >= arr[i+1] ){
bool = true;
break;
}
}
if(!bool) System.out.println("YES");
else System.out.println("NO");
}
}
}
/*
6
2
1 2
2
1 0
3
4 4 4
2
0 0
3
0 1 0
4
1000000000 1000000000 1000000000 1000000000*/
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
9fb382c103adac389f0b417b07aa077e
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.io.PrintWriter;
import java.util.Scanner;
/**
* Created by Wilson on
* Feb. 18, 2021
*/
public class WilsonStack {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int t = sc.nextInt();
int n,a,b,c;
boolean can;
long sum;
while (t-->0){
n = sc.nextInt();
sum =0;
can = true;
for(int i=1; i<=n; i++){
sum += sc.nextLong();
b = i*(i-1)/2;
if(can && sum < b){
can = false;
}
}
if(can)
System.out.println("YES");
else
System.out.println("No");
}
out.close();
sc.close();
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
f2aac690d4302cffb820117a79f389f4
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
import java.math.*;
import java.io.*;
// Arrays.sort();
//char[] a=fs.next().toCharArray();
public class A_Shifting_Stacks {
public static void main(String[] args) {
FastScanner fs = new FastScanner();
int T = fs.nextInt();
outer: while (T-- > 0) {
int n = fs.nextInt();
int arr[] = fs.readArray(n);
long sum = 0;
for (int i = 0; i < n - 1; i++) {
sum += arr[i] - i;
if (sum < 0) {
System.out.println("NO");
continue outer;
}
}
sum += arr[n - 1];
if (sum > n - 2) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
static void sort(int[] a) {
ArrayList<Integer> l = new ArrayList<>();
for (int i : a)
l.add(i);
Collections.sort(l);
for (int i = 0; i < a.length; i++)
a[i] = l.get(i);
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
StringBuilder nextsb() {
StringBuilder sb = new StringBuilder(next());
return sb;
}
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
}
return st.nextToken();
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
a6833b085c3251d88849bc36d942b7e8
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
public class Main{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader sc = new FastReader();
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
long sum = 0;
long b = 0;
String s = "YES";
for(int i = 0; i<n; i++){
int m = sc.nextInt();
sum+=m;
b+=i;
if(sum<b){
s = "NO";
}
}
System.out.println(s);
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
5f35852973094a3a035b8a57073a498f
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.Scanner;
import java.math.BigDecimal;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
long t=sc.nextLong();
while(t--!=0) {
int n=sc.nextInt();
long sum=0;
int f=0;
for(int i=0;i<n;i++) {
sum+=sc.nextLong();
if(sum<i*(i+1)/2)f=1;
}
if(f==1)System.out.println("NO");
else System.out.println("YES");
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
63c747da6d76e1511d536c05b5f44baf
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class A703 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
loop1: for (int ff = 0; ff < t; ff++) {
long n = Long.parseLong(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());
long sum = 0;
long req = 0;
for (int i = 0; i < n; i++) {
sum += Long.parseLong(st.nextToken());
req += i;
if(sum < req){
System.out.println("NO");
continue loop1;
}
}
System.out.println("YES");
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 11
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
1d0675ca0bbf8eacbaebd810614b7eb6
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static java.lang.System.*;
import static java.lang.System.out;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Arrays.sort;
import static java.util.Collections.sort;
public class Solution {
private final static FastScanner scanner = new FastScanner();
private final static int mod = (int) 1e9+7;
private final static int max_value = Integer.MAX_VALUE;
private final static int min_value = Integer.MIN_VALUE;
private final static String endl = "\n";
private static void solve() {
int n = ii();
var a = readArrayInt(n);
long sum = 0;
for (int i = 0; i<n; i++) {
sum+=a[i];
if (sum<i*(i+1)/2) {
no();
return;
}
}
yes();
}
public static void main(String[] args) {
int t = ii();
while (t-->0) {
solve();
}
}
private static void swap(int[] a, int i, int j) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
private static void swap(int[] a, int[] b, int i) {
int temp = a[i];
a[i] = b[i];
b[i] = temp;
}
private static int[] reverse(int[] a) {
int[] b = new int[a.length];
int k = 0;
for (int i = a.length-1; i>=0; i--) {
b[k++] = a[i];
}
return b;
}
private static int[] readArrayInt(int n) {
return scanner.readArray(n);
}
private static String[] readArrayString(int n) {
return IntStream.range(0, n).mapToObj(i -> s()).toArray(String[]::new);
}
private static int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
private static int ii() {
return scanner.nextInt();
}
private static long l() {
return scanner.nextLong();
}
private static double d() {
return scanner.nextDouble();
}
private static String s() {
return scanner.next();
}
private static int toInt(String s) {
return Integer.parseInt(s);
}
private static ArrayList<Integer> list() {
return new ArrayList<>();
}
private static HashSet<Integer> set() {
return new HashSet<>();
}
private static HashMap<Integer, Integer> map() {
return new HashMap<>();
}
private static int toInt(char c) {
return Integer.parseInt(c+"");
}
private static<K> void println(K a) {
print(a+endl);
}
private static<K> void print(K a) {
out.print(a);
}
private static void yes() {
println("YES");
}
private static void no() {
println("NO");
}
private static int max_a(int[] a) {
int max = a[0];
for (int j : a) {
if (j > max) {
max = j;
}
}
return max;
}
private static int min_a(int[] a) {
int min = a[0];
for (int j : a) {
if (j < min) {
min = j;
}
}
return min;
}
private static long sum(int[] a) {
return stream(a).asLongStream().sum();
}
private static void println() {
out.println();
}
private static void printArray(int[] a) {
stream(a).mapToObj(i -> i + " ").forEachOrdered(Solution::print);
println();
}
private static<K> void printArray(K[] a) {
stream(a).map(k -> k + " ").forEachOrdered(Solution::print);
println();
}
private static int reverseInteger(int k) {
String a = k+"", res = "";
for (int i = a.length()-1; i>=0; i--) {
res+=a.charAt(i);
}
return toInt(res);
}
private static long phi(long n) {
long result = n;
for (long i=2; i*i<=n; i++)
if (n % i == 0) {
while (n % i == 0)
n /= i;
result -= result / i;
}
if (n > 1)
result -= result / n;
return result;
}
private static int pow(int a, int n) {
if (n == 0)
return 1;
if (n % 2 == 1)
return pow(a, n-1) * a;
else {
int b = pow (a, n/2);
return b * b;
}
}
private static boolean isPrimeLong(long n) {
BigInteger a = BigInteger.valueOf(n);
return a.isProbablePrime(10);
}
private static boolean isPrime(int n) {
return IntStream.iterate(2, i -> i * i <= n, i -> i + 1).noneMatch(i -> n % i == 0);
}
private static List<Integer> primes(int N) {
int[] lp = new int[N+1];
List<Integer> pr = new ArrayList<>();
for (int i=2; i<=N; ++i) {
if (lp[i] == 0) {
lp[i] = i;
pr.add(i);
}
for (int j = 0; j<pr.size() && pr.get(j)<=lp[i] && i*pr.get(j)<=N; ++j)
lp[i * pr.get(j)] = pr.get(j);
}
return pr;
}
private static Set<Integer> toSet(int[] a) {
return stream(a).boxed().collect(Collectors.toSet());
}
private static int linearSearch(int[] a, int key) {
return IntStream.range(0, a.length).filter(i -> a[i] == key).findFirst().orElse(-1);
}
private static<K> int linearSearch(K[] a, K key) {
return IntStream.range(0, a.length).filter(i -> a[i].equals(key)).findFirst().orElse(-1);
}
static int upper_bound(int[] arr, int key) {
int index = binarySearch(arr, key);
int n = arr.length;
if (index < 0) {
int upperBound = abs(index) - 1;
if (upperBound < n)
return upperBound;
else return -1;
}
else {
while (index < n) {
if (arr[index] == key)
index++;
else {
return index;
}
}
return -1;
}
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
public static void psort(int[] arr, int n) {
int min = min_a(arr);
int max = max_a(arr);
int range = max-min+1, i, j, index = 0;
int[] count = new int[range];
for(i = 0; i<n; i++)
count[arr[i] - min]++;
for(j = 0; j<range; j++)
while(count[j]-->0)
arr[index++]=j+min;
}
private static void csort(int[] a, int n) {
int max = max_a(a);
int min = min_a(a);
int range = max - min + 1;
int[] count = new int[range];
int[] output = new int[n];
for (int i = 0; i < n; i++) {
count[a[i] - min]++;
}
for (int i = 1; i < range; i++) {
count[i] += count[i - 1];
}
for (int i = n - 1; i >= 0; i--) {
output[count[a[i] - min] - 1] = a[i];
count[a[i] - min]--;
}
arraycopy(output, 0, a, 0, n);
}
private static void csort(char[] arr) {
int n = arr.length;
char[] output = new char[n];
int[] count = new int[256];
for (int i = 0; i < 256; ++i)
count[i] = 0;
for (char c : arr) ++count[c];
for (int i = 1; i <= 255; ++i)
count[i] += count[i - 1];
for (int i = n - 1; i >= 0; i--) {
output[count[arr[i]] - 1] = arr[i];
--count[arr[i]];
}
arraycopy(output, 0, arr, 0, n);
}
static class Pair implements Comparable<Pair> {
String key;
Integer count = 0;
public Pair(String key, Integer count) {
this.key = key;
this.count = count;
}
@Override
public int compareTo(Pair pair) {
return count.compareTo(pair.count);
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 17
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
233d23c0d0ed67d8095be86cae702fce
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0)
{
int n = sc.nextInt();
long ar[] = new long[n];
for (int i = 0; i <n; i++) {
ar[i]=sc.nextInt();
}
int c=0;
if(n==1)
{
System.out.println("YES");
}
else
{
long s=0;
long s2=ar[0];
for (int i = 1; i <n; i++) {
s2+=ar[i];
s= (i*(i+1))/2;
if(s2<s)
{
c=1;
System.out.println("NO");
break;
}
}
if(c==0)
System.out.println("YES");
}
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 17
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
9594899a5580f7f3a6b05b7b3148f16f
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
MyScanner read = new MyScanner();
int testCases = read.nextInt();
for (int i = 0; i < testCases; i++) {
int n = read.nextInt();
String[] boxes = read.nextLine().split(" ");
calculate(n, boxes);
}
}
public static void calculate(int boxes, String[] c) {
long[] height = new long[c.length];
int left = 0;
for (int i = 0; i < c.length; i++) {
height[i] = Long.parseLong(c[i]);
}
long total = 0;
for (int i = 0; i < height.length; i++) {
if (height[i] > i) {
total += height[i] - i;
height[i] = i;
}
else{
if(height[i] + total < i) {
System.out.println("NO");
return;
}
total -= ((long)i - height[i]);
}
}
// System.out.println(total);
System.out.println("YES");
}
}
//--------------------------------------------------------
class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
//--------------------------------------------------------
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 17
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
00c68d463c06bd9dcc2b2f85cd8d4c05
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.Scanner;
public class Shifting_Stacks {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int i = 0; i < t; i++){
boolean flag = true;
int n = sc.nextInt();
long[] arr = new long[n];
int[] ex = new int[n];
for (int j = 0; j < n; j++){
arr[j] = sc.nextInt();
ex[j] = j;
}
for (int j = 1; j < n; j++){
arr[j] += arr[j - 1];
ex[j] += ex[j - 1];
}
for (int j = 1; j < n; j++){
if (arr[j] < ex[j]){
System.out.println("NO");
flag = false;
break;
}
}
if (flag) {
System.out.println("YES");
}
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 17
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
0cfa41ebfcf1ab91e0bf25188de951ab
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
// package practise;
import java.io.*;
import java.util.*;
public class B {
static int dp[][];
static Reader sc;
static PrintWriter w;
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
sc = new Reader();
w = new PrintWriter(System.out);
int t=sc.nextInt();
while(t-->0) {
solve();
}
w.close();
}
static void solve() throws IOException {
int n=sc.nextInt();
int a[]= new int [n ];
for(int i=0;i<n;i++)a[i]=sc.nextInt();
long cur=0;
for(int i=0;i<n;i++) {
cur+=1L*a[i];
cur-=1L*i;
if(cur<0L) {
w.println("NO");
return;
}
}
w.println("YES");
}
static int solve(int i,int j,int g[],int b[]) {
if(i==b.length || j==g.length)return 0;
if(dp[i][j]!=-1)return dp[i][j];
// System.out.println(b[i]+" "+g[j]);
if(Math.abs(b[i]-g[j])<=1) {
return dp[i][j]=1+solve(i+1,j+1,g,b);
}else {
return dp[i][j]=Math.max(solve(i,j+1,g,b), solve(i+1,j,g,b));
}
}
static long fact(long n,long mod) {
if(n==0 || n==1)return 1;
return ((n %mod)* (fact(n-1,mod)%mod)%mod);
}
static boolean isSorted(int a[],int lo,int hi) {
//reverse sorted
if(lo==hi)return true;
for(int i=lo;i<=hi-1;i++) {
if(a[i]<a[i+1]) {
return false;
}
}
return true;
}
static class FenwickTree{
int tree[];
void contructFenwickTree(int ar[],int n) {
tree= new int[n+1];
for(int i=0;i<ar.length;i++) {
update(i,ar[i],n);
}
}
void update(int i,int delta,int n) { //delta means newValue - preValue.
//i is index of array.
i++;
while(i<=n) {
tree[i]+=delta;
i=i+Integer.lowestOneBit(i);
}
}
int getSum(int i ){
int sum=0;
i++;
while(i>0) {
sum+=tree[i];
i-=Integer.lowestOneBit(i);
}
return sum;
}
int rangeOfSum(int i,int j) {
return getSum(j)-getSum(i-1);
}
}
// of a given number n
static List<Integer> primeFactors(int n)
{
List<Integer> prime= new ArrayList<Integer>();
// Print the number of 2s that divide n
while (n%2==0)
{
prime.add(2);
// System.out.print(2 + " ");
n /= 2;
}
// n must be odd at this point. So we can
// skip one element (Note i = i +2)
for (int i = 3; i <= Math.sqrt(n); i+= 2)
{
// While i divides n, print i and divide n
while (n%i == 0)
{
prime.add(i);
//System.out.print(i + " ");
n /= i;
}
}
// This condition is to handle the case when
// n is a prime number greater than 2
if (n > 2 ) prime.add(n);
return prime;
// System.out.print(n);
}
static ArrayList<Integer> findDiv(int N)
{
//gens all divisors of N
ArrayList<Integer> ls1 = new ArrayList<Integer>();
ArrayList<Integer> ls2 = new ArrayList<Integer>();
for(int i=1; i <= (int)(Math.sqrt(N)+0.00000001); i++)
if(N%i == 0)
{
ls1.add(i);
ls2.add(N/i);
}
Collections.reverse(ls2);
for(int b: ls2)
if(b != ls1.get(ls1.size()-1))
ls1.add(b);
return ls1;
}
static void sort(int[] arr)
{
//because Arrays.sort() uses quicksort which is dumb
//Collections.sort() uses merge sort
ArrayList<Integer> ls = new ArrayList<Integer>();
for(int x: arr)
ls.add(x);
Collections.sort(ls);
for(int i=0; i < arr.length; i++)
arr[i] = ls.get(i);
}
static void sort(long[] arr)
{
//because Arrays.sort() uses quicksort which is dumb
//Collections.sort() uses merge sort
ArrayList<Long> ls = new ArrayList<>();
for(long x: arr)
ls.add(x);
Collections.sort(ls);
for(int i=0; i < arr.length; i++)
arr[i] = ls.get(i);
}
static long power(long x, long y, long p)
{
//0^0 = 1
long res = 1L;
x = x%p;
while(y > 0)
{
if((y&1)==1)
res = (res*x)%p;
y >>= 1;
x = (x*x)%p;
}
return res;
}
static long power(long x, long y)
{
long res = 1; // Initialize result
while (y > 0)
{
// If y is odd, multiply x with result
if ((y & 1) != 0)
res = res * x;
// y must be even now
y = y >> 1; // y = y/2
x = x * x; // Change x to x^2
}
return res;
}
static class Reader // here reader class is defined.
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 17
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
7d9aa36d64ce51879d583e0a4f46c2c9
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
// package practise;
import java.io.*;
import java.util.*;
public class B {
static int dp[][];
static Reader sc;
static PrintWriter w;
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
sc = new Reader();
w = new PrintWriter(System.out);
int t=sc.nextInt();
while(t-->0) {
solve();
}
w.close();
}
static void solve() throws IOException {
int n=sc.nextInt();
int a[]= new int [n ];
for(int i=0;i<n;i++)a[i]=sc.nextInt();
long cur=0;
for(int i=0;i<n;i++) {
cur+=1L*a[i];
cur-=1L*i;
if(cur<0L) {
w.println("NO");
return;
}
}
w.println("YES");
}
static int solve(int i,int j,int g[],int b[]) {
if(i==b.length || j==g.length)return 0;
if(dp[i][j]!=-1)return dp[i][j];
// System.out.println(b[i]+" "+g[j]);
if(Math.abs(b[i]-g[j])<=1) {
return dp[i][j]=1+solve(i+1,j+1,g,b);
}else {
return dp[i][j]=Math.max(solve(i,j+1,g,b), solve(i+1,j,g,b));
}
}
static long fact(long n,long mod) {
if(n==0 || n==1)return 1;
return ((n %mod)* (fact(n-1,mod)%mod)%mod);
}
static boolean isSorted(int a[],int lo,int hi) {
//reverse sorted
if(lo==hi)return true;
for(int i=lo;i<=hi-1;i++) {
if(a[i]<a[i+1]) {
return false;
}
}
return true;
}
static class FenwickTree{
int tree[];
void contructFenwickTree(int ar[],int n) {
tree= new int[n+1];
for(int i=0;i<ar.length;i++) {
update(i,ar[i],n);
}
}
void update(int i,int delta,int n) { //delta means newValue - preValue.
//i is index of array.
i++;
while(i<=n) {
tree[i]+=delta;
i=i+Integer.lowestOneBit(i);
}
}
int getSum(int i ){
int sum=0;
i++;
while(i>0) {
sum+=tree[i];
i-=Integer.lowestOneBit(i);
}
return sum;
}
int rangeOfSum(int i,int j) {
return getSum(j)-getSum(i-1);
}
}
// of a given number n
static List<Integer> primeFactors(int n)
{
List<Integer> prime= new ArrayList<Integer>();
// Print the number of 2s that divide n
while (n%2==0)
{
prime.add(2);
// System.out.print(2 + " ");
n /= 2;
}
// n must be odd at this point. So we can
// skip one element (Note i = i +2)
for (int i = 3; i <= Math.sqrt(n); i+= 2)
{
// While i divides n, print i and divide n
while (n%i == 0)
{
prime.add(i);
//System.out.print(i + " ");
n /= i;
}
}
// This condition is to handle the case when
// n is a prime number greater than 2
if (n > 2 ) prime.add(n);
return prime;
// System.out.print(n);
}
static ArrayList<Integer> findDiv(int N)
{
//gens all divisors of N
ArrayList<Integer> ls1 = new ArrayList<Integer>();
ArrayList<Integer> ls2 = new ArrayList<Integer>();
for(int i=1; i <= (int)(Math.sqrt(N)+0.00000001); i++)
if(N%i == 0)
{
ls1.add(i);
ls2.add(N/i);
}
Collections.reverse(ls2);
for(int b: ls2)
if(b != ls1.get(ls1.size()-1))
ls1.add(b);
return ls1;
}
static void sort(int[] arr)
{
//because Arrays.sort() uses quicksort which is dumb
//Collections.sort() uses merge sort
ArrayList<Integer> ls = new ArrayList<Integer>();
for(int x: arr)
ls.add(x);
Collections.sort(ls);
for(int i=0; i < arr.length; i++)
arr[i] = ls.get(i);
}
static void sort(long[] arr)
{
//because Arrays.sort() uses quicksort which is dumb
//Collections.sort() uses merge sort
ArrayList<Long> ls = new ArrayList<>();
for(long x: arr)
ls.add(x);
Collections.sort(ls);
for(int i=0; i < arr.length; i++)
arr[i] = ls.get(i);
}
static long power(long x, long y, long p)
{
//0^0 = 1
long res = 1L;
x = x%p;
while(y > 0)
{
if((y&1)==1)
res = (res*x)%p;
y >>= 1;
x = (x*x)%p;
}
return res;
}
static long power(long x, long y)
{
long res = 1; // Initialize result
while (y > 0)
{
// If y is odd, multiply x with result
if ((y & 1) != 0)
res = res * x;
// y must be even now
y = y >> 1; // y = y/2
x = x * x; // Change x to x^2
}
return res;
}
static class Reader // here reader class is defined.
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 17
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
5a87e8bf83e7356e036e8e972e4eb247
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.io.*;
import java.util.*;
import static java.lang.Math.min;
import static java.lang.Math.max;
import static java.lang.Math.abs;
import static java.lang.Math.sqrt;
public class Main
{
private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws IOException {
int t = getSingle();
while(t --> 0) {
int n = getSingle();
if(solve(n)) {
System.out.println("YES");
}
else {
System.out.println("NO");
}
}
}
public static boolean solve(int n) throws IOException {
StringTokenizer st = new StringTokenizer(br.readLine());
long leftovers = 0;
for(int i = 0; i < n; ++i) {
long h = getNextInt(st) + leftovers;
//System.out.println(h);
if(h < i) {
return false;
}
else { // h + leftovers >= i
leftovers = h - i;
}
}
return true;
}
public static int[] getInts(int n, BufferedReader br, StringTokenizer st) {
int[] arr = new int[n];
for(int i=0; i < n; ++i) {
arr[i] = Integer.parseInt(st.nextToken());
}
return arr;
}
public static void printArr(int[] a) {
for(int i : a) {
System.out.print(i + " ");
}
System.out.println();
}
public static void sort(int[] a) {
ArrayList<Integer> ls = new ArrayList<Integer>();
for (int x : a) {
ls.add(x);
}
Collections.sort(ls);
for (int i = 0; i < a.length; i++) {
a[i] = ls.get(i);
}
}
public static long pow(long x, long y, long p) {
long res = 1L;
x = x%p;
while(y > 0)
{
if((y&1)==1)
res = (res*x)%p;
y >>= 1;
x = (x*x)%p;
}
return res;
}
public static long getSingleLong() throws IOException {
return Long.parseLong(br.readLine());
}
public static int getSingle() throws IOException {
return Integer.parseInt(br.readLine());
}
public static int getNextInt(StringTokenizer st) {
return Integer.parseInt(st.nextToken());
}
public static long getNextLong(StringTokenizer st) {
return Long.parseLong(st.nextToken());
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 17
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
4ac2193125281ea5d29421a9357ac793
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.Scanner;
public class ShiftingStacks {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0) {
int n = sc.nextInt();
long sum = 0;
boolean b = true;
for(int i = 1; i <= n; i++) {
sum += sc.nextInt();
if(sum < (i-1)*(i)/2) {
b = false;
}
}
if(b) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}
sc.close();
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
d8f4fd09670f64b28956f87e7771aacd
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.io.*;
import java.util.*;
public class Codeforces {
public void solve() {
FastScanner fs = new FastScanner();
StringBuilder print = new StringBuilder();
int t = fs.nextInt();
while (t-- > 0 ){
int n = fs.nextInt();
long[]ar = new long[n];
for(int i=0;i<n;i++)ar[i] = fs.nextLong();
long extra = 0;
boolean ok = true;
for(int i=0;i<n;i++){
if(ar[i] + extra < i ){
ok = false;
break;
}else if(ar[i] > i ){
extra += ar[i]-i;
}else{
extra = extra+ar[i]-i;
}
}
if(ok)print.append("Yes\n");
else print.append("No\n");
}
System.out.println(print);
}
public static void main(String[]args){
try{
new Codeforces().solve();
}catch (Exception e){
e.printStackTrace();
}
}
class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
b19b09041d8ce58bd2c502fda12cf690
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class forces{
public static void main(String[] args){
Scanner scn = new Scanner(System.in);
int t = scn.nextInt();
while(t-- > 0){
solve(scn);
}
}
public static void solve(Scanner scn){
long n = scn.nextLong();
ArrayList<Long> list = new ArrayList<>();
for(long i = 0; i < n; i++){
list.add(scn.nextLong());
}
long carry = 0;
for(long i = 0; i < n; i++){
if(list.get((int)i) < i){
if(i - list.get((int)i) > carry){
System.out.println("No");
return;
}
else{
carry -= (i - list.get((int)i));
}
}
else{
carry += (list.get((int)i) - i);
}
}
System.out.println("Yes");
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
01d883bc049fe847beb1bcb8a56db9ca
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
public class ShiftingBricks2 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String testCases = scanner.nextLine();
int t = Integer.parseInt(testCases);
String[][] array = new String[t][2];
for(int i=0 ; i < t ; i++) {
String columns = scanner.nextLine();
String bricks = scanner.nextLine();
array[i][0] = columns;
array[i][1] = bricks;
}
for (int i = 0; i < array.length; i++) {
solve(array[i][0],array[i][1]);
}
}
public static void solve(String columns, String bricks) {
int n = Integer.parseInt(columns);
String[] bricksNumbers = bricks.split(" ");
long sum = 0;
int stairSum = 0;
for (int j = 0; j < n; j++) {
stairSum +=j;
sum += Integer.parseInt(bricksNumbers[j]);
if (sum < stairSum) {
System.out.println("No");
return;
}
}
System.out.println("Yes");
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
2ba6f4c0404e0a03f472fa2a75a62463
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.Scanner;
public class NextContest1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
long[] arr = new long[n];
long sum = 0;
boolean res = true;
for (int i = 0; i < n; i++) {
arr[i] = sc.nextLong();
sum += arr[i];
long sum1 = (i) * (i + 1) / 2;
if (sum1 > sum) {
res = false;
}
}
if (res == false) {
System.out.println("NO");
} else if (n == 1 || n == 0) {
System.out.println("YES");
} else {
System.out.println("YES");
}
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
9b2b8b14cec6d63db817ab6c5062fed5
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.Scanner;
public class ShiftingStacks {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- >0){
int n = sc.nextInt();
boolean flag = true;
long sum1 = 0 ;
for(int i = 0 ;i < n ;i++){
long a = sc.nextLong();
long sum2 = i*(i+1)/2;
sum1 +=a;
if( sum1<sum2){
flag = false;
}
}
if(flag == false){
System.out.println("no");
}
else if(n==1||n==0){
System.out.println("yes");
}
else if(flag == true){
System.out.println("yes");
}
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
63898c8847c5a05555461d8d8c487c50
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
public class ShiftingStacks {
private static String solve(int n,ArrayList<Long> arr,ArrayList<Long> sum) {
if(n==1) return "YES";
//if(n==2&&sum<1)return "NO";
//if(n==2&&sum>1)return "YES";
for(int i=1;i<=n;i++) {
long minsum=((i)*(i-1))/2;
// System.out.println(minsum+" "+sum);
if(sum.get(i)<minsum) return "NO";
}
return "YES";
}
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Reader in=new Reader();
int t=in.nextInt();
for (int i = 0; i < t; i++) {
ArrayList<Long> sum=new ArrayList<>();
int n=in.nextInt();
ArrayList<Long> arr=new ArrayList<Long>();
long sum1=0;
sum.add((long) 0);
arr.add((long) 0);
for (int j = 1; j <=n; j++) {
long temp=in.nextLong();
sum1+=temp;
arr.add(temp);
sum.add(sum1);
}
System.out.println(solve(n, arr,sum));
}
}
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[120]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
8a59ba09da7270d4f33f0be4d89f591d
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
public class Main
{
static Scanner scanner=new Scanner(System.in);
static int testCases,n;
static void solve(long a[],int n){
boolean ok=true;
long need=0;
for(int i=0;i<n;i++){
if( need>a[i] ){
ok=false;
}
a[i+1]+=( a[i]-need );
need++;
}
if( ok ){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
public static void main(String[] args) {
testCases=scanner.nextInt();
for(int t=0;t<testCases;t++){
n=scanner.nextInt();
long a[]=new long[n+1];
for(int i=0;i<n;i++){
a[i]=scanner.nextLong();
}
solve(a,n);
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
fce69bf69c2788157507f51481ab776f
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
public class HelloWorld{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n =sc.nextInt();
int[] arr = new int[n];
long sum=0;
boolean flag = true;
for(int i=0;i<n;i++){
arr[i] = sc.nextInt();
}
for(int i=0;i<n;i++){
sum+=(long)arr[i];
int val= ((i)*(i+1))/2;
if(sum<val){
flag = false;
break;
}
}
if(flag)
System.out.println("Yes");
else
System.out.println("No");
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
f26e87728b5531d79c31c2f192790fb9
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
StringTokenizer st;
for(int t = 0; t < T; t++) {
int N = Integer.parseInt(br.readLine());
long[] blocks = new long[N];
st = new StringTokenizer(br.readLine());
for(int i = 0; i < N; i++)
blocks[i] = Integer.parseInt(st.nextToken());
if(N <= 1) {
System.out.println("YES");
continue;
}
boolean flag = true;
for(int i = 0; i < N; i++) {
if(i > 0) {
blocks[i] += blocks[i - 1] - i + 1;
blocks[i - 1] = i - 1;
if(blocks[i] <= blocks[i-1]) {
flag = false;
break;
}
}
}
if(flag)
System.out.println("YES");
else
System.out.println("NO");
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
479847dc088128af4778bd8ff36bef6a
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
public class Test{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0){
int n = sc.nextInt();
int[] arr = new int[n];
for(int i=0; i<n; i++)
arr[i] = sc.nextInt();
long sum = 0;
long time = 0;
boolean flag = true;
for(int i=0; i<n; i++){
time += i;
sum += arr[i];
if(sum < time){
flag = false;
}
}
if(flag){
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
0b99ab914a5652e3841dd372852d8888
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.io.*;
public class Code {
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException {
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException {
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException {
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException {
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null)
return;
din.close();
}
}
static Reader sc = new Reader();
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
public static void main(String args[]) throws IOException {
int t = inputInt();
while(t-->0){
int n = inputInt();
int[] a = new int[n];
for(int i = 0;i < n;i++){
a[i] = inputInt();
}
long extra = 0;
boolean check = true;
for(int i = 0;i < n;i++) {
if (a[i] > i) {
extra += a[i] - i;
} else {
int diff = i - a[i];
if(extra >= diff)
extra -= diff;
else{
check = false;
println("NO");
break;
}
}
}
if(check)
println("YES");
}
bw.flush();
bw.close();
}
public static int inputInt() throws IOException {
return sc.nextInt();
}
public static long inputLong() throws IOException {
return sc.nextLong();
}
public static double inputDouble() throws IOException {
return sc.nextDouble();
}
public static String inputString() throws IOException {
return sc.readLine();
}
public static void print(String a) throws IOException {
bw.write(a);
}
public static void printSp(String a) throws IOException {
bw.write(a + " ");
}
public static void println(String a) throws IOException {
bw.write(a + "\n");
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
ec0801fa876b9a51318f7427fb7fbf71
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class CF1486A_ShiftingStacks {
static class Scanner {
BufferedReader br;
StringTokenizer st;
public Scanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void solution() {
int n = scanner.nextInt();
long sum = 0, need = 0;
int[] arr = new int[n];
for(int i = 0; i < n; i++) {
arr[i] = scanner.nextInt();
}
for (int i = 0; i < n; ++i) {
need += i;
sum += arr[i];
if (sum < need) {
System.out.println("NO");
return;
}
}
System.out.println("YES");
}
static Scanner scanner;
public static void main(String[] args) {
// TODO Auto-generated method stub
scanner = new Scanner();
int te = scanner.nextInt();
while(te-- > 0)solution();
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
f9bbb52ab7a9ad9cab03de79d1ea0826
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.lang.*;
import java.util.*;
public class Arpit
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0)
{
int n = sc.nextInt();
long[] arr = new long[n+1];
for(int i=1;i<n+1;i++)
arr[i] = sc.nextInt();
long sum = 0;
int f = 0;
for(int i=1;i<n+1;i++)
{
sum += arr[i];
long k = (i * (i-1))/2;
if(sum<k)
{
f = 1;
break;
}
}
if(f==1)
System.out.println("NO");
else
System.out.println("YES");
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
056d0473709a5e811cb90b95291a038f
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.Scanner;
public class Codechef {
private static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int t = sc.nextInt();
while(t -- != 0) {
int n = sc.nextInt();
long sum = 0, need = 0;
boolean flag = false;
for(int i = 0; i < n; ++i) {
sum += sc.nextInt();
need += i;
if(sum < need && !flag) {
System.out.println("NO");
flag = true;
}
}
if (!flag)
System.out.println("YES");
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
0cc5083bf9ae309869c8b12382673d8c
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
public class ShiftingStacks {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
long x,c=0,sum1=0,sum2=0;
long n=sc.nextLong();
for(int i=0;i<n;i++)
{
long a=sc.nextLong();
sum1+=a;
sum2+=i;
if(sum1<sum2)
c=1;
}
if( c==1)
System.out.println("NO");
else
System.out.println("YES");
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
2d9206671f98598fffd9fb6bd24aff40
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
//package practice;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
public class Main {
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static void ruffleSort(int[] a) {
//ruffle
int n=a.length;
Random r=new Random();
for (int i=0; i<a.length; i++) {
int oi=r.nextInt(n), temp=a[i];
a[i]=a[oi];
a[oi]=temp;
}
//then sort
Arrays.sort(a);
}
static boolean prime[] = new boolean[1000001];
static void sieveOfEratosthenes()
{
int n=1000000;
Arrays.fill(prime, true);
prime[0]=false;prime[1]=false;
for(int p = 2; p*p <=n; p++)
{
// If prime[p] is not changed, then it is a prime
if(prime[p] == true)
{
// Update all multiples of p
for(int i = p*p; i <= n; i += p)
prime[i] = false;
}
}
}
public static void main(String[] args) throws IOException {
FastReader sc=new FastReader();
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
long arr[]=new long[n+3];
for(int i=0;i<n;i++) {
arr[i]=sc.nextLong();
}
boolean flag=true;
for(int i=0;i<n;i++) {
if(arr[i]>=i) {
long temp=arr[i];
arr[i+1] +=(temp-i);
arr[i]=i;
}
else {
System.out.println("NO");
flag=false;
break;
}
}
if(flag) {
System.out.println("YES");
}
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
acc0df14acbee4dce541cd1838767c60
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
import java.io.*;
public class A{
public static FastReader sc=new FastReader();
public static PrintWriter out = new PrintWriter(System.out);
public static void taskSolver(){
int n=sc.nextInt();int arr[]=new int[n];
for(int i=0;i<n;i++)arr[i]=sc.nextInt();long sum=0;
for(int i=0;i<n;i++){
if(arr[i]>i)sum+=arr[i]-i;
else{
int x=i-arr[i];
if(sum>=x){
sum-=x;continue;
}
else {
out.println("NO");return;
}
}
}
out.println("YES");
}
public static void main(String args[]) throws java.lang.Exception{
int t=sc.nextInt();
while(t-->0)
taskSolver();
out.close();
}
static class Pair{
long x,y;
Pair(long x,long y){
this.x=x;this.y=y;
}
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
437a87f75e9bf13cfe830f35099b3b7f
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
public class ShiftingStacks {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
int a[]=new int[n];
long j=0,k=0;
boolean is=true;
for(int i=0;i<n;i++) {
a[i]=sc.nextInt();
j+=i;
k+=a[i];
if(j>k)
is=false;
}
System.out.println(is?"YES":"NO");
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
e96feebfeb512d508b98774ba69c0d78
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
public class Main {
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int t=s.nextInt();
while(t-->0)
{
int n=s.nextInt();
long arr[]=new long[n];
for(int i=0;i<n;i++)
{
arr[i]=s.nextLong();
}
for(int i=0;i<n-1;i++)
{
if(arr[i]>i)
{
arr[i+1]+=(arr[i]-i);
arr[i]=i;
}
}
int flag=2;
for(int i=0;i<n;i++)
{
if(arr[i]<i)
{
flag=3;
System.out.println("NO");break;
}
}
if(flag!=3)
System.out.println("YES");
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
a02b7a860f45eb363e40ac36ab68e791
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
// Working program with FastReader
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;
public class B
{
public static void main(String[] args) {
FastReader sc = new FastReader();
int t = sc.nextInt();
//we must find the number of odd unique pairwise differences
while (t-- > 0) {
int n=sc.nextInt();
int count=0;
long[] a=new long[n];
boolean increasing=true;
long sum=0,need=0;
for (int i=0;i<n;i++)
{a[i]=sc.nextLong();}
for(int i=0;i<n;i++)
{
sum+=a[i];
need+=i;
if(sum<need)
{increasing=false;break;}
}
if(increasing)
System.out.println("Yes");
else
System.out.println("NO");
}//while
}//main
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
9781798de85b9d8626e6b6db0c3108cf
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
public class Check2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
process:for(int i=0;i<t;i++){
int n=sc.nextInt();
long[] ar=new long[n];
long sum=0;
for(int j=0;j<n;j++){
ar[j]=sc.nextLong();
}
for(int j=0;j<n-1;j++){
if(ar[j]>=(j+1)){
ar[j+1]=(ar[j]-j)+ar[j+1];
ar[j]=j;
}
if(ar[j+1]<=ar[j]){
System.out.println("NO");
continue process;
}
}
for(int j=0;j<n-1;j++){
if(ar[j+1]<=ar[j]){
System.out.println("NO");
continue process;
}
}
// System.out.println(Arrays.toString(ar));
System.out.println("YES");
/* Arrays.sort(ar);
long y=((n-1)*n)/2;
if(sum>=y){
System.out.println("YES");
}else {
System.out.println("NO");
}
*//*for(int j=0;j<n;j++){
if(ar[j]>=j){
}else {
System.out.println("NO");
continue process;
}
}
System.out.println("YES");*/
}
}
public static long NcR(int n,int r,long[][] dp) {
if(r==0 || r==n || n==1){
dp[n][r]=1L;
return 1L;
}
if(dp[n][r]!=-1){
return dp[n][r];
}
dp[n][r]= NcR(n-1,r-1,dp)+NcR(n-1,r,dp);
return dp[n][r];
}
public static long power(long a, long b, long c) {
long ans = 1;
while (b != 0) {
if (b % 2 == 1) {
ans = ans * a;
ans %= c;
}
a = a * a;
a %= c;
b /= 2;
}
return ans;
}
public static long power1(long a, long b, long c) {
long ans = 1;
while (b != 0) {
if (b % 2 == 1) {
ans = multiply(ans, a, c);
}
a = multiply(a, a, c);
b /= 2;
}
return ans;
}
public static long multiply(long a, long b, long c) {
long res = 0;
a %= c;
while (b > 0) {
if (b % 2 == 1) {
res = (res + a) % c;
}
a = (a + a) % c;
b /= 2;
}
return res % c;
}
public static long totient(long n) {
long result = n;
for (long i = 2; i * i <= n; i++) {
if (n % i == 0) {
//sum=sum+2*i;
while (n % i == 0) {
n /= i;
// sum=sum+n;
}
result -= result / i;
}
}
if (n > 1) {
result -= result / n;
}
return result;
}
public static long gcd(long a, long b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
public static boolean[] primes(int n) {
boolean[] p = new boolean[n + 1];
p[0] = false;
p[1] = false;
for (int i = 2; i <= n; i++) {
p[i] = true;
}
for (int i = 2; i * i <= n; i++) {
if (p[i]) {
for (int j = i * i; j <= n; j += i) {
p[j] = false;
}
}
}
return p;
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
e6e68d637fb8fd1a0e49506bfc4e0d93
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
//package codeforcesja29;
import java.util.*;
public class CodeF1 {
public class MyPair{
private Integer key;
private Integer value;
MyPair(Integer key, Integer value)
{
this.key = key;
this.value = value;
}
public Integer getKey() {
return this.key;
}
public Integer getValue() {
return this.key;
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner = new Scanner(System.in);
int cases = scanner.nextInt();
for(int i = 0 ; i < cases; i++)
{
int n = scanner.nextInt();
int[] height = new int[n];
for(int j = 0; j < n; j++)
height[j] = scanner.nextInt();
System.out.println(solve(height));
}
}
public static String solve(int[] height)
{
long aca = 0;
for(int i = 0; i < height.length; i++)
{
aca += height[i] - i;
if(aca < 0) return "No";
}
return "Yes";
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
bba404c3968b49a5794ab4fd7f49abe0
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
long sum=0;
long prev=0;
boolean flag=true;
for(int i=0;i<n;i++){
int no=sc.nextInt();
sum+=no-prev;
prev++;
if(sum<0)
flag=false;
}
if(flag)
System.out.println("YES");
else
System.out.println("NO");
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
93a104f4ed6935d561ad24c1884f26f6
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Arrays;
public class Cv {
//==========================Solution============================//
public static void main(String[] args) {
FastScanner in = new FastScanner();
Scanner input = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int t = input.nextInt();
while (t-- > 0) {
int n = input.nextInt();
int[] arr = new int[n];
long sum = 0;
long u = 0;
int x = 0;
for (int i = 0; i < n; i++) {
arr[i] = input.nextInt();
u+=i;
sum+=arr[i];
if (sum < u) {
x++;
}
}
if (x != 0) {
out.println("NO");
} else {
out.println("YES");
}
}
out.close();
}
//==============================================================//
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public String next() {
while (!st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
byte nextByte() {
return Byte.parseByte(next());
}
short nextShort() {
return Short.parseShort(next());
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return java.lang.Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
62138654f1e5205b907f49e5e6ea8fb1
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
import java.io.*;
import java.math.*;
public class B
{
public static void main(String[] args) throws IOException
{Scanner sc=new Scanner(System.in);
int ttt=sc.nextInt();
outer:while(ttt-->0)
{int n=sc.nextInt();String sb="yes";
long[] a=new long[n];long sum=0;
for(int i=0;i<n;i++)
{
a[i]=sc.nextLong();
sum=sum+a[i];
}
if(sum>=n*(n-1)/2)
{
for(int j=0;j<n-1;j++)
{
long temp=a[j]-j;
if(temp<0)
{
System.out.println("no");
continue outer;
}
a[j]=j;
a[j+1]+=temp;
}
}
else
sb="no";
for(int i=0;i<n-1;i++)
{
if(a[i]>=a[i+1])
{ sb="no";
break;
}
}
System.out.println(sb);
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
0e848abe6e404a1a4ea49ba37a2bbb1d
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
public class shifting1
{
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];
long j=0,k=0;
boolean is=true;
for(int i=0;i<n;i++) {
a[i]=sc.nextInt();
j+=i;
k+=a[i];
if(j>k)
is=false;
}
System.out.println(is?"YES":"NO");
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
9e56124739dcedd28d39a46cb08e702b
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.Scanner;
public class ShiftingStacks {
boolean shift(long arr[], int n )
{
int i ;
long carry = arr[0] ;
arr[0] = 0 ;
for( i = 1 ; i < n ; i++ )
{
carry = carry + arr[i] - i ;
if( carry < 0 )
return false ;
arr[i] = i ;
}
return true ;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
ShiftingStacks obj = new ShiftingStacks() ;
Scanner sc = new Scanner(System.in);
int t = sc.nextInt() ;
int i , j , n ;
boolean val ;
String res[] = new String[t] ;
for( i = 0 ; i < t ; i++ )
{
n = sc.nextInt() ;
long arr[] = new long[n] ;
for( j = 0 ; j < n ; j++ )
arr[j] = sc.nextInt() ;
val = obj.shift(arr, n) ;
res[i] = val == true ? "YES" : "NO" ;
System.out.println(res[i]) ;
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
5870bcbba9ab626f6d76bdab31ed35da
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
public class Shivigawdz {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
long a[]=new long[n+1];
for(int i=1;i<=n;i++)
{
a[i]=sc.nextLong();
}
int loop=0;
long sum=0;
for(int i=1;i<=n;i++)
{
sum+=a[i];
long need=(i*(i-1))/2;
if(sum<need)
{
loop=1;
break;
}
}
if(loop==1)
System.out.println("NO");
else
System.out.println("YES");
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
8891842fbd26cd453bdd1ead09182e1c
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
// package Round_703;
import java.io.*;
import java.math.*;
import java.util.*;
public class Problem_A {
public static void main(String[] args) {
FastReader in = new FastReader();
int numTrials = in.nextInt();
while(numTrials --> 0) {
int len = in.nextInt();
boolean works = true;
long extra = 0;
long[] arr = new long[len];
for(int i = 0; i < len; i++) {
arr[i] = in.nextLong();
}
for(int i = 0; i < len; i++) {
long n = arr[i];
extra = extra + n;
extra = extra - i;
if(extra < 0) {
works = false;
break;
}
}
if(works) {
System.out.println("YES");
}
else {
System.out.println("NO");
}
}
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
4b6dc628ea2677d13c2df4a589898054
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;
public class Main {
static class point {
long val, time, t3;
point(long val, long time, int t3) {
this.val = val;
this.time = time;
this.t3 = t3;
}
}
static class Reader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(
new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n') {
if (cnt != 0) {
break;
}
else {
continue;
}
}
buf[cnt++] = (byte)c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ') {
c = read();
}
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0,
BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
static class comp implements Comparator<point> {
public int compare(point a, point b) {
if (a.val == b.val) {
return Long.compare(b.time, a.time);
}
return Long.compare(a.val, b.val);
}
}
static class TreeNode {
int val;
TreeNode left,right;
TreeNode(int val){
this.val=val;left=null;right=null;
}
}
static TreeNode maxx(int start,int end,int[] arr){
if(start>end){
return null;
}
int ind=0;
int max=-1;
for(int j=start;j<=end;j++){
if(arr[j]>max){
max=arr[j];
ind=j;
}
}
TreeNode jj=new TreeNode(arr[ind]);
jj.left=maxx(start,ind-1,arr);
jj.right=maxx(ind+1,end,arr);
return jj;
}
static void dfs(TreeNode root,int dep){
if(root==null){
return;
}
ans[hashMap.get(root.val)]=dep;
dfs(root.left,dep+1);
dfs(root.right,dep+1);
}
static int[] ans;
static HashMap<Integer,Integer> hashMap;
static class pont{
int val,index;
pont(int val,int index){
this.val=val;
this.index=index;
}
}
static class compr implements Comparator<pont>{
public int compare(pont a,pont b){
return a.val-b.val;
}
}
public static void main(String[] args) throws IOException {
Scanner s = new Scanner(System.in);
int t=s.nextInt();
for(int j=0;j<t;j++){
int n=s.nextInt();
// int low=1,high=n;
//
// while (low<high){
// System.out.print("? "+low+" "+high);
// System.out.println();
// System.out.flush();
// int index=s.nextInt();
//// if(index==low){
//// low++;continue;
//// }
//// if(index==high){
//// high--;continue;
//// }
// if(high==index) {
// System.out.print("? " + low + " " + index);
// System.out.println();
// System.out.flush();
// int ss = s.nextInt();
// if(ss==index){
// high=index-1;
// }else{
// low=index+1;
// }
//
// }else{
// System.out.print("? " + index + " " + high);
// System.out.println();
// System.out.flush();
// int ss = s.nextInt();
// if(ss==index){
// low=index+1;
// }else{
// high=index-1;
// }
// }
//
//// System.out.print("? "+low+" "+index);
//// System.out.println();
//// System.out.flush();
//// ss=s.nextInt();
//
//
// }
//// if(low==high){
// System.out.println("! "+low );
//// }
//
//
//// System.out.println();
// System.out.flush();
// int[] x=new int[n];
// int[] y=new int[n];
// HashMap<Integer,HashSet<Integer>> has=new HashMap<>();
//
// for(int i=0;i<n;i++){
// x[i]=s.nextInt();
// y[i]=s.nextInt();
// has.put(x[i],new HashSet<>());
// }
// int tot=0;
// //boolean[][] vis=new boolean[n][n];
// long min=Long.MAX_VALUE;
// for(int i=0;i<n;i++){
// long sum=0;
// for(int k=0;k<n;k++){
// sum=(long)((long)sum+(long)Math.abs(x[i]-x[k])+Math.abs(y[i]-y[k]));
// }
// if(sum<min){
// tot=1;
// min=sum;
//// if(has.get(x[i])==null){
//// has.put(x[i],new HashSet<>());
//// }
// has.get(x[i]).add(y[i]);
// }
// else if(sum==min && !has.get(x[i]).contains(y[i]) ){
// tot++;
//// if(has.get(x[i])==null){
//// has.put(x[i],new HashSet<>());
//// }
// has.get(x[i]).add(y[i]);
//
// }
//// vis[x[i]][y[i]]=true;
// }
//
// System.out.println(tot);
long[] arr=new long[n];
long sum=0;
int jj=0;
long tt=0;
for(int i=0;i<n;i++){
arr[i]=s.nextLong();
sum=(long)((long)sum+(long)arr[i]);
// if(i>0 && arr[i]<arr[i-1] && arr[i-1]-arr[i]>1){
// jj=1;break;
// }
// else if(i>0 && arr[i]<arr[i-1]){
// arr[i-1]--;
// arr[i]++;
// if(arr[i-1]==0 && i-1>0){
// jj=1;break;
// }
// }
// else if(i>0 && arr[i]==arr[i-1] && arr[i]==0){
// jj=1;break;
// }
long to=tt*(tt+1)/2;
if(sum<to){
jj=1;
}
tt++;
}
//long tot=(n-1)*n/(long)2;
if(jj==0){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
29bd60dfd39b5e4ac5d1a354401e9c82
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
FastScanner input = new FastScanner();
int tc = input.nextInt();
work: while (tc-- > 0) {
int n = input.nextInt();
int a[] = new int[n + 1];
for (int i = 0; i < n; i++) {
a[i] = input.nextInt();
}
long sum=0;
for (int i = 0; i < n; i++) {
sum+=a[i];
if(((i*(i+1))/2)>sum)
{
System.out.println("NO");
continue work;
}
}
System.out.println("YES");
}
}
static class FastScanner
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next()
{
while (!st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine() throws IOException
{
return br.readLine();
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
85e0b0be5db560b4d2d649dc49458a91
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.Scanner;
public class stack {
public static void check(long[] h) {
long count=0;
for(int i=0;i<h.length-1;i++) {
long a=h[i]-i;
h[i]=i;
h[i+1]+=a;
if(h[i+1]<=h[i]) {
System.out.println("NO");
count=1;
break;
}
}
if(count!=1) {
System.out.println("YES");
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
for (int i = 0; i < t; i++) {
int n=scanner.nextInt();
long[] a=new long[n];
for(int j=0;j<n;j++) {
a[j]=scanner.nextLong();
}
check(a);
}
scanner.close();
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
21b01f7b9aaec4e853153d609d9f36f5
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.Scanner;
public class shiftingstacks {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int t = scn.nextInt();
for (int tt = 0; tt < t; tt++) {
int n = scn.nextInt();
long sum = 0;
boolean flag = false;
long limit = 0;
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
long k = scn.nextLong();
arr[i] = k;
}
long save = 0;
for (int i = 0; i < n; i++) {
if (arr[i] >= i) {
save = save + arr[i] - i;
} else {
if (save < i - arr[i]) {
flag = true;
System.out.println("NO");
break;
} else {
save = save - i + arr[i];
}
}
}
if (flag == false) {
System.out.println("YES");
}
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
7cefbe647394861d89cb0222736e72fb
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.Scanner;
public class Shifting {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
long h[] = new long[n];
long temp = 0;
boolean answear = true;
for (int i = 0; i < n; i++) {
h[i] = sc.nextLong();
if (h[i] >= i) {
temp += h[i] - i;
} else if (h[i]+ temp>=i) {
temp-=i-h[i];
}else {
answear = false;
}
}
if (answear == true) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
4c696a0f6a09ea83ab61858040844941
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
public class codeforces2 {
public static int abs(int x) {
if(x<0)return -x;
return x;
}
public static int gcd(int a,int b) {
if(b==0)return a;
return gcd(b,a%b);
}
public static void display(char[][]x) {
for(int i=0;i<x.length;i++) {
for(int j=0;j<x[i].length;j++) {
System.out.print(x[i][j]+" ");
}
System.out.println();
}
}
public static boolean allEqual(int[] arr) {
for(int i=0;i<arr.length-1;i++) {
if(arr[i]!=arr[i+1])return false;
}
return true;
}
public static boolean isSorted(int[] x) {
for(int i=0;i<x.length-1;i++) {
if(x[i]>x[i+1])return false;
}
return true;
}
/*public static QueueObj multCons(QueueObj x) {
QueueObj t1=new QueueObj(x.size()-1);
QueueObj t2=new QueueObj(x.size());
int s=x.size();
for(int i=0;i<s-1;i++) {
int n=(int)x.dequeue();
t2.enqueue(n);
t1.enqueue(n*(int)(x.peek()));
x.enqueue(n);
//t1.printQueue();
}
//while(!t2.isEmpty())x.enqueue(t2.dequeue());
x.enqueue(x.dequeue());
return t1;
}*/
/*public static boolean num(QueueObj x,char c,int n) {
int s=x.size();
int t=0;
for(int i=0;i<s;i++) {
char w=(char)x.dequeue();
if(w==c)t++;
x.enqueue(w);
}
if(t==n)return true;
else return false;
}*/
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0) {
int n=sc.nextInt();
int[] h=new int[n];
long s=0;
long need=0;
boolean r=true;
for(int i=0;i<n;i++) {
h[i]=sc.nextInt();
need+=i;
s+=h[i];
if(s<need) {
r=false;
}
}
if(!r)System.out.println("NO");
else System.out.println("YES");
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
6b5ab2bc7c20b7f0a672847b6a0b0f5c
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.Scanner;
public class cf1486A {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
int n = 0;
long[] a;
while(t-->0){
n = scan.nextInt();
a = new long[n];
for(int i=0;i<n;i++){
a[i] = scan.nextLong();
}
long sum = 0;
long s = 0;
boolean c = true;
for(int i=0;i<n;i++){
sum += i;
s += a[i];
if(sum>s){
c = false;
break;
}
}
// System.out.println("count: "+count);
if(c) System.out.println("Yes");
else System.out.println("No");
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
33f073a7728207d4d2c1d70f61846dfb
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.io.*;
import java.util.*;
/*
*
* @author
*
*/
public class SolveIt {
private static StringTokenizer st;
private static BufferedReader br;
private static PrintWriter pw;
static class Pair{
int a, b;
public Pair(int a, int b) {
this.a = a;
this.b = b;
}
}
public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int t = nextInt();
while (t -- > 0)
{
int n = nextInt();
//System.out.println(suma);
long cnt = 0;
long a[] = new long[n + 1];
boolean check = true;
long suma = 0;
for(int i = 0; i < n ;i++){
a[i] = nextLong();
cnt += i;
check &= (a[i] + suma) >= cnt;
suma += a[i];
}
System.out.println(check ? "YES" : "NO");
}
}
private static int nextInt() throws IOException {
return Integer.parseInt(next());
}
private static long nextLong() throws IOException {
return Long.parseLong(next());
}
private static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
private static String next() throws IOException {
while (st==null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
7de16cd020cd51b21fae40622670a169
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import com.sun.org.apache.regexp.internal.RE;
import java.util.*;
public class Main {
static Scanner scan = new Scanner(System.in);
public static void slove(){
int n = scan.nextInt();
int[] a = new int[n];
for(int i=0;i<n;i++){
a[i] = scan.nextInt();
}
long sum = 0;
int base = 0;
for(int i=0;i<n;i++){
sum +=a[i];
if(sum < base){
System.out.println("NO");
return;
}
base +=(i+1);
}
System.out.println("YES");
}
public static void main(String[] args) {
int T = scan.nextInt();
while(T-->0){
slove();
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
5be98b77ad601f7dd0652a42fc216bd1
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
public class Solution{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int test_cases =sc.nextInt();
while(test_cases-->0){
int ele =sc.nextInt();
int height[] =new int[ele];
for(int i=0;i<ele;i++){
height[i]=sc.nextInt();
}
long sum=0;
int index_Sum=0,count=1;
for(int i=0;i<ele;i++){
index_Sum+=i;
sum+=height[i];
if(sum<index_Sum){
count=0;
}
}
if(count==1){
System.out.println("YES");
}
else
System.out.println("NO");
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
054bd712a5d38f1826fee19ac8533c7f
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.io.*;
import java.util.*;
/*
polyakoff
*/
public class Main {
static FastReader in;
static PrintWriter out;
static Random rand = new Random();
static final int oo = (int) 1e9 + 10;
static final long OO = (long) 2e18 + 10;
static final int MOD = (int) 1e9 + 7;
static void solve() {
int n = in.nextInt();
int[] h = new int[n];
for (int i = 0; i < n; i++) {
h[i] = in.nextInt();
}
int last = 0;
long extra = h[0];
for (int i = 1; i < n; i++) {
if (h[i] + extra > last) {
extra = h[i] + extra - last - 1;
last++;
} else {
out.println("NO");
return;
}
}
out.println("YES");
}
public static void main(String[] args) {
in = new FastReader();
out = new PrintWriter(System.out);
int T = 1;
T = in.nextInt();
while (T-- > 0)
solve();
out.flush();
out.close();
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
FastReader() {
this(System.in);
}
FastReader(String file) throws FileNotFoundException {
this(new FileInputStream(file));
}
FastReader(InputStream is) {
br = new BufferedReader(new InputStreamReader(is));
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String next() {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(nextLine());
}
return st.nextToken();
}
String nextLine() {
String line;
try {
line = br.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
return line;
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
7c337dce6bfd3cee3ca40c4a5e9e14a9
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.io.*;
import java.util.*;
/*
polyakoff
*/
public class Main {
static FastReader in;
static PrintWriter out;
static Random rand = new Random();
static final int oo = (int) 1e9 + 10;
static final long OO = (long) 2e18 + 10;
static final int MOD = (int) 1e9 + 7;
static void solve() {
int n = in.nextInt();
long[] h = new long[n];
for (int i = 0; i < n; i++) {
h[i] = in.nextInt();
}
long last = -1;
long extra = 0;
for (int i = 0; i < n; i++) {
if (h[i] + extra > last) {
extra = h[i] + extra - last - 1;
last++;
} else {
out.println("NO");
return;
}
}
out.println("YES");
}
public static void main(String[] args) {
in = new FastReader();
out = new PrintWriter(System.out);
int T = 1;
T = in.nextInt();
while (T-- > 0)
solve();
out.flush();
out.close();
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
FastReader() {
this(System.in);
}
FastReader(String file) throws FileNotFoundException {
this(new FileInputStream(file));
}
FastReader(InputStream is) {
br = new BufferedReader(new InputStreamReader(is));
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String next() {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(nextLine());
}
return st.nextToken();
}
String nextLine() {
String line;
try {
line = br.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
return line;
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
89160233bbe521f947fb5249dfaede79
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
import java.util.StringTokenizer;
import static java.lang.Math.*;
public class B {
static FastScanner sc;
static PrintWriter pw;
public static void main(String[] args) {
sc = new FastScanner();
pw = new PrintWriter(System.out);
int T = sc.nextInt();
while (T-- > 0) {
solve();
}
pw.close();
}
private static void solve() {
int n = sc.nextInt();
long[] a = new long[n];
for(int i = 0; i < n; i++) {
a[i] = sc.nextLong();
}
if(n == 1) {
pw.println("YES");
return;
}
long prev = -1;
for(int i = 0; i< n-1; i++) {
if(a[i] > prev+1) {
a[i+1] += a[i] - prev - 1;
} else if(a[i] < prev + 1){
pw.println("NO");
return;
}
a[i] = prev+1;
prev = a[i];
}
if(a[n-1] <= a[n-2] ) {
pw.println("NO");
return;
}
pw.println("Yes");
}
static void debug(Object... O) {
System.out.println(Arrays.deepToString(O));
}
static void sort(int[] a) {
ArrayList<Integer> l = new ArrayList<>();
for (int i : a)
l.add(i);
Collections.sort(l);
for (int i = 0; i < a.length; i++)
a[i] = l.get(i);
}
static class FastScanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
2ebd6cead043cf44d714fda7642390ab
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.Scanner;
public class ShiftingStacks {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int a =input.nextInt();
for (int i=0;i<a;i++) {
int b = input.nextInt();
long newArray[] = new long[b];
for(int j=0;j<b;j++)
newArray[j]=input.nextInt();
System.out.println(shiftingStacks(b,newArray));
}
}
public static String shiftingStacks(int b,long newArray[]) {
long sum=0;
for(int i=0;i<b;i++) {
sum+=newArray[i];
if (sum<i*(i+1)/2)
return "NO";
}
return "YES";
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
b112a0562dea4c08459953ac659b2b53
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.Scanner;
public class ShiftingStacks {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int a =input.nextInt();
int array[] = new int[a];
int k=0;
for (int i=0;i<a;i++) {
int b = input.nextInt();
int newArray[] = new int[b];
for(int j=0;j<newArray.length;j++) {
newArray[j]=input.nextInt();
}
array[k]=shiftingStacks(b,newArray);
k++;
}
for(int i=0;i<array.length;i++) {
if(array[i]==0)
System.out.println("NO");
else
System.out.println("YES");
}
}
public static int shiftingStacks(int b,int newArray[]) {
long sum=0;
for(int i=0;i<b;i++) {
sum+=newArray[i];
if (sum<i*(i+1)/2)
return 0;
}
return 1;
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
b882c680465421a938ebb3914b8a3cf1
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;import java.io.*;import java.math.*;
public class ShiftingStacks
{
static final Random random=new Random();
static void ruffleSort(int[] a) {
int n = a.length;
for (int i=0; i<n; i++) {
int oi=random.nextInt(n), temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
ArrayList<Integer> lst = new ArrayList<>();
for(int i : a)
lst.add(i);
Collections.sort(lst);
for(int i = 0; i < n; i++)
a[i] = lst.get(i);
}
static void ruffleSort(long[] a) {
int n = a.length;
for (int i=0; i<n; i++) {
int oi=random.nextInt(n);
long temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
ArrayList<Long> lst = new ArrayList<>();
for(long i : a)
lst.add(i);
Collections.sort(lst);
for(int i = 0; i < n; i++)
a[i] = lst.get(i);
}
public static void process()throws IOException
{
int n = ni();
long[] h = nal(n);
long sum = 0, cur = 0;
for(int i = 0; i < n; i++){
cur += i;
sum += h[i];
if(sum < cur){
pn("NO");
return;
}
}
pn("YES");
}
static AnotherReader sc;
static PrintWriter out;
public static void main(String[]args)throws IOException
{
boolean oj = System.getProperty("ONLINE_JUDGE") != null;
if(oj){sc=new AnotherReader();out=new PrintWriter(System.out);}
else{sc=new AnotherReader(100);out=new PrintWriter("output.txt");}
long s = System.currentTimeMillis();
int t=1;
t=ni();
//int k = t;
while(t-->0) {/*p("Case #"+ (k-t) + ": ")*/;process();}
out.flush();
System.err.println(System.currentTimeMillis()-s+"ms");
out.close();
}
static long power(long k, long c, long mod){
long y = 1;
while(c > 0){
if(c%2 == 1)
y = y * k % mod;
c = c/2;
k = k * k % mod;
}
return y;
}
static void pn(Object o){out.println(o);}
static void p(Object o){out.print(o);}
static void pni(Object o){out.println(o);out.flush();}
static int ni()throws IOException{return sc.nextInt();}
static long nl()throws IOException{return sc.nextLong();}
static double nd()throws IOException{return sc.nextDouble();}
static String nln()throws IOException{return sc.nextLine();}
static int[] nai(int N)throws IOException{int[]A=new int[N];for(int i=0;i!=N;i++){A[i]=ni();}return A;}
static long[] nal(int N)throws IOException{long[]A=new long[N];for(int i=0;i!=N;i++){A[i]=nl();}return A;}
static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
static class AnotherReader{BufferedReader br; StringTokenizer st;
AnotherReader()throws FileNotFoundException{
br=new BufferedReader(new InputStreamReader(System.in));}
AnotherReader(int a)throws FileNotFoundException{
br = new BufferedReader(new FileReader("input.txt"));}
String next()throws IOException{
while (st == null || !st.hasMoreElements()) {try{
st = new StringTokenizer(br.readLine());}
catch (IOException e){ e.printStackTrace(); }}
return st.nextToken(); } int nextInt() throws IOException{
return Integer.parseInt(next());}
long nextLong() throws IOException
{return Long.parseLong(next());}
double nextDouble()throws IOException { return Double.parseDouble(next()); }
String nextLine() throws IOException{ String str = ""; try{
str = br.readLine();} catch (IOException e){
e.printStackTrace();} return str;}}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
d13c10d23073eb09fae8193b004adf5a
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.util.*;
public class Solve {
public static void swap(int a,int b){
int temp = a;
a=b;
b=temp;
}
public static int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
public static int lcm(int a, int b) {
return (a / gcd(a, b)) * b;
}
public static int sumOfDigits(int n){
int sum=0;
while (n!=0){
sum+=n%10;
n/=10;
}
return sum;
}
public static int ceil(int x,int y){
return (x+y-1)/y;
}
public static int numberOfDigits(int n){
int count=0;
while(n!=0){
count++;
n/=10;
}
return count;
}
public static boolean checkPrime(int n){
if(n<=1){
return false;
}
if(n==2){
return true;
}
if(n%2==0){
return false;
}
for(int i=3;i<=Math.sqrt(n);i++){
if(n%i==0){
return false;
}
}
return true;
}
public static int countPrime(int n){
int count=0;
for(int i=0;i<=n;i++){
if(checkPrime(i)){
count++;
}
}
return count;
}
/* public static int factorial(int n){
if(n<=1){
return 1;
}
return n*factorial(n-1);
}
*/
public static void factorial(int n){
int[] res = new int[500];
res[0] = 1;
int res_size = 1;
for(int x=2;x<=n;x++){
res_size = multiply(res,res_size,x);
}
for (int i = res_size - 1; i >= 0; i--){
System.out.print(res[i]);
}
}
public static int multiply(int[] res,int res_size,int x){
int carry = 0;
for(int i=0;i<res_size;i++){
int prod = res[i]*x+carry;
res[i] = prod%10;
carry = prod/10;
}
while(carry!=0){
res[res_size] = carry%10;
carry /= 10;
res_size++;
}
return res_size;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
while (t-->0){
int n = scan.nextInt();
int[] a = new int[n];
long sum=0L,index=0L;
boolean f = true;
for(int i=0;i<n;i++){
a[i] = scan.nextInt();
}
for(int i=0;i<n;i++){
sum+=a[i];
index += i;
if(sum<index){
f = false;
System.out.println("NO");
break;
}
}
if(f){
System.out.println("YES");
}
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
| |
PASSED
|
ee37e2c7f5218b56dde6e81378326cf8
|
train_109.jsonl
|
1613658900
|
You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.
|
256 megabytes
|
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author atul05kumar
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA {
public void solve(int testNumber, Scanner in, PrintWriter out) {
int t = in.nextInt();
while (t > 0) {
int n = in.nextInt();
int[] h = new int[n];
long extra = 0;
for (int i = 0; i < n; i++) {
h[i] = in.nextInt();
}
for (int i = 0; i < n; i++) {
if (h[i] > i) {
extra += (h[i] - i);
} else {
extra -= (i - h[i]);
if (extra < 0) {
break;
}
}
}
if (extra < 0) {
out.println("NO");
} else {
out.println("YES");
}
t--;
}
}
}
}
|
Java
|
["6\n2\n1 2\n2\n1 0\n3\n4 4 4\n2\n0 0\n3\n0 1 0\n4\n1000000000 1000000000 1000000000 1000000000"]
|
1 second
|
["YES\nYES\nYES\nNO\nNO\nYES"]
|
NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.
|
Java 8
|
standard input
|
[
"greedy",
"implementation"
] |
7a8c4ba98a77097faff625b94889b365
|
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.
| 900
|
For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).
|
standard output
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.