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
77102ec1fca772c621add2694e9c9aa7
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 Array; import java.util.Scanner; public class test { private static Scanner sc = new Scanner(System.in); public static void main(String[] args) { long t = sc.nextLong(); while(t-- > 0) { long n = sc.nextInt(); long min = -1; long previous = 0; boolean flag = false; for (int i = 0; i < n; i++) { long current = sc.nextLong() + previous; if(current <= min) { flag = true; } min++; previous = current - min; } System.out.println(flag ? "NO" : "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
9c7740470047b0cf7bbdc69007205ded
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) { // TODO Auto-generated method stub Scanner x = new Scanner(System.in); int testcase = x.nextInt(); while(testcase-- != 0) { int n = x.nextInt(); long arr[] = new long[n]; for(int i=0; i<n; i++) { arr[i] = x.nextLong(); } for(int i=0; i<n-1; i++) { if(arr[i]>i) { arr[i+1] = arr[i+1] + (arr[i]-i); arr[i] = i; } } boolean b = true; for(int i=1; i<n; i++) { if(arr[i-1]>=arr[i]) { b=false; System.out.println("NO"); break; } } if(b)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
e47114ed66b850872b822de50dc53743
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.InputStream; import java.io.InputStreamReader; import java.util.*; public class Scratch { public static void main(String[] args) throws IOException { Scanner Reader = new Scanner(System.in); long n = Reader.nextLong(); while(n-->0){ long size = Reader.nextLong(); long[] arr = new long[(int) size]; for (int i = 0; i < size; i++) { arr[i] = Reader.nextInt(); } if(size==1){ System.out.println("YES"); continue; } boolean bol = false;long diff = 0; for (int i = 0; i < size-1; i++){ if(arr[i]>=arr[i+1]){ diff = arr[i] -i; if(diff <=0){ bol = true; break; } else{ arr[i] = i; arr[i+1] = arr[i+1] + diff; if(arr[i]>=arr[i+1]){ bol = true; break; } } } else{ diff = arr[i]-i; if(diff>0){ arr[i] = i; arr[i+1] = arr[i+1] +diff; } } } if(bol){ System.out.println("NO"); } else{ System.out.println("YES"); } } } public static double costToHireMinimum(double[] Skill, double[] wage, long k){ int TotalWorkers = Skill.length; Worker[] workers = new Worker[TotalWorkers]; for (int i = 0; i < TotalWorkers; i++) { workers[i] = new Worker(wage[i],Skill[i]); } Arrays.sort(workers); heap2 maxCostHeap = new heap2(); double Finalcost = Double.MAX_VALUE; double TotalNumberOfSkill = 0; for (int i = 0; i < workers.length; i++) { TotalNumberOfSkill += workers[i].GetSkill(); maxCostHeap.insert(workers[i].GetSkill()); if(maxCostHeap.heap.size() > k){ TotalNumberOfSkill = TotalNumberOfSkill - maxCostHeap.delete(); } if(maxCostHeap.heap.size() == k) { Finalcost = Math.min(Finalcost, TotalNumberOfSkill * workers[i].ratio()); } } return Finalcost; } } class Reader { static BufferedReader reader; static StringTokenizer tokenizer; /** call this method to initialize reader for InputStream */ static void init(InputStream input) { reader = new BufferedReader(new InputStreamReader(input) ); tokenizer = new StringTokenizer(""); } /** get next word */ static String next() throws IOException { while ( ! tokenizer.hasMoreTokens() ) { tokenizer = new StringTokenizer( reader.readLine() ); } return tokenizer.nextToken(); } static long nextInt() throws IOException { return Long.parseLong( next() ); } static double nextDouble() throws IOException { return Double.parseDouble( next() ); } } class Worker implements Comparable<Worker> { private double Wage; private double Skill; private double ratio; public Worker(double wage, double skill){ Wage = wage; Skill = skill; } public double ratio(){ ratio = Wage/Skill; return ratio; } @Override public int compareTo(Worker o1) { if(this.ratio()>o1.ratio()){ return 1; } else if(this.ratio()<o1.ratio()){ return -1; } return 0; } public double GetSkill(){ return Skill; } } class heap2 { public ArrayList<Double> heap = new ArrayList<>(); public void insert(double value) { heap.add(value); correction_in_heap(heap.size() - 1); } private void correction_in_heap(double value) { double parent = (value - 1) / 2; if (heap.get((int)parent) < heap.get((int)value)) { swap(parent, value); correction_in_heap(parent); } } private void swap(double val1, double val2) { double temp1 = heap.get((int)val1); double temp2 = heap.get((int)val2); heap.set((int)val1,temp2); heap.set((int)val2, temp1); } public double delete() { swap(0, this.heap.size() - 1); double removed = this.heap.remove(this.heap.size() - 1); downcorrection(0); return removed; } private void downcorrection(long val) { long left = 2 * val + 1; long right = 2 * val + 2; long pi = val; if (left < heap.size() && heap.get((int) left) > heap.get((int) pi)) { pi = left; } if (right < heap.size() && heap.get((int) right) > heap.get((int) pi)) { pi = right; } if (pi != val) { swap(pi, val); downcorrection(pi); } } }
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
8443f78f69d188a4936c6313f631e271
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 { static Scanner input=new Scanner(System.in); public static void main(String[] args) { readData(); } public static void readData() { int t=input.nextInt(); for(int i=0;i<t;i++) { int n=input.nextInt(); long[] heights=new long[n]; for(int j=0;j<n;j++) heights[j]=input.nextInt(); System.out.println(response(n,heights)); } } public static String response(int n, long[] heights) { long sum=0; for(int i=0;i<n;i++) { sum+=heights[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
076df8b8016fcb0fb414608c2881b93b
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 Solution { public static void main(String[] args) throws Exception { FastReader fr=new FastReader(); int t=fr.nextInt(); while(t-->0) { int n=fr.nextInt(); long a[]=new long[n]; for(int i=0;i<n;i++) { a[i]=fr.nextInt(); } boolean pos=true; for(int i=0;i<n-1;i++) { if(a[i]>i) { a[i+1]+=(a[i]-i); a[i]=i; } } for(int i=1;i<n;i++) { if(a[i]<=a[i-1]) { pos=false; break; } } if(pos) System.out.println("YES"); else System.out.println("NO"); } } } class Pair implements Comparable<Pair>{ int x; int y; Pair(int x,int y){ this.x=x; this.y=y; } public int compareTo(Pair o) { if(this.x!=o.x) return this.x-o.x; else return this.y-o.y; } } 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
ed9b1df8dc69f10d15689b28aea1025f
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 Solution { static Scanner sc=new Scanner(System.in); static String isInc(int n,int[] arr) { if(n==0 || n==1) return "YES"; long sum =0; long ts =0; for(int i=0;i<n;i++) { ts+=i; sum+=arr[i]; if(sum<ts) return "NO"; } return "YES"; } public static void main(String[] args) { 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(); System.out.println(isInc(n,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 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
e93bfbc2b5a73c66f8866959917c6392
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 Main { public static boolean check(long[] arr){ for (int i = 0; i < arr.length-1; i++) { if(arr[i] >= arr[i+1]) return false; } return true; } public static void main(String[] args) throws IOException { int tc = sc.nextInt(); while(tc --> 0){ int n = sc.nextInt(); int[] arr = sc.nextIntArr(n); long cum = 0; int el = 0; boolean f = true; for (int i = 0; i < n; i++) { if(arr[i] >= el){ cum += arr[i]-el; } else{ long needed = el - arr[i]; if(cum < needed) f = false; else cum -= needed; } el++; } if(f) pw.println("YES"); else pw.println("NO"); } pw.close(); } public static void pairSort(Pair[] arr) { ArrayList<Pair> l = new ArrayList<>(); Collections.addAll(l, arr); Collections.sort(l); for (int i = 0; i < arr.length; i++) { arr[i] = l.get(i); } } public static void longSort(long[] arr) { ArrayList<Long> l = new ArrayList<>(); for (long i : arr) l.add(i); Collections.sort(l, Collections.reverseOrder()); for (int i = 0; i < arr.length; i++) { arr[i] = l.get(i); } } public static void intSort(int[] arr) { ArrayList<Integer> l = new ArrayList<>(); for (int i : arr) l.add(i); Collections.sort(l, Collections.reverseOrder()); for (int i = 0; i < arr.length; i++) { arr[i] = l.get(i); } } static class Pair implements Comparable<Pair>{ int first; int second; public Pair(int first, int second){ this.first = first; this.second = second; } @Override public int compareTo(Pair p2) { /*if(first == p2.first) return (second - p2.second); else*/ return first - p2.first; } @Override public String toString() { return "("+ first + "," + second + ')'; } } static class Triple { int x, y, z; Triple(int a, int b, int c) { x = a; y = b; z = c;} // public int compareTo(Triple t) // { // if(Math.abs(sum - t.sum) < 1e-9) return x > t.x ? 1 : -1; // return sum > t.sum ? 1 : -1; // } public String toString() { return "(" + x + ", " + y + ", " + z + ")"; } } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public boolean ready() throws IOException { return br.ready(); } public int[] nextIntArr(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = Integer.parseInt(next()); } return arr; } public long[] nextLongArr(int n) throws IOException { long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = Long.parseLong(next()); } return arr; } } static PrintWriter pw = new PrintWriter(System.out); static Scanner sc = new Scanner(System.in); static Random random = new Random(); static final long MOD = 1_000_000_000 + 7; }
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
d4e9f0ae54a2dbce6560fd30ff84250f
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.StringTokenizer; public class A { public boolean solve(IO io) throws IOException { long n = io.nextLong(); long sum = 0L; boolean ans = true; for (long i = 0L; i < n; ++i) { sum += io.nextLong(); sum -= i; if (sum < 0L) { ans = false; } } return ans; } public void run() throws IOException { IO io = new IO(); long t = io.nextLong(); for (long i = 0L; i < t; ++i) { if (solve(io)) { io.println("YES"); } else { io.println("NO"); } io.out.flush(); } io.close(); } public static void main(String[] args) throws IOException { new A().run(); } } class IO { public IO() { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } BufferedReader br; StringTokenizer in; PrintWriter out; public String nextToken() throws IOException { while (in == null || !in.hasMoreTokens()) { in = new StringTokenizer(br.readLine()); } return in.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(nextToken()); } public double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } public long nextLong() throws IOException { return Long.parseLong(nextToken()); } public void print(String a) { out.print(a); } public void println(String a) { out.println(a); } public void close() { 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 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
55075c564cdc2d0147a2ba9dc4d7e3d9
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 void main(String[] args) { new Main(); } public Main() { submit(); } public void submit() { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); for(int i = 0; i < N; i++) { int count = scan.nextInt(); long sum = 0; boolean sign = true; for(int j = 0; j < count; j++) { long preSum = j * (j + 1) / 2; sum += scan.nextInt(); if(sign && preSum > sum) { System.out.println("No"); sign = false; } } if(sign) System.out.println("Yes"); } return; } }
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
3e56d115574636c861c84a6d8b616c01
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 B_703 { public static void main(String[] args) { // TODO Auto-generated method stub FastScanner fs = new FastScanner(); int t = fs.nextInt(); while(t-- > 0) { int size = fs.nextInt(); long sum = 0; long[] arr = new long[size]; for(int i = 0 ; i < size ; i++) { arr[i] = fs.nextLong(); sum += arr[i]; } double val1 = (double)((size-1)*(size)); val1 /= 2; //System.out.println(val1); boolean flag = false; if(val1 <= sum) { long val = 0; for(int i = 0 ; i < size; i++) { val += (arr[i] - i); if(val < 0) { flag = true; break; } } if(!flag) System.out.println("YES"); else System.out.println("NO"); } else System.out.println("NO"); } } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { 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
9c70e5585399dd4d6752b3fdf2ecfc1e
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 kriti; import java.math.*; import java.io.*; import java.util.*; public class A { static PrintWriter out = new PrintWriter(System.out); static StringBuilder ans=new StringBuilder(); static FastReader in=new FastReader(); public static void main(String args[])throws IOException { int t =i(); outer:while(t-->0) { long n = l(); long[] A = inputLong((int)n); long[] B = new long[(int)n]; B[0]=0; // if(isSorted(A)) { // out.println("YES"); // continue outer; // } for(int i=1;i<n;i++) { B[i]=B[i-1]+1; // out.print(B[i]); } for(int i=0;i<n-1;i++) { if(A[i]>=B[i]) { A[i+1]+=A[i]-B[i]; } else { out.println("NO"); continue outer; } } if(A[(int)n-1]>=B[(int)n-1]) { out.println("YES"); } else { out.println("NO"); } // long sumA=0; long sumB=0; // for(int i=0;i<n;i++) { // sumA+=A[i]; // } // for(int i=1;i<n;i++) { // B[i]=B[i-1]+1; // sumB+=B[i]; // // out.print(B[i]); // } // if(sumA<sumB) { // out.println("NO"); // } // else { // out.println("YES"); // } } out.close(); } static void BubbleSort(int[] A , int n, int i) { if(i==n-1 && n==0) return ; if(n>i) { if(A[i]>A[i+1]) { Swap(A, i,i+1); } BubbleSort(A,n, i=i+1); } else { BubbleSort(A,n=n-1,0); } } static int[] Swap(int[] A, int i, int j) { int temp = A[i]; A[i]=A[j]; A[j]=temp; return A; } static String ChartoString(char[] x) { String ans=""; for(char i:x) { ans+=i; } return ans; } static int HCF(int num1, int num2) { int temp1 = num1; int temp2 = num2; while(temp2 != 0){ int temp = temp2; temp2 = temp1%temp2; temp1 = temp; } int hcf = temp1; return hcf; } static boolean palindrome(String s) { char[] x = s.toCharArray(); int i=0; int r= x.length-1; while(i<r) { if(x[i]!=x[r]) { return false; } i++; r--; } return true; } static void sorting(long[] a) //check for long { ArrayList<Long> l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static boolean equal(int[] A) { int cnt=1;int prev=A[0]; for(int i=1;i<A.length;i++) { if(A[i]==prev)cnt++; } if(cnt==A.length)return true; return false; } static int findGcd(int x, int y) { if (x == 0) return y; return findGcd(y % x, x); } static int findLcm(int x, int y) { return (x / findGcd(x, y)) * y; } public static int checkTriangle(long a, long b, long c) { if (a + b <= c || a + c <= b || b + c <= a) return 0; else return 1; } static boolean isSorted(long A[]) { for(int i=1; i<A.length; i++)if(A[i]<=A[i-1])return false; return true; } static int kadane(int A[]) { int lsum=A[0],gsum=A[0]; for(int i=1; i<A.length; i++) { lsum=Math.max(lsum+A[i],A[i]); gsum=Math.max(gsum,lsum); } return gsum; } static void print(char A[]) { for(char c:A)System.out.print(c); System.out.println(); } static void print(boolean A[]) { for(boolean c:A)System.out.print(c+" "); System.out.println(); } static void print(int A[]) { for(int a:A)System.out.print(a+" "); System.out.println(); } static void print(long A[]) { for(long i:A)System.out.print(i+ " "); System.out.println(); } static void print(ArrayList<Long> A) { for(long a:A)System.out.print(a); System.out.println(); } static void sort(long[] a) //check for long { ArrayList<Long> l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } 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 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*i<=N; i=i+6) if (N%i == 0 || N%(i+2) == 0) return false; return true; } static int i() { return in.nextInt(); } static long l() { return in.nextLong(); } static String S() { return in.next(); } static int[] input(int N){ int A[]=new int[N]; for(int i=0; i<N; i++) { A[i]=in.nextInt(); } return A; } static long[] inputLong(int N) { long A[]=new long[N]; for(int i=0; i<A.length; i++)A[i]=in.nextLong(); return A; } } 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
5fa7ac81a07181364ce360d7ace84da2
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; public class test { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); int t = Integer.parseInt(br.readLine()); for (int i = 0; i < t; i++) { int n = Integer.parseInt(br.readLine()); String[] input = br.readLine().split(" "); long[] h = new long[n]; for (int j = 0; j < n; j++) { h[j] = Long.parseLong(input[j]); } if (solution(h)) { pw.println("YES"); } else { pw.println("NO"); } } pw.flush(); pw.close(); br.close(); } public static boolean solution(long[] h) { long sum = 0; long s = 0; for (int i = 0; i < h.length; i++) { sum += h[i]; s += i; if (sum < s) 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 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
9a6b6a08e8a11df578626a311ee9e775
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 ShiftingStacks { public static void main(String[] args) { new ShiftingStacks().run(); } BufferedReader br; PrintWriter out; long mod = (long) (1e9 + 7), inf = (long) (3e18); class pair { int F, S; pair(int f, int s) { F = f; S = s; } } void solve() { int t = ni(); while(t-- > 0) { // TODO: int n= ni(); boolean pos=true; long suma=0; long sumn=0; for(int i=0; i<n; i++){ long x= nl(); sumn+=i; suma+=x; if(suma<sumn){ pos=false; } } if(pos){ out.println("YES"); } else{ out.println("NO"); } } } // -------- I/O Template ------------- char nc() { return ns().charAt(0); } String nLine() { try { return br.readLine(); } catch(IOException e) { return "-1"; } } double nd() { return Double.parseDouble(ns()); } long nl() { return Long.parseLong(ns()); } int ni() { return Integer.parseInt(ns()); } long[] na(int n) { long a[] = new long[n]; for(int i = 0; i < n; i++) a[i] = nl(); return a; } StringTokenizer ip; String ns() { if(ip == null || !ip.hasMoreTokens()) { try { ip = new StringTokenizer(br.readLine()); if(ip == null || !ip.hasMoreTokens()) ip = new StringTokenizer(br.readLine()); } catch(IOException e) { throw new InputMismatchException(); } } return ip.nextToken(); } void run() { try { if (System.getProperty("ONLINE_JUDGE") == null) { br = new BufferedReader(new FileReader("/media/ankanchanda/Data1/WORKPLACE/DS and CP/Competitive Programming/VSCODE/IO/input.txt")); out = new PrintWriter("/media/ankanchanda/Data1/WORKPLACE/DS and CP/Competitive Programming/VSCODE/IO/output.txt"); } else { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } } catch (FileNotFoundException e) { System.out.println(e); } solve(); out.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 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
5470a18d63bc1d7e7a6770f50d52d744
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.File; import java.io.FileInputStream; import java.io.IOException; import java.io.PrintStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import static java.lang.Math.min; import static java.lang.Math.max; import static java.lang.Math.abs; public class Main { static boolean DEBUG = false; public static void main(String[] args) throws IOException { Comparator<pair> com = (p1, p2) -> ((p1.first > p2.first || (p1.first == p2.first && p1.second > p2.second)) ? 1 : -1); if (System.getProperty("ONLINE_JUDGE") == null) { System.setIn(new FileInputStream(new File("D://program//javaCPEclipse//MyJava//src//MyJava//input.txt"))); // System.setOut(new PrintStream(new File("output.txt"))); System.setErr(new PrintStream(new File("D://program//javaCPEclipse//MyJava//src//MyJava//error.txt"))); DEBUG = true; } Reader fs = new Reader(); PrintWriter pw = new PrintWriter(System.out); int t = fs.nextInt(); while (t-- > 0) { int n = fs.nextInt(); long a[] = new long[n]; for (int i = 0; i < n; i++) a[i] = fs.nextLong(); long sum = 0; boolean ispossible = true; for (int i = 0; i < n; i++) { if (a[i] > i) { sum += abs(i - a[i]); } else if (a[i] == i) { continue; } else { long req = abs(a[i] - i); if(req <= sum) { sum -= req; a[i] += req; }else { ispossible = false; break; } } } pw.println(ispossible ? "YES" : "NO"); debug(sum, "sum"); } fs.close(); pw.close(); } static void debug(int a[], String l) { if (DEBUG) { System.err.print("l-> ["); for (int x : a) System.err.print(x + " "); System.err.println("]"); } } static void debug(long a[], String l) { if (DEBUG) { System.err.print("l-> ["); for (long x : a) System.err.print(x + " "); System.err.println("]"); } } static <T> void debug(HashSet<Integer> a, String l) { if (DEBUG) { System.err.println(l + " -> "); System.err.println(a); } } static void debug(String a, String l) { if (DEBUG) { System.err.println(l + " -> " + a); } } static void debug(StringBuilder a, String l) { if (DEBUG) { System.err.println(l + " -> " + a); } } static <T extends Number, V extends T> void debug(HashMap<T, V> a, String l) { if (DEBUG) { System.err.println(l + " -> "); System.err.println(a); } } static <T extends Number> void debug(T a, String l) { if (DEBUG) { System.err.println(l + " -> " + a); } } static <T extends Number> void debug(T[] a, String l) { if (DEBUG) { System.err.print(l + " -> \n" + "[ "); for (int i = 0; i < a.length; i++) { System.err.print(a[i] + " "); } System.err.println("]"); } } static <T> void debug(ArrayList<T> a, String l) { if (DEBUG) { System.err.print(l + " -> "); System.err.print("[ "); for (T q : a) { System.err.print(q + " "); } System.err.println("]"); } } static boolean primeFactors(long n, long b) { while (n % 2 == 0) { if (b % 2 != 0) return false; n = n / 2; } for (long i = 3; i * i <= n; i = i + 2) { while (n % i == 0) { if (b % i != 0) return false; n = n / i; } } if (n > 2) if (b % n != 0) return false; return true; } public static long __gcd(long a, long b) { if (b != 0) { return __gcd(b, a % b); } else { return a; } } public static int lower_bound(ArrayList<Integer> ar, int k) { int s = 0; int e = ar.size(); while (s != e) { int mid = s + e >> 1; if (ar.get(mid) < k) { s = mid + 1; } else { e = mid; } } if (s == ar.size()) { return -1; } return s; } public static int upper_bound(ArrayList<Integer> ar, int k) { int s = 0; int e = ar.size(); while (s != e) { int mid = s + e >> 1; if (ar.get(mid) <= k) { s = mid + 1; } else { e = mid; } } if (s == ar.size()) { return -1; } return s; } static final int MAXN = (int) 1e7; // stores smallest prime factor for every number static int spf[] = new int[MAXN]; // Calculating SPF (Smallest Prime Factor) for every // number till MAXN. // Time Complexity : O(nloglogn) static void sieve() { spf[1] = 1; for (int i = 2; i < MAXN; i++) // marking smallest prime factor for every // number to be itself. spf[i] = i; // separately marking spf for every even // number as 2 for (int i = 4; i < MAXN; i += 2) spf[i] = 2; for (int i = 3; i * i < MAXN; i++) { // checking if i is prime if (spf[i] == i) { // marking SPF for all numbers divisible by i for (int j = i * i; j < MAXN; j += i) // marking spf[j] if it is not // previously marked if (spf[j] == j) spf[j] = i; } } } // A O(log n) function returning primefactorization // by dividing by smallest prime factor at every step static ArrayList<Integer> getFactorization(int x) { ArrayList<Integer> ret = new ArrayList<>(); while (x != 1) { ret.add(spf[x]); x = x / spf[x]; } return ret; } public static ArrayList<Integer> sieve(int n) { int[] prime = new int[n + 1]; ArrayList<Integer> ans = new ArrayList<Integer>(); for (int p = 2; p <= n; p++) { if (prime[p] == 0) { ans.add(p); for (int i = p * p; i <= n; i += p) { prime[i] = 1; } } } return ans; } 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 next() throws IOException { byte[] buf = new byte[100009]; int cnt = 0, c; while ((c = read()) != -1) { if (c <= ' ') { 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 int[] readArray(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } public int[] readArray(int n, int x) throws IOException { int[] arr = new int[n + x]; for (int i = x; i < n + x; i++) { arr[i] = nextInt(); } return arr; } public ArrayList<Integer> readList(int n) throws IOException { ArrayList<Integer> a = new ArrayList<Integer>(); for (int i = 0; i < n; i++) { a.add(nextInt()); } return a; } public int[][] read2Array(int n, int m) throws IOException { int[][] a = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { a[i][j] = nextInt(); } } return a; } public void close() throws IOException { if (din == null) return; din.close(); } } public static int pow(int base, int index) { if (index == 0) { return 1; } else if (index % 2 == 0) { return pow(base * base, index / 2); } else { return base * pow(base * base, ((index - 1) / 2)); } } public static long pow(long base, long index) { if (index == 0) { return 1; } else if (index % 2 == 0) { return pow(base * base, index / 2); } else { return base * pow(base * base, ((index - 1) / 2)); } } static class pair { long first; long second; pair() { this.first = 0l; this.second = 0l; } pair(long first, long second) { this.first = first; this.second = second; } void make_pair(long first, long second) { this.first = first; this.second = second; } } }
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
849a3809b05732ac2937d399880a20d2
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 static java.lang.Math.min; import static java.lang.Math.max; import static java.lang.Math.abs; public class Main { static boolean DEBUG = false; public static void main(String[] args) throws IOException { if (System.getProperty("ONLINE_JUDGE") == null) { System.setErr(new PrintStream("error.txt")); System.setIn(new FileInputStream("input.txt")); System.setOut(new PrintStream(new File("output.txt"))); DEBUG = true; } Reader fs = new Reader(); PrintWriter pw = new PrintWriter(System.out); int t = fs.nextInt(); while (t-- > 0) { int n = fs.nextInt(); long []a = new long[n + 1]; for (int i = 0 ; i < n ; i++) { a[i] = fs.nextLong(); } for (int i = 0 ; i < n - 1 ; i++) { if (a[i] > i) { a[i + 1] += a[i] - i; a[i] = i; } } boolean flag = true; for (int i = 0 ; i < n - 1 ; i++) { if(a[i + 1] <= a[i]){ flag = false; break; } } if(flag){ pw.println("YES"); } else{ pw.println("NO"); } } pw.close(); fs.close(); } ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// static void Debug(StringBuilder a) { System.err.println("String: " + a + "\n"); } static <T> void Debug(ArrayList<T>a ) { System.err.print("[ "); for (int i = 0 ; i < a.size() ; i++) { System.err.print(a.get(i) + " "); } System.err.println(" ]"); } static void Debug(int a[]) { System.err.println("Array"); System.err.print("[ "); for (int i = 0 ; i < a.length ; i++) { System.err.print(a[i] + " "); } System.err.println(" ]"); } static <T> void Debug(T a) { System.err.println(a + "\n"); } static void Debug(HashSet<Integer>a) { System.err.println("ArrayList"); System.err.println(a + "\n"); } static void Debuga(ArrayList<ArrayList<Integer>>a) { System.err.println("ArrayList of ArrayList"); for (int i = 0 ; i < a.size() ; i++) { System.err.println(a.get(i)); } } static void Debug(int [][]a) { System.err.println("2d Array"); for (int i = 0 ; i < a.length ; i++) { System.err.print("[ "); for (int j = 0 ; j < a[i].length ; j++) { System.err.print(a[i][j] + " "); } System.err.println(" ]"); } } static <T> void Debug(Stack<T>a) { System.err.print(a); } //////////////////////////////////////////////////////////////////////// static void debug(StringBuilder a, String l) { if (DEBUG) { System.err.print(l + "->"); Debug(a); } } static <T> void debug(ArrayList<T>a, String l ) { if (DEBUG) { System.err.print(l + "->"); Debug(a); } } static void debug(int a[], String l) { if (DEBUG) { System.err.print(l + "->"); Debug(a); } } static <T> void debug(T a, String l) { if (DEBUG) { System.err.print(l + "->"); Debug(a); } } static void debug(HashSet<Integer>a, String l) { if (DEBUG) { System.err.print(l + "->"); Debug(a); } } static void debuga(ArrayList<ArrayList<Integer>>a, String l) { if (DEBUG) { System.err.print(l + "->"); Debuga(a); } } static void debug(int [][]a, String l) { if (DEBUG) { System.err.println(l + "->"); Debug(a); } } static <T> void debug(Stack<T>a, String l) { if (DEBUG) { System.err.println(l + "->"); Debug(a); } } //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //******************************************************************************\ //******************************************************************************\ 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[100009]; 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 int[] readArray(int n) throws IOException { int []arr = new int[n]; for (int i = 0 ; i < n ; i++) { arr[i] = nextInt(); } return arr; } public int[] readArray(int n, int x) throws IOException { int []arr = new int[n + x]; for (int i = x ; i < n + x ; i++) { arr[i] = nextInt(); } return arr; } public ArrayList<Integer> readList(int n) throws IOException { ArrayList<Integer>a = new ArrayList<Integer>(); for (int i = 0 ; i < n ; i++) { a.add(nextInt()); } return a; } public int[][] read2Array(int n, int m)throws IOException { int [][]a = new int[n][m]; for (int i = 0 ; i < n ; i++) { for (int j = 0 ; j < m ; j++) { a[i][j] = nextInt(); } } return a; } public void close() throws IOException { if (din == null) return; din.close(); } } public static int __gcd(int a, int b) { if ( b != 0) { return __gcd(b, a % b); } else { return a; } } public static ArrayList<Integer> sieve(int n) { int []prime = new int[n + 1]; ArrayList<Integer>ans = new ArrayList<Integer>(); for (int p = 2; p <= n ; p++) { if (prime[p] == 0) { ans.add(p); for (int i = p * p ; i <= n ; i += p) { prime[i] = 1; } } } return ans; } public static int pow(int base, int index) { if (index == 0) { return 1; } else if (index % 2 == 0) { return pow(base * base, index / 2); } else { return base * pow(base * base, ((index - 1) / 2)); } } public static long pow(long base, long index) { if (index == 0) { return 1; } else if (index % 2 == 0) { return pow(base * base, index / 2); } else { return base * pow(base * base, ((index - 1) / 2)); } } static class pair { int first; int second; pair(int first, int second) { this.first = first; this.second = second; } } }
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
3991948a786f479198a909704fb3b523
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
// Piyush Nagpal import java.util.*; import java.io.*; public class C{ static int MOD=1000000007; static PrintWriter pw; static FastReader sc; 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());} public char nextChar() throws IOException {return next().charAt(0);} String nextLine(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int[] intArr(int n) throws IOException {int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();return in;} public long[] longArr(int n) throws IOException {long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();return in;} } public static long gcd(long a,long b){if( b>a ){return gcd(b,a);}if( b==0 ){return a;} return gcd(b,a%b);} public static long expo( long a,long b,long M ){long result=1;while(b>0){if( b%2==1 ){result=(result*a)%M;}a=(a*a)%M;b=b/2;}return result%M;} public static ArrayList<Long> Sieve(int n){boolean [] arr= new boolean[n+1];Arrays.fill(arr, true);ArrayList<Long> list= new ArrayList<>();for(int i=2;i<=n;i++){if( arr[i]==true ){list.add((long)i);}for(int j=2*i;j<=n;j+=i){arr[j]=false;}}return list;} public static void printarr(int [] arr){for(int i=0;i<arr.length;i++){pw.print(arr[i]+" ");}} public static void printarr(long [] arr){for(int i=0;i<arr.length;i++){pw.print(arr[i]+" ");}} // int [] arr=sc.intArr(n); static void solve() throws Exception{ int n=sc.nextInt(); long [] arr= new long [n+1]; for(int i=0;i<n;i++){ arr[i]=sc.nextInt(); } for(int i=0;i<n;i++){ if(arr[i]>=i){ arr[i+1]+=arr[i]-i; arr[i]=i; }else{ // printarr(arr); pw.println("NO"); return; } } // printarr(arr); pw.println("YES"); } public static void main(String[] args) throws Exception{ try { System.setIn(new FileInputStream("input.txt")); System.setOut(new PrintStream(new FileOutputStream("output.txt"))); } catch (Exception e) { System.err.println("Error"); } sc= new FastReader(); pw = new PrintWriter(System.out); int tc=1; tc=sc.nextInt(); for(int i=1;i<=tc;i++) { // pw.printf("Case #%d: ", i); solve(); } pw.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 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
2a2999bd354a99ca6a8def3371bc8762
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 static java.lang.Math.min; import static java.lang.Math.abs; import static java.lang.Math.max; import java.io.*; public class EdE { static long[] mods = {1000000007, 998244353, 1000000009}; static long mod = mods[0]; public static MyScanner in; public static PrintWriter out; static int[][] dp; static ArrayList<ArrayList<Integer>> tree; public static void main( String[] args ) throws IOException{ in = new MyScanner(); out = new PrintWriter(System.out); StringBuilder ans1=new StringBuilder(); int test=in.nextInt(); while(test-->0) { int n=in.nextInt(); long a[]=readArrayLong(n); String ans=""; //Arrays.sort(a); long extra=0; boolean ok = true; long rest = 0; for (int i=0; i<n; i++) { rest += a[i]; rest -= i; if (rest < 0) { ok = false; break; } } ans=(ok ? "YES" : "NO"); ans1.append(ans).append(System.getProperty("line.separator")); } out.println(ans1); out.close(); } public static boolean valid(String s) { Stack<Character> stack=new Stack<>(); char ch[]=s.toCharArray(); for(int i=0;i<ch.length;i++) { if(ch[i]=='(') stack.push('('); else if(ch[i]==')') { if(stack.peek()==')') return false; else stack.pop(); } } return (stack.isEmpty()); } //comparator to solve according to b in descending order static class Pair implements Comparable<Pair>{ private long a; private long b; public Pair(long a, long b) { this.a = a; this.b = b; } public int compareTo(Pair other) { //return Long.compare(this.b, other.b ); //to sort in ascending order swap the arguments in Long.compare return Long.compare(other.b ,this.b); //to sort in descending order swap the arguments in Long.compare } } static void printArray(long[] a) { StringBuilder stringBuilder=new StringBuilder(); for(long i: a) stringBuilder.append(i).append(" "); out.println(stringBuilder); } public static void sort(long[] array){ ArrayList<Long> copy = new ArrayList<>(); for (long i : array) copy.add(i); Collections.sort(copy); for(int i = 0;i<array.length;i++) array[i] = copy.get(i); } public static void sortDes(long[] array){ ArrayList<Long> copy = new ArrayList<>(); for (long i : array) copy.add(i); Collections.sort(copy); int j=array.length-1; for(int i = 0;i<array.length;i++) array[j--] = copy.get(i); } static String[] readArrayString(int n){ String[] array = new String[n]; for(int j =0 ;j<n;j++) array[j] = in.next(); return array; } static int[] readArrayInt(int n){ int[] array = new int[n]; for(int j = 0;j<n;j++) array[j] = in.nextInt(); return array; } static int[] readArrayInt1(int n){ int[] array = new int[n+1]; for(int j = 1;j<=n;j++){ array[j] = in.nextInt(); } return array; } static long[] readArrayLong(int n){ long[] array = new long[n]; for(int j =0 ;j<n;j++) array[j] = in.nextLong(); return array; } static double[] readArrayDouble(int n){ double[] array = new double[n]; for(int j =0 ;j<n;j++) array[j] = in.nextDouble(); return array; } static int minIndex(int[] array){ int minValue = Integer.MAX_VALUE; int minIndex = -1; for(int j = 0;j<array.length;j++){ if (array[j] < minValue){ minValue = array[j]; minIndex = j; } } return minIndex; } static int minIndex(long[] array){ long minValue = Long.MAX_VALUE; int minIndex = -1; for(int j = 0;j<array.length;j++){ if (array[j] < minValue){ minValue = array[j]; minIndex = j; } } return minIndex; } static int minIndex(double[] array){ double minValue = Double.MAX_VALUE; int minIndex = -1; for(int j = 0;j<array.length;j++){ if (array[j] < minValue){ minValue = array[j]; minIndex = j; } } return minIndex; } static boolean isPrime(int 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 * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static ArrayList<Integer> sieveOfEratosthenes(int n) { ArrayList<Integer> al = new ArrayList<>(); boolean prime[] = new boolean[n + 1]; for (int i = 0; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } for (int i = 2; i <= n; i++) { if (prime[i] == true) al.add(i); } return al; } static long power(long x, long y){ if (y == 0) return 1; if (y%2 == 1) return (x*power(x, y-1))%mod; return power((x*x)%mod, y/2)%mod; } static void verdict(boolean a){ out.println(a ? "YES" : "NO"); } public static 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 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
ef3d059a1611ff659da3d8b7b36e9405
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.math.*; import java.util.*; public class apples{ 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; } char nextchar() { char ch = ' '; try { ch = (char) br.read(); } catch (IOException e) { e.printStackTrace(); } return ch; } } public static void main(String[] args) { FastReader x = new FastReader(); StringBuilder str = new StringBuilder(); int t=x.nextInt(); while(t>0) { int n=x.nextInt(); int a[]=new int[n]; long s=0,f=0;long m=0; for (int i = 0; i < n; i++) { a[i]=x.nextInt(); } for (int i = 0; i < n; i++) { s+=a[i]; m=(i*(i+1))/2; if(s<m) { f=1; break; } } if(f==0) { str.append("YES"); } else { str.append("NO"); } str.append("\n"); t--; } System.out.println(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
4ceb05f60d980fc71d91372faac8d1c6
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; /*package whatever //do not write package name here */ public final class Solution { public static void main(String[] args) throws IOException { BufferedReader bi = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(bi.readLine()); while (t > 0) { int n = Integer.parseInt(bi.readLine()); String s[] = bi.readLine().split(" "); long rem = 0; boolean fail = false; for (int i = 0; i < n; i++) { long h = Long.parseLong(s[i]); if (rem + h < i) { fail = true; break; } rem += Long.parseLong(s[i]) - i; } if (fail) { System.out.println("NO"); } else { System.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
PASSED
9452184e8110a3dbc14efeee91aee189
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 A { public static void main(String[] args) { // TODO Auto-generated method stub FastScanner sc = new FastScanner(); 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 avail = a[0]; boolean res = true; for(int i = 1 ;i < n ; i++) { avail += a[i]; if(avail < i) { //System.out.println(avail + " " + i); res = false; break; } avail -= i; } if(res) { System.out.println("YES"); } else { System.out.println("NO"); } } } 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()); } } // Use this instead of Arrays.sort() on an array of ints. Arrays.sort() is n^2 // worst case since it uses a version of quicksort. Although this would never // actually show up in the real world, in codeforces, people can hack, so // this is needed. 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); } }
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
de6026949b6ccc7222054dc6e9005728
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 Question1 { public static void main(String args[]) { Scanner in=new Scanner(System.in); int t=in.nextInt(); int i,j; while(t-->0) { int n=in.nextInt(); //int k=in.nextInt(); long a[]=new long[n]; long sum=0,c=0; for(i=0;i<n;i++) { a[i]=in.nextLong(); // sum=sum+(a[i]-i); // if(sum<0) // { // c++; // System.out.println("No"); // break; // } } long x=0; for(i=0;i<n-1;i++) { x=a[i]-i; a[i]=i; if(x>0) a[i+1]=a[i+1]+x; if(x<0) break; } if(x<0) System.out.println("No"); else { c=0; for(i=0;i<n;i++) { if(a[i]<i) c++; } //System.out.println(sum); if(c==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
cbeb25008c3edac9a398afd0a041b4b8
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 void main(String[] args) { FastScanner sc = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = sc.nextInt(); while(t-- != 0) { int n = sc.nextInt(); int[] arr = sc.readArray(n); if(solve(arr, n)) out.println("YES"); else out.println("NO"); } out.close(); } static boolean solve(int[] arr, int n) { long sum = 0; long need = 0; for(int i=0; i<n; i++) { need += i; sum += arr[i]; if(sum < need) return false; } return true; } 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(); } public String nextLine() { try { return br.readLine(); } catch (Exception e) { e.printStackTrace(); } return null; } 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
503c1c30620398e7c1bae19548048dc8
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 void main(String[] args) { FastScanner sc = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = sc.nextInt(); while(t-- != 0) { int n = sc.nextInt(); int[] arr = sc.readArray(n); if(solve(arr, n)) out.println("YES"); else out.println("NO"); } out.close(); } static boolean solve(int[] arr, int n) { long sum = 0; for(int i=0; i<n; i++) { sum += arr[i]; if(sum < i) return false; sum -= i; } return true; } 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(); } public String nextLine() { try { return br.readLine(); } catch (Exception e) { e.printStackTrace(); } return null; } 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
68ba8b74f1a49bd6b10671ea8c583ab3
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 void main(String[] args) { FastScanner sc = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = sc.nextInt(); while(t-- != 0) { int n = sc.nextInt(); int[] arr = sc.readArray(n); if(solve(arr, n)) out.println("YES"); else out.println("NO"); } out.close(); } static boolean solve(int[] arr, int n) { long sum = 0; for(int i=0; i<n; i++) { if(sum + arr[i] >= i) { // System.out.println(sum); sum += arr[i] - i; } else { return false; } } // System.out.println(sum); return true; } 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(); } public String nextLine() { try { return br.readLine(); } catch (Exception e) { e.printStackTrace(); } return null; } 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
c128daeb26a3c0a9e575097192926c8e
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.*; import java.lang.*; import java.util.Arrays; public class geek { public static void main(String[] args) { Scanner s=new Scanner(System.in); try{ int t=s.nextInt(); StringBuffer sb=new StringBuffer(); while (t-->0){ int n=s.nextInt(); //int count=0; boolean flag=true; long sum=0,temp=0; long a[]=new long[n]; for(int i=0;i<n;i++){ a[i]=s.nextLong(); } for(int i=0;i<n;i++){ sum+=a[i]; temp+=i; if(temp>sum){ flag=false; sb.append("NO\n"); break; } } if(flag)sb.append("YES\n"); } System.out.println(sb); //solve.show(a); // solve.show(b); }catch (Exception e){ System.out.println(e.getMessage()); } } }
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
2ba98afaea9e11158f46cd8952d18662
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 Scanner scammer = new Scanner(System.in); public static void solve(){ int n = scammer.nextInt(); long rest = 0; boolean bad = false; for(int i = 0; i < n; ++i){ long w = scammer.nextLong(); if(w + rest < i) bad = true; if(w < i) rest -= i - w; else rest += (w - i); } if(bad) System.out.println("NO"); else System.out.println("YES"); } public static void main(String[] args) { int test_cases = scammer.nextInt(); while(test_cases > 0){ solve(); --test_cases; } } }
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
2187b4de3186aa95caafcfe75859a51d
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 codeforcesQuestions; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.*; public class cdf703a { static void merge(int arr[], int l, int m, int r) { int n1 = m - l + 1; int n2 = r - m; int L[] = new int [n1]; int R[] = new int [n2]; for (int i=0; i<n1; ++i) L[i] = arr[l + i]; for (int j=0; j<n2; ++j) R[j] = arr[m + 1+ j]; int i = 0, j = 0; int k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } while (i < n1) { arr[k] = L[i]; i++; k++; } while (j < n2) { arr[k] = R[j]; j++; k++; } } static void sort(int arr[], int l, int r) { if (l < r) { int m = (l+r)/2; sort(arr, l, m); sort(arr , m+1, r); merge(arr, l, m, r); } } public static int lowerBound(int[] array, int length, int value) { int low = 0; int high = length; while (low < high) { final int mid = (low + high) / 2; //checks if the value is less than middle element of the array if (value <= array[mid]) { high = mid; } else { low = mid + 1; } } return low; } public static int upperBound(int[] array, int length, int value) { int low = 0; int high = length; while (low < high) { final int mid = (low + high) / 2; if (value >= array[mid]) { low = mid + 1; } else { high = mid; } } return low; } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } static long power(long n,long m) { if(m==0) return 1; long ans=1; while(m>0) { ans=ans*n; m--; } return ans; } static int BinarySearch(int arr[], int x) { int l = 0, r = arr.length - 1; while (l <= r) { int m = l + (r - l) / 2; if (arr[m] == x) return m; if (arr[m] < x) l = m + 1; else r = m - 1; } return -1; } public static void main(String args[])throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine()); out:for(int i=1;i<=t;i++) { int n=Integer.parseInt(br.readLine()); long arr[]=new long[n]; String s=br.readLine(); String str[]=s.split(" "); for(int j=0;j<n;j++) arr[j]=Integer.parseInt(str[j]); for(int j=0;j<n;j++) { if(arr[j]<j) { System.out.println("NO"); continue out; } else if(j<n-1) arr[j+1]+=arr[j]-j; } // if(sum>=temp) 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
25035d3df0b4dc68ba626b5e40525066
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) { 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
08f32265b5881ef89f3b2984c8f013b4
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.FileNotFoundException; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Scanner; public class Main { static Scanner in = new Scanner(System.in); // static Scanner in = new Scanner( new File("javain.txt")); public static void main(String[] args) throws FileNotFoundException { if(args.length > 0){ in = new Scanner( new File("javain.txt")); } int t = in.nextInt(); for(int i = 0; i < t; i++){ solve(); } } public static void solve(){ int n = in.nextInt(); long cnt = 0; boolean flag = true; for(int i = 0; i < n; i++){ cnt += in.nextInt(); if(cnt < i * (i + 1) / 2){ flag = false; } } System.out.println(flag ? "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
e0864bc0523ab14ee6e3281bea9703a2
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 whatever //do not write package name here */ import java.util.*; import java.lang.*; import java.io.*; public class GFG{ 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 n=sc.nextInt(); for(int g=0;g<n;g++){ int size=sc.nextInt(); int a[]=new int[size]; for(int i=0;i<size;i++){ a[i]=sc.nextInt(); } int i=0; long sum=0; for(i=0;i<size;i++){ if(a[i]>i){ sum=sum+(a[i]-i); } else if(a[i]==i) continue; else{ if(sum+a[i]<i){ break; }else{ sum=sum-(i-a[i]); } } } if(i==size){ 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
59ef625458eca5012d962d7e10f67c28
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.math.*; import java.security.*; import java.text.*; import java.time.LocalTime; import java.util.*; import java.util.concurrent.*; import java.util.regex.*; import java.math.*; public class A { public static void main(String[] args) { FastScanner scan = new FastScanner(); int t = scan.nextInt(); for(int tt=0; tt<t; tt++) { int n =scan.nextInt(); int [] a = scan.readArray((int) n); boolean works = true; long sum = 0; for(int i=0; i<n; i++) { sum += a[i]; if(sum < (i) * (i+1) / 2) works = false; } System.out.println(works ? "YES" : "NO"); } } public static void sort(int [] a) { ArrayList<Integer> b = new ArrayList<>(); for(int i: a) b.add(i); Collections.sort(b); for(int i=0; i<a.length; i++) a[i]= b.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
5b6670a1a58efc94bcbf9fc98578f16d
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.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.*; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Task solver = new Task(); solver.solve(1, in, out); out.close(); } static class Task { public void solve(int testNumber, InputReader in, PrintWriter out) { int t = in.nextInt(); for (int i = 0; i < t; i++) { int n = in.nextInt(); long rest = 0; int last = -1; boolean fail = false; for (int j = 0; j < n; j++) { int h = in.nextInt(); if(fail) continue; int should = last + 1; if (h + rest < should ) { fail = true; }else{ rest = rest + h - should; last = should; } } if (!fail) out.println("YES"); else out.println("NO"); } } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public Long nextLong() { return Long.parseLong(next()); } public 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
2665f7ba30c66a7a30413dd7d0a7c59b
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.util.concurrent.ConcurrentHashMap; //_________________________________________________________________ public class Main { public static void main(String[] args) throws IOException { File file = new File("input.txt"); FastScanner sc = new FastScanner(); // Scanner sc= new Scanner(file); PrintWriter out = new PrintWriter(System.out); int t=sc.nextInt(); outer:while (t-->=1) { int n=sc.nextInt(); int a[]=sc.readArray(n); long sum=0; for (int i=0;i<n;i++){ sum+=a[i]; int sub=i*(i+1)/2; if (sum<sub){ System.out.println("NO"); continue outer; } } System.out.println("YES"); } out.flush(); } //------------------------------------if------------------------------------------------------------------------------------------------------------------------------------------------- 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 String sortString(String s) { char temp[] = s.toCharArray(); Arrays.sort(temp); return new String(temp); } static class Pair implements Comparable<Pair> { long a; int b; public Pair(long a, int b) { this.a = a; this.b = b; } // to sort first part public int compareTo(Pair other) { if (this.a == other.a) return other.b > this.b ? -1 : 1; else if (this.a > other.a) return 1; else return -1; } // public int compareTo(Pair other) { // if (this.b == other.b) return 0; // if (this.b < other.b) return 1; // else return -1; // } //sort on the basis of first part only // public int compareTo(Pair other) { // if (this.a == other.a) return 0; // else if (this.a > other.a) return 1; // else return -1; // } } static int[] frequency(String s){ int fre[]= new int[26]; for (int i=0;i<s.length();i++){ fre[s.charAt(i)-'a']++; } return fre; } static int mod =(int)1e9; static long mod(long x) { return ((x % mod + mod) % mod); } static long add(long x, long y) { return mod(mod(x) + mod(y)); } static long mul(long x, long y) { return mod(mod(x) * mod(y)); } static int[] find(int n, int start, int diff) { int a[] = new int[n]; a[0] = start; for (int i = 1; i < n; i++) a[i] = a[i - 1] + diff; return a; } static void swap(int a, int b) { int c = a; a = b; b = c; } static void printArray(int a[]) { for (int i = 0; i < a.length; i++) { System.out.print(a[i] + " "); } } static boolean sorted(int a[]) { int n = a.length; boolean flag = true; for (int i = 0; i < n - 1; i++) { if (a[i] > a[i + 1]) flag = false; } if (flag) return true; else return false; } public static int findlog(long n) { if (n == 0) return 0; if (n == 1) return 0; if (n == 2) return 1; double num = Math.log(n); double den = Math.log(2); if (den == 0) return 0; return (int) (num / den); } public static long gcd(long a, long b) { if (b % a == 0) return a; return gcd(b % a, a); } public static int gcdInt(int a, int b) { if (b % a == 0) return a; return gcdInt(b % a, a); } static void sortReverse(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); // Collections.sort.(l); Collections.sort(l, Collections.reverseOrder()); 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[] readArrayLong(long n) { long[] a = new long[(int) n]; for (int i = 0; i < n; i++) a[i] = nextLong(); 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
81a9e08c8e39e3f73c09b0daf240c1ed
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 scan = new Scanner(System.in); int t = scan.nextInt(); while(t-- > 0) { long n = scan.nextInt(); long sum =0; boolean flag =false; for(int i=0;i<n;i++) { sum += scan.nextLong(); if(sum < (i*(i+1)/2)) flag = true; } 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
71d571c2e4be7d85f77319dc4c5c51bf
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 ProblemA { public static void main(String[] args) throws Exception{ // TODO Auto-generated method stub Scanner input = new Scanner(System.in); int test = input.nextInt(); StringBuilder sb = new StringBuilder(); while(test-->0){ int n= input.nextInt(); long arr[] = new long[n]; String ans = "NO"; long sum = 0; for(int i=0;i<n;i++){ arr[i] = input.nextLong(); } for(int i =0;i<n-1;i++){ arr[i+1] += arr[i] - Math.min(arr[i], i); arr[i] = Math.min(i,arr[i]); } if(check(arr))ans = "YES"; sb.append(ans); sb.append("\n"); } System.out.println(sb); } public static boolean check(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 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
d378addd59ed2ab31da78358404bdad5
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{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); long t = sc.nextLong(); while(t-->0){ long n = sc.nextLong(); long[] arr = new long[(int)n]; for(int i=0; i<n; i++){ arr[i] = sc.nextLong(); } String ans = res(arr, n); System.out.println(ans); } } static String res(long[] arr, long n){ long temp = 0; long sum = 0; for(int i=0; i<n; i++){ temp += i; sum += arr[i]; if(sum < temp){ 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
201a5faaa28520ef089a0873284f3c82
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) { //System.out.println("Hello World"); Scanner sc = new Scanner(System.in); int t= sc.nextInt(); while(t!=0){ int n = sc.nextInt(); int [] s= new int[n]; for(int i=0;i<s.length;i++) s[i]=sc.nextInt(); int j=1; int prev=0; long sum=s[0]; while(j<s.length){ int temp=((j)*(j+1))/2; sum+=s[j]; if(sum<temp) { System.out.println("NO"); break; } j++; } if(j==n) System.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
PASSED
acf36ddfa8b842ad58ab4b05d0869052
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.util.Arrays; public class codeforces { public static void main(String[] args) throws Exception { int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int[]a=sc.nextArrint(n); long over=0; boolean flag=true; for (int i = 0; i < a.length; i++) { if(a[i]>=i)over+=a[i]-i; else { if(over>=(i-a[i])) { over-=(i-a[i]); }else { flag=false; break; } } } pw.println(flag?"YES":"NO"); } pw.close(); } static void merge(int[] arr,int b,int m,int e) { int len1=m-b+1,len2=e-m; int[] l=new int[len1]; int[] r=new int[len2]; for(int i=0;i<len1;i++)l[i]=arr[b+i]; for(int i=0;i<len2;i++)r[i]=arr[m+1+i]; int i=0,j=0,k=b; while(i<len1 && j<len2) { if(l[i]<r[j])arr[k++]=l[i++]; else arr[k++]=r[j++]; } while(i<len1)arr[k++]=l[i++]; while(j<len2)arr[k++]=r[j++]; return; } static void mergesort(int[] arr,int b,int e) { if(b<e) { int m=(b+e)/2; mergesort(arr,b,m); mergesort(arr,m+1,e); merge(arr,b,m,e); } return; } static long mergen(int[] arr,int b,int m,int e) { int len1=m-b+1,len2=e-m; int[] l=new int[len1]; int[] r=new int[len2]; for(int i=0;i<len1;i++)l[i]=arr[b+i]; for(int i=0;i<len2;i++)r[i]=arr[m+1+i]; int i=0,j=0,k=b; long c=0; while(i<len1 && j<len2) { if(l[i]<r[j])arr[k++]=l[i++]; else { arr[k++]=r[j++]; c=c+(long)(len1-i); } } while(i<len1)arr[k++]=l[i++]; while(j<len2)arr[k++]=r[j++]; return c; } static long mergesortn(int[] arr,int b,int e) { long c=0; if(b<e) { int m=(b+e)/2; c=c+(long)mergesortn(arr,b,m); c=c+(long)mergesortn(arr,m+1,e); c=c+(long)mergen(arr,b,m,e); } return c; } public static long fac(int n) { if(n==0)return 1; return n*fac(n-1); } public static long summ(long x) { long sum=0; while(x!=0) { sum+=x%10; x=x/10; } return sum; } public static void sort2darray(Integer[][]a){ Arrays.sort(a,Comparator.<Integer[]>comparingInt(x -> x[0]).thenComparingInt(x -> x[1])); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(String file) throws FileNotFoundException { br = new BufferedReader(new FileReader(file)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public boolean ready() throws IOException { return br.ready(); } public int[] nextArrint(int size) throws IOException { int[] a=new int[size]; for (int i = 0; i < a.length; i++) { a[i]=sc.nextInt(); } return a; } public long[] nextArrlong(int size) throws IOException { long[] a=new long[size]; for (int i = 0; i < a.length; i++) { a[i]=sc.nextLong(); } return a; } public int[][] next2dArrint(int rows,int columns) throws IOException{ int[][]a=new int[rows][columns]; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { a[i][j]=sc.nextInt(); } } return a; } public long[][] next2dArrlong(int rows,int columns) throws IOException{ long[][]a=new long[rows][columns]; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { a[i][j]=sc.nextLong(); } } return a; } } static Scanner sc=new Scanner(System.in); static PrintWriter pw=new PrintWriter(System.out); }
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
7a483633c7f9b00e9891af4134e8067c
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.io.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class Shiftingstacks { public static void main(String[] args) throws IOException { BufferedReader f = new BufferedReader(new InputStreamReader(System.in)); int n= Integer.parseInt(f.readLine()); int j=1; for(int i=0; i<n;i++) { int n2 = Integer.parseInt(f.readLine()); long[] stack = new long[n2]; StringTokenizer st = new StringTokenizer(f.readLine()); for(int k=0;k<n2;k++) { stack[k]=Long.parseLong(st.nextToken()); } while(j<=n2 && (arraySum(j-1, stack) >= ((j)*(j-1)/2))) { j+=1; } if(j==n2+1) { System.out.println("YES"); } else { System.out.println("NO"); } j=1; } } public static long arraySum(int n, long[] array) { long sum=0; for(int i=0;i<=n;i++) { sum+=array[i]; } return sum; } }
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
0786f8efc70b710fc7bf44766de92160
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.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; public class A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { long n = sc.nextLong(); long arr[] = new long[(int) n]; long zero = 0, one = 0; // for (int i = 0; i < n; i++) { // arr[i] = sc.nextLong(); // if (arr[i] == 0) { // zero++; // } else { // one++; // } // } // Arrays.sort(arr); // for (int i = 0; i < n - 1; i++) { // if (arr[i] >= arr[i + 1]) { // arr[i] = arr[i] - 1; // arr[i + 1] = arr[i + 1] + 1; // } // } // System.out.println(Arrays.toString(arr)); boolean check = true; long sum=0; for (int i = 1; i <= n; ++i) { int a; a=sc.nextInt(); sum += a; if (sum < ((long) i * (i - 1)) / 2) check= false; } if (check) { System.out.println("YES"); } else { System.out.println("NO"); // for (int i = 0; i < arr.length - 1; i++) { // if (arr[i] < arr[i + 1] && arr[i] >= 0 && arr[i + 1] >= 0) { // // } else { // check = false; // break; // } // } // if (check) { // System.out.println("YES"); // } else { // System.out.println("NO"); // } //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
25c4d1ebdbe9601755432a3f45013c9a
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 Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // FastOutput out = new FastOutput(System.out); for(int T = sc.nextInt(); T > 0; --T) { int n = sc.nextInt(); long[] nums = new long[n]; for(int i = 0; i < n; ++i) { nums[i] = sc.nextLong(); } boolean flag = true; long sum = 0; for(int i = 0; i < n; ++i) { if(nums[i] > i) sum += nums[i] - i; else { sum -= i - nums[i]; } if(sum < 0) { flag = false; break; } } System.out.println(flag ? "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
bc9596e8fc9329bb4e3a647c936ec1f9
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 Codechef{ static final int mod = 1000000007; static FastReader sc = new FastReader(); static List< List<Integer>> adjacency; static Map<Integer, Integer> snack; static Map<Integer, Integer> ladder; static long grid[][]; static int dp[][]; static List<Integer> primes; static int heights[]; static int[] tree, arr, frequency; static Map<Integer, Long> map = new HashMap<>(); static long left; static int block_size = 300, count = 0; static List<String> list; public static void main(String args[]) throws Exception{ int t = sc.nextInt(); StringBuilder res = new StringBuilder(); while(t-- > 0){ long n = sc.nextLong(); long a[] = sc.inputArray(n); long sum = 0; int i = 0; boolean flag = true; while(i < n){ // System.out.println(((i*(i+1))/2 ) +" "+ sum); sum += a[i]; if( ((i*(i+1))/2 ) > sum){ flag = false; break; } i++; } if(flag){ res.append("YES\n"); } else{ res.append("NO\n"); } } System.out.println(res); } static class DSU{ int[] parent, rank; public DSU(int v){ parent = new int[v]; rank = new int[v]; for(int i=0; i<v; i++){ parent[i] = -1; rank[i] = 1; } } int findParent(int u){ if(parent[u] == -1) return u; parent[u] = findParent(parent[u]); return parent[u]; } void union(int u, int v){ u = findParent(u); v = findParent(v); if(u == v) return; if(rank[u] < rank[v]){ parent[u] = v; rank[v] += rank[u]; } else{ parent[v] = u; rank[u] += v; } } } 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()); } char nextChar(){ return next().charAt(0); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } void print( char output){ System.out.print(output + " "); } void print( int output){ System.out.print(output + " "); } void print( long output){ System.out.print(output + " "); } void print( double output){ System.out.print(output + " "); } void print(String output){ System.out.print(output); } void print(StringBuilder output){ System.out.print(output); } void println( char output){ System.out.println(output); } void println( int output){ System.out.println(output); } void println( long output){ System.out.println(output); } void println(double output){ System.out.println(output); } void println(String output){ System.out.println(output); } void println(StringBuilder output){ System.out.println(output); } void printArray(char arr[]){ StringBuilder str = new StringBuilder(); int n = arr.length; for(int i=0; i<n; i++){ str.append(arr[i]+" "); } System.out.println(str); } void printArray(int arr[]){ StringBuilder str = new StringBuilder(); int n = arr.length; for(int i=0; i<n; i++){ str.append(arr[i]+" "); } System.out.println(str); } void printArray(Integer arr[]){ StringBuilder str = new StringBuilder(); int n = arr.length; for(int i=0; i<n; i++){ str.append(arr[i]+" "); } System.out.println(str); } void printArray(boolean arr[]){ StringBuilder str = new StringBuilder(); int n = arr.length; for(int i=0; i<n; i++){ str.append(arr[i]+" "); } System.out.println(str); } void printArray(int arr[], int fromIndex){ StringBuilder str = new StringBuilder(); int n = arr.length; for(int i=fromIndex; i<n; i++){ str.append(arr[i]+" "); } System.out.println(str); } void printArray(long arr[]){ StringBuilder str = new StringBuilder(); int n = arr.length; for(int i=0; i<n; i++){ str.append(arr[i]+" "); } System.out.println(str); } void printArray(double arr[]){ StringBuilder str = new StringBuilder(); int n = arr.length; for(int i=0; i<n; i++){ str.append(arr[i]+" "); } System.out.println(str); } void printArray(int arr[][]){ StringBuilder str = new StringBuilder(); int n = arr.length; int m = arr[0].length; for(int i=0; i<n; i++){ for(int j = 0; j<m; j++){ str.append(arr[i][j]+" "); } str.append("\n"); } System.out.println(str); } void printArray(long arr[][]){ StringBuilder str = new StringBuilder(); int n = arr.length; int m = arr[0].length; for(int i=0; i<n; i++){ for(int j = 0; j<m; j++){ str.append(arr[i][j]+" "); } str.append("\n"); } System.out.println(str); } void printArray(double arr[][]){ StringBuilder str = new StringBuilder(); int n = arr.length; int m = arr[0].length; for(int i=0; i<n; i++){ for(int j = 0; j<m; j++){ str.append(arr[i][j]+" "); } str.append("\n"); } System.out.println(str); } void printGraph(List<List<Integer>> G){ int nodes = G.size(); for(int i=0; i<nodes; i++){ System.out.print(i+"-> "); for(int j : G.get(i)){ System.out.print(j+" "); } System.out.println(); } } static long pow(long base, int p, int mod_){ if(p == 0) return 1; long m = (base * base ) % mod; if(p % 2 == 0){ return pow(m, p/2)%mod; } else return (base * pow(m , p/2) ) % mod ; } static long pow(long base, int p){ if(p == 0) return 1; long product = base * base ; if(p % 2 == 0){ return pow(product, p/2); } else return base * pow(product , p/2) ; } static int max(int arr[]){ int len = arr.length; int max = Integer.MIN_VALUE; for(int i=0; i<len; i++){ if( max < arr[i]){ max = arr[i]; } } return max; } static int[] inputArray(int n){ int arr[] = new int[n]; for(int i=0; i<n; i++){ arr[i] = sc.nextInt(); } return arr; } static int[] inputArray(int n, int fromIndex){ int size = n + fromIndex; int arr[] = new int[size]; for(int i=fromIndex; i<size; i++){ arr[i] = sc.nextInt(); } return arr; } static long[] inputArray(long n){ long arr[] = new long[(int)n]; for(int i=0; i<n; i++){ arr[i] = sc.nextLong(); } return arr; } static long[] inputArray(long n, int fromIndex){ int size = (int)n + fromIndex; long arr[] = new long[size]; for(int i=fromIndex; i<size; i++){ arr[i] = sc.nextLong(); } return arr; } static double[] inputArray(double n, int fromIndex){ int size = (int)n + fromIndex; double arr[] = new double[size]; for(int i=fromIndex; i<size; i++){ arr[i] = sc.nextDouble(); } return arr; } static List<Integer> findPrimes(int n){ int sieve[] = new int[n+1]; for(long i = 2; i<= n; i++){ if(sieve[(int)i] == 0){ for(long j = i*i; j <= n; j += i){ sieve[(int)j] = 1; } } } List<Integer> primes = new ArrayList<>(); for(int i=2; i<=n ; i++){ if(sieve[i] == 0){ primes.add(i); } } return primes; } } }
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
72521b380b3590ed9f6fb6a35c54f1cc
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 pvv { public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); // System.out.print("*"); for (int h = 0; h < t; h++) { //int ar[] = new int[200]; int n=s.nextInt();long sum=0; int ar[]=new int[n]; for(int i=0;i<n;i++){ // long d=x2; ar[i]=s.nextInt(); }sum=ar[0];int f=0;int x=0; for(int i=1;i<n;i++) { sum=sum+(long)ar[i]+0L; x=x+i; if (sum < x) { f = 1; break; } } if(f==0) System.out.println("yes"); else System.out.println("no"); //int sum = 0; // } //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 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
29c409cf066a2cff1c583389d80729ee
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.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.*; public class pcarp{ static int max_value; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); outer : while(t-->0){ int n = sc.nextInt(); long[] arr = new long[n]; for(int i=0;i<n;i++){ arr[i]=sc.nextLong(); } long a = arr[0]; for (int i = 1; i < n; i++) { if (arr[i] < i) { a =a- (i - arr[i]); if (a < 0) { System.out.println("NO"); continue outer; } } else { a =a+(arr[i] - i); } } System.out.println("YES"); } } static void function(int l, int r, int[] arr, int[] depth, int d){ if(r<l){ return; } if(r==l){ depth[l]=d; return; } int m = l; for(int i=l+1;i<=r;i++){ if(arr[m]<arr[i]){ m=i; } } depth[m]=d; function(l,m-1,arr,depth,d+1); function(m+1,r,arr,depth,d+1); } static boolean perfectCube(long N) { long cube_root; cube_root = (long)Math.round(Math.cbrt(N)); // If cube of cube_root is equals to N, // then print Yes Else print No if (cube_root * cube_root * cube_root == N) { return true; } return false; } public static int value(int n){ if(n==0){ return 0; } int cnt=0; while(n>0){ cnt++; n/=2; } return cnt; } public static int value1(int n){ int cnt=0; while(n>1){ cnt++; n/=2; } return cnt; } public static String function(String s){ if(check(s)){ return s; } if(s.length()==2 && s.charAt(0)==s.charAt(1)){ return ""; } if(s.charAt(0)==s.charAt(1)){ return function(s.substring(2,s.length())); } else{ return function(s.charAt(0)+function(s.substring(1,s.length()))); } } static boolean isPowerOfTwo(int n){ if(n==0) return false; return (int)(Math.ceil((Math.log(n) / Math.log(2)))) == (int)(Math.floor(((Math.log(n) / Math.log(2))))); } static boolean isPerfectSquare(double x) { if (x >= 0) { double sr = Math.sqrt(x); return ((sr * sr) == x); } return false; } public static boolean isPerfect(int n){ int a = (int)Math.sqrt(n); if(a*a==n){ return true; } return false; } public static boolean check(String s){ if(s.length()==1){ return true; } for(int i=1;i<s.length();i++){ if(s.charAt(i)==s.charAt(i-1)){ return false; } } return true; } public static boolean isPrime(int n){ boolean flag=true; while(n%2==0){ n=n/2; flag=false; } for(int i=3;i<=Math.sqrt(n);i+=2){ if(n%i==0){ flag=false; while(n%i==0){ n=n/i; } } } return flag; } public static void dfst(ArrayList<ArrayList<Integer>> graph,int src, int deg,boolean ef, boolean of, boolean[] vis, boolean[] flip, int[] init, int[] goal){ if(vis[src]){ return; } vis[src]=true; if((deg%2==0 && ef) || (deg%2==1 && of)){ init[src]=1-init[src]; } if(init[src]!=goal[src]){ flip[src]=true; if(deg%2==0){ ef=!ef; } else{ of=!of; } } for(int i=0;i<graph.get(src).size();i++){ if(!vis[graph.get(src).get(i)]){ dfst(graph,graph.get(src).get(i),deg+1,ef,of,vis,flip,init,goal); } } } public static void dfs(ArrayList<ArrayList<Integer>> graph, int src, int val, boolean[] vis){ vis[src]=true; int cur_val =0; for(int i=0;i<graph.get(src).size();i++){ if(!vis[graph.get(src).get(i)]){ cur_val=val+1; dfs(graph,graph.get(src).get(i),cur_val,vis); } if(max_value<cur_val){ max_value=cur_val; } cur_val=0; } } public static ArrayList<Integer> pf(int n){ ArrayList<Integer> arr = new ArrayList<>(); boolean flag=false; while(n%2==0){ flag=true; n/=2; } if(flag){ arr.add(2); } for(int i=3;i<=Math.sqrt(n);i++){ if(n%i==0){ arr.add(i); while(n%i==0){ n/=i; } } } if(n>1){ arr.add(n); } return arr; } static int gcd(int a, int b){ if(b==0){ return a; } else{ return gcd(b,a%b); } } static boolean function(int n, int i, int[] arr, int sum){ if(sum==0){ return true; } if(i==n && sum!=0){ return false; } if(sum<arr[i]){ return function(n,i+1,arr,sum); } else{ return function(n,i+1,arr,sum-arr[i]) || function(n,i+1,arr,sum); } } public static long fact( long n, long mod){ long res =1; for(int i=1;i<=n;i++){ res%=mod; i%=mod; res=(res*i)%mod; } return res; } public static long nCk(long n,long k, long mod){ return (fact(n,mod)%mod*modular(fact(k,mod),mod-2,mod)%mod*modular(fact(n-k,mod),mod-2,mod)%mod)%mod; } public static long modular(long n, long e, long mod){ long res = 1; n%=mod; if (n == 0) return 0; while(e>0){ if((e&1)==1){ res=(res*n)%mod; } e=e>>1; n=(n*n)%mod; } return res; } 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
e23bbaeef971796bda5a38ad9cac9af6
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 Main2 { public static void main(String[] args) throws IOException, InterruptedException { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t = sc.nextInt() ; while(t-->0) { int n = sc.nextInt(); long a[]= new long [n]; for(int i = 0 ; i<n;i++) { a[i]= sc.nextLong(); } long remain=0; for(int i=0;i<n;i++){ remain+=(a[i]-i); if(remain<0) break; } System.out.println(remain>=0?"YES":"NO"); } } static class Scanner { BufferedReader br; StringTokenizer st; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader f) { br = new BufferedReader(f); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public String nextLine() throws IOException { return br.readLine(); } public int[] nextIntArr(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = Integer.parseInt(next()); } return arr; } public boolean ready() throws IOException, IOException { return br.ready(); } } }
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
2e5f2a6d55b823d40bd4b82d68fd87db
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.ArrayList; import java.util.List; import java.util.Scanner; import java.util.Set; import java.util.stream.IntStream; import java.math.BigInteger; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; public class Main { 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 int MAX=100000; static ArrayList<Integer> a=new ArrayList<>(); public static int[] prefix=new int[MAX+1]; static BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out)); public static void main(String args[])throws IOException { /* * For integer input: int n=inputInt(); * For long input: long n=inputLong(); * For double input: double n=inputDouble(); * For String input: String s=inputString(); * Logic goes here * For printing without space: print(a+""); where a is a variable of any datatype * For printing with space: printSp(a+""); where a is a variable of any datatype * For printing with new line: println(a+""); where a is a variable of any datatype */ int t=inputInt(); while(t--!=0) { int n=inputInt(); long sum=0; long[] arr=new long[n]; long ans=0; long iheight =0, fheight =0,sho = 0; for(int i=0;i<n;i++) { arr[i]=inputLong(); } for(int i=0; i<n; i++) { sho= fheight + arr[i]; iheight = i; arr[i] = iheight; fheight = sho - iheight; if(fheight < 0) break; } if(fheight >=0) println("YES"); else println("NO"); } bw.flush(); bw.close(); } public static int max(int[] arr,int k) { int xx=0; for(int i=k;i<arr.length;i++) { xx=Math.max(xx, arr[i]); } return xx; } public static void sieve() { boolean[] prime=new boolean[MAX+1]; Arrays.fill(prime, true); for(int i = 2; i * i <= MAX; i++) { if(prime[i] == true) { for(int j = i * 2; j<= MAX; j+= i) { prime[j] = false; } } } prefix[0] = prefix[1] = 0; for(int i = 2; i<= MAX; i++) { prefix[i] = prefix[i-1]; if(prime[i]) prefix[i]++; } } public static boolean isPrime(int n) { // Check if number is less than // equal to 1 if (n <= 1) return false; // Check if number is 2 else if (n == 2) return true; // Check if n is a multiple of 2 else if (n % 2 == 0) return false; // If not, then just check the odds for(int i = 3; i <= Math.sqrt(n); i += 2) { if (n % i == 0) return false; } return true; } 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"); } } class Pair implements Comparable<Pair> { public int x; public int y; public Pair(int x, int y) { this.x = x; this.y = y; } @Override public String toString() { return (x + " " + y); } @Override public boolean equals(Object o) { if (!(o instanceof Pair)) return false; Pair pairo = (Pair) o; return this.x == pairo.x && this.y == pairo.y; } //Arrays.sort(pairArray,new Comparator<Pair>() // // { // @Override // public int compare (Pair p1, Pair p2){ // return p1.getL().compareTo(p2.getL()); // } // }); @Override public int compareTo(Pair p) { return Integer.compare(this.x, p.x); } } class SegmentTree { // Implemented to store min in a range , point update and range query int tree[]; int len; int size; SegmentTree(int len) { // arr should be a 1 based array this.len = len; size = 1 << (32 - Integer.numberOfLeadingZeros(len - 1) + 1); // ceil(log(len)) + 1 tree = new int[size]; Arrays.fill(tree, Integer.MAX_VALUE); } void update(int node, int idx, int val, int nl, int nr) { if (nl == nr && nl == idx) tree[node] = val; else { int mid = (nl + nr) >> 1; if (idx <= mid) update(2 * node, idx, val, nl, mid); else update((2 * node) + 1, idx, val, mid + 1, nr); tree[node] = Math.min(tree[2 * node], tree[(2 * node) + 1]); } } void update(int idx, int val) { update(1, idx, val, 0, len - 1); } int query(int L, int R) { if (L > R) return Integer.MAX_VALUE; return query(1, L, R, 0, len - 1); } int query(int node, int L, int R, int nl, int nr) { int mid = (nl + nr) >> 1; if (nl == L && nr == R) return tree[node]; else if (R <= mid) return query(2 * node, L, R, nl, mid); else if (L > mid) return query((2 * node) + 1, L, R, mid + 1, nr); else return Math.min(query(2 * node, L, mid, nl, mid), query((2 * node) + 1, mid + 1, R, mid + 1, nr)); } } class Maths { public final long MOD = (long) 1e9 + 7; public long[] fact = generateFactorials(1000000); public long[] invFact = generateReverseFactorials(1000000); public static long modInverse(long a, long m) { return power(a, m - 2, m); } public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } public static long power(long a, long k, long m) { long res = 1; while (k > 0) { if ((k & 1) != 0) { res = res * a % m; } a = a * a % m; k >>= 1; } return res; } public long comb(final int m, final int n) { return (((fact[n] * invFact[m]) % MOD) * invFact[n - m]) % MOD; } public long[] generateFactorials(int count) { long[] result = new long[count]; result[0] = 1; for (int i = 1; i < count; i++) { result[i] = (result[i - 1] * i) % MOD; } return result; } long[] generateReverseFactorials(int upTo) { final long[] reverseFactorials = new long[upTo]; reverseFactorials[0] = reverseFactorials[1] = 1; final BigInteger BIG_MOD = BigInteger.valueOf(MOD); for (int i = 1; i < upTo; i++) { reverseFactorials[i] = (BigInteger.valueOf(i).modInverse(BIG_MOD).longValue() * reverseFactorials[i - 1]) % MOD; } return reverseFactorials; } } class Node { List<Integer> neighbors; Node() { neighbors = new ArrayList<>(); } void addEdge(Integer v) { neighbors.add(v); } public List<Integer> getNeighbors() { return neighbors; } } class Graph { List<Node> nodes = new ArrayList<>(); public Graph(int n) { for (int i = 0; i < n; ++i) { nodes.add(new Node()); } } public Node getNode(int v) { return nodes.get(v); } public void addEdge(int u, int v) { getNode(u).addEdge(v); getNode(v).addEdge(u); } }
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
f90237ac1763854a0d45d3abbde8adbe
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 Scanner in =new Scanner(System.in); static final Random random=new Random(); static int mod=1000_000_007; static long[]rank; static List<List<Integer>>adj; public static void main(String[] args) { int tt=in.nextInt(); outer:while(tt-->0) { int n=in.nextInt(); long h[]=readAr(n);long res=0,sum=0; for(int i=0;i<n;i++){ sum+=i; res+=h[i]; if(res<sum){ System.out.println("NO");continue outer; } } System.out.println("YES"); } } static void uf (int[] root, int v1, int v2) { int rootP = find(v1,root); int rootQ = find(v2,root); if (rootP == rootQ) return; if (rank[rootQ] > rank[rootP]) { root[rootP] = rootQ; rank[rootQ]+=rank[rootP]; rank[rootP]=0; } else { root[rootQ] = rootP; rank[rootP]+=rank[rootQ]; rank[rootQ]=0; } } static int find(int p,int [] root) { while (p != root[p]) { root[p] =root[root[p]]; p = root[p]; } return p; } static int lb(int ind,int[] a,int k){ int l=ind; int h=a.length-1; int r=ind; while(l<=h){ int mid=(l+h)/2; if(a[ind]+a[mid]>=k){ r=mid;l=mid+1; } else h=mid-1; } return r; } static int nCr(int n,int r,int p){ if (r == 0) return 1; if(r==1)return n; return ((int)fact(n)*modInverse((int)fact(r),p)%p * modInverse((int)fact(n-r),p) % p)%p; } static int modInverse(int n, int p){ return power(n, p-2, p); } static int power(int x,int y,int p){ int res = 1; x= x % p; while (y>0){ if (y%2==1) res= (res*x)% p; y= y >> 1; x= (x*x)% p; } return res; } static void seive(){ int num=1000001; boolean[] prime = new boolean[num]; Arrays.fill(prime,true); for (int i=2; i*i<=num; i++) { if(prime[i] == true) { for(int j=i*i; j<num; j=j+i) { prime[j]=false; } } } } static long[]readAr(int n) { long[] a=new long[(int)n]; for (int i=0; i<n; i++) {a[i]=in.nextLong();} return a; } static int[]readA1r(int n) { int[] a=new int[(int)n]; for (int i=0; i<n; i++) {a[i]=in.nextInt();} return a; } static int fact(int k){ long[]f=new long[10001];f[1]=1; for(int i=2;i<10001;i++){ f[i]=(i*f[i-1]% mod); } return (int)f[k]; } 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 void reverse(int []a){ int n= a.length; for(int i=0;i<n/2;i++){ int temp=a[i]; a[i]=a[n-i-1]; a[n-i-1]=temp; a[i]=a[i]; } //debug(a); } static void debug(int []a) { for (int i=0; i<a.length;i++) System.out.print(a[i]+" "); System.out.println(); } static void print(List<Integer>s) { for(int x:s) System.out.print(x+","); System.out.println(); } static int gcd(int a, int b) { return b==0 ? a : gcd(b, a % b); } static long find_max(long []a){ long m=Integer.MIN_VALUE; for(long x:a)m=Math.max(x,m); return m; } static int find_min(int []a){ int m=Integer.MAX_VALUE; for(int x:a)m=Math.min(x,m); return 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 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
691b607e3ad0a6dc0e468c23f7cdac02
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 A { static FastReader reader = new FastReader(); static OutputWriter out = new OutputWriter(System.out); static int[] dsu; public static void main(String[] args) { int tests = reader.nextInt(); for(int test = 1; test <= tests; test++) { int n = reader.nextInt(); boolean ch = true; long add = 0; for(int i = 0; i < n; i++) { long t = reader.nextLong(); if(t >= i) { add += t - i; } else { if(add < i - t) { ch = false; } else { add -= (i- t); } } } if(ch) { out.println("YES"); } else { out.println("NO"); } } out.flush(); } 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 class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(char[] array) { writer.print(array); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void print(int[] array) { for (int i = 0; i < array.length; i++) { if (i != 0) { writer.print(' '); } writer.print(array[i]); } } public void print(double[] array) { for (int i = 0; i < array.length; i++) { if (i != 0) { writer.print(' '); } writer.print(array[i]); } } public void print(long[] array) { for (int i = 0; i < array.length; i++) { if (i != 0) { writer.print(' '); } writer.print(array[i]); } } public void println(int[] array) { print(array); writer.println(); } public void println(double[] array) { print(array); writer.println(); } public void println(long[] array) { print(array); writer.println(); } public void println() { writer.println(); } public void println(Object... objects) { print(objects); writer.println(); } public void print(char i) { writer.print(i); } public void println(char i) { writer.println(i); } public void println(char[] array) { writer.println(array); } public void printf(String format, Object... objects) { writer.printf(format, objects); } public void close() { writer.close(); } public void flush() { writer.flush(); } public void print(long i) { writer.print(i); } public void println(long i) { writer.println(i); } public void print(int i) { writer.print(i); } public void println(int i) { writer.println(i); } public void separateLines(int[] array) { for (int i : array) { println(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
bcf1c8205886d413a1ee91ab927f58cf
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; public class ShiftingStacks { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(reader.readLine()); for (int i = 0; i < t; i++) { int n = Integer.parseInt(reader.readLine()); String[] array = reader.readLine().split(" "); long sum1 = 0L; long sum2 = 0L; for (int j = 0; j < n; j++) { sum1 += j; sum2 += Long.parseLong(array[j]); if (sum2 < sum1) { System.out.println("NO"); break; } } if (sum2 >= sum1) { System.out.println("YES"); } // if (sum2 >= sum1) { // 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
d0785c7a0b3e439cf410ab71170ee9b3
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.Desktop; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.URI; import java.net.URISyntaxException; import java.sql.Array; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.PriorityQueue; import java.util.Queue; import java.util.Scanner; import java.util.Set; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeSet; import java.util.Vector; public class codechef3 { static class comp implements Comparator<Integer> { @Override public int compare(Integer o1, Integer o2) { if(Math.abs(o1)>Math.abs(o2)) return -1; else return 1; } } //======================================================= //sorting Pair static class comp1 implements Comparator<Pair<Integer,Integer>> { @Override public int compare(Pair<Integer, Integer> o1, Pair<Integer, Integer> o2) { if(o1.k>o2.k) return 1; else return -1; } } //======================================================= //Creating Pair class //---------------------------------------------------------------------- static class Pair<Integer,Intetger> { int k=0; int v=0; public Pair(int a,int b) { k=a; v=b; } } //-------------------------------------------------------------------------- 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; } } //gcd of two number public static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } //-------------------------------------------------------------------------------------------- //lcm of two number static int x; public static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } //------------------------------------------------------------------------------------------- public static void main(String[] args) { FastReader s=new FastReader(); PrintWriter pw=new PrintWriter(System.out); StringBuffer s2=new StringBuffer(); int t=s.nextInt(); while(t-->0) { int n=s.nextInt(); long[] a=new long[n]; long sum=0; for(int i=0;i<n;i++) { a[i]=s.nextLong(); } int flag=0; if(n==1) { System.out.println("YES"); continue; } for(int i=0;i<n;i++) { sum+=a[i]; if(sum>=(i*(i+1))/2) continue; else { flag=1; break; } } if(flag==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
6903ae87dc516681b0a09c55cf7b9f60
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.Arrays; import java.util.StringTokenizer; public class A { public static void main(String[] args) { // Scanner sc=new Scanner(System.in); FastScanner sc = new FastScanner(); FastOutput out = new FastOutput(System.out); int t = sc.nextInt(); while (t-- > 0) { int n=sc.nextInt(); long arr[]=sc.readLongArray(n); boolean ok=true,first=true; for(int i=0;i<n-1;i++){ if(arr[i]>=i){ arr[i+1]+=arr[i]-i; arr[i]=i; arr[i+1]=Math.min(arr[i+1], 1000000000); }else{ ok=false; break; } } if(arr[n-1]<n-1)ok=false; // System.out.println(ok); // System.out.println(Arrays.toString(arr)); out.println(ok?"YES":"NO"); } out.close(); } 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[] readIntArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long[] readLongArray(int n) { long[] a=new long[n]; for (int i=0; i<n; i++) a[i]=nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } } static class FastOutput implements AutoCloseable, Closeable, Appendable { private static final int THRESHOLD = 1 << 13; private final Writer os; private StringBuilder cache = new StringBuilder(THRESHOLD * 2); public FastOutput append(CharSequence csq) { cache.append(csq); return this; } public FastOutput append(CharSequence csq, int start, int end) { cache.append(csq, start, end); return this; } private void afterWrite() { if (cache.length() < THRESHOLD) { return; } flush(); } public FastOutput(Writer os) { this.os = os; } public FastOutput(OutputStream os) { this(new OutputStreamWriter(os)); } public FastOutput append(char c) { cache.append(c); afterWrite(); return this; } public FastOutput append(int c) { cache.append(c); afterWrite(); return this; } public FastOutput append(String c) { cache.append(c); afterWrite(); return this; } public FastOutput println(String c) { return append(c).println(); } public FastOutput println() { return append(System.lineSeparator()); } public FastOutput flush() { try { os.append(cache); os.flush(); cache.setLength(0); } catch (IOException e) { throw new UncheckedIOException(e); } return this; } public void close() { flush(); try { os.close(); } catch (IOException e) { throw new UncheckedIOException(e); } } public String toString() { return cache.toString(); } } }
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
f97693c9ea8a8baace16c9371db6bd17
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
/* * Date Created : 18/2/2021 * Have A Good Day ! */ import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author arpit */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastReader in = new FastReader(inputStream); OutputWriter out = new OutputWriter(outputStream); AShiftingStacks solver = new AShiftingStacks(); int testCount = Integer.parseInt(in.next()); for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); } static class AShiftingStacks { public void solve(int testNumber, FastReader r, OutputWriter out) { int n = r.nextInt(); long[] arr = r.nextLongArray(n); long req = 0; boolean flag = true; for (int i = 0; i < n && flag; i++) { if (arr[i] < req) flag = false; else if (i + 1 < n) { arr[i + 1] += (arr[i] - req); arr[i] = req; } req++; } // out.debugln("arr", arr); out.println(flag ? "YES" : "NO"); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { writer.print(objects[i]); if (i != objects.length - 1) writer.print(" "); } } public void println(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } } static class FastReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private FastReader.SpaceCharFilter filter; public FastReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String nextString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) { res.appendCodePoint(c); } c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return nextString(); } public long[] nextLongArray(int n) { long[] array = new long[n]; for (int i = 0; i < n; ++i) array[i] = nextLong(); return array; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
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
434c976175f95834280bb73b470771ee
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
//created by Whiplash99 import java.io.*; import java.util.*; public class A { public static void main(String[] args) throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int i,N; int T=Integer.parseInt(br.readLine().trim()); StringBuilder sb=new StringBuilder(); while (T-->0) { N=Integer.parseInt(br.readLine().trim()); long[] a=new long[N]; String[] s=br.readLine().trim().split(" "); for(i=0;i<N;i++) a[i]=Long.parseLong(s[i]); long extra=a[0]; a[0]=0; for(i=1;i<N;i++) { a[i]+=extra; if(a[i]<=a[i-1]) break; extra=a[i]-i; a[i]-=extra; } sb.append(i==N?"YES\n":"NO\n"); } 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
bd003912fe234e01c5bd838794661d65
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.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; import static java.lang.Math.*; public class A implements Closeable { private InputReader in = new InputReader(System.in); private PrintWriter out = new PrintWriter(System.out); public void solve() { int t = in.ni(); while (t-- > 0) { int n = in.ni(); long spare = 0; boolean ok = true; for (int i = 0; i < n; i++) { long next = in.nl(); if (next > i) { spare += next - i; } else { long need = i - next; if (spare >= need) { spare -= need; } else { ok = false; } } } out.println(ok ? "YES" : "NO"); } } @Override public void close() throws IOException { in.close(); out.close(); } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int ni() { return Integer.parseInt(next()); } public long nl() { return Long.parseLong(next()); } public void close() throws IOException { reader.close(); } } public static void main(String[] args) throws IOException { try (A instance = new A()) { instance.solve(); } } }
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
9f743a97f9a5c1ddcd20582a3934bc36
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 []a = new long[n]; long flag=1; long j = 1; for(int i=0;i<n;i++) { a[i]=sc.nextLong(); } for(int i=0;i<n-1;i++) { long s = a[i]-i; if(s<0) { break; } a[i] = a[i]-s; a[i+1]+=s; } for(int i=0;i<n-1;i++) { if(a[i]<a[i+1]) { flag=1; } else { flag=0; break; } } if(flag==1) { 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 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
54e347ab5c755c6adf062ab976674445
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 A { public static long gcd(long a, long b) { return a == 0 ? b : gcd(b, a % b); } public static void print(long[] a) { PrintWriter out = new PrintWriter(System.out); for (int i = 0; i < a.length; i++) { out.print(a[i] + " "); } out.println(); out.close(); } public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter o = new PrintWriter(System.out); int t1 = sc.nextInt(); while (t1-- > 0) { int n = sc.nextInt(); long l[] = new long[n]; boolean f = false; for (int i = 0; i < n; i++) l[i] = sc.nextLong(); long m = 0; for (int i = 0;i<n;i++) { if (l[i]>=i) { m+=l[i]-i; }else { long h = i-l[i]; m-=h; if (m<0) { f = true; break; } } } if (!f) { o.println("YES"); }else { o.println("NO"); } } o.close(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public boolean ready() throws IOException { return br.ready(); } int[] readArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } } }
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
aac4aee396596432cb07e752dfc1275b
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.math.BigInteger; import java.util.*; public class Test { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int i = 0; i < t; i++) { int n = sc.nextInt(); int need = 0; long have = 0; boolean ans = true; for (int j = 0; j < n; j++) { need += j; have += sc.nextInt(); if (have < need) ans = false; } if (ans) System.out.println("YES"); else System.out.println("NO"); } } 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(); } } }
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
3910bd50c776c1474de37f0827feeda7
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 Problem_1486A { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); int n; long sum = 0, need = 0; boolean flag = false; for (int i = 0; i < t; i++) { n = scanner.nextInt(); long[] h = new long[n]; for (int j = 0; j < n; j++) { h[j] = scanner.nextLong(); } sum = 0; need = 0; flag = true; for (int j = 0; j < n; j++) { need += j; sum += h[j]; if (sum < need) { flag = false; 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 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
238b40931e89e614ac3428415cd742e4
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.util.*; import java.io.*; //My life seems to be a joke. But, one day I will conquer. public class B{ public static void main(String[] args) { FastScanner fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = fs.nextInt(); a:for(int tt=0;tt<t;tt++) { int n = fs.nextInt(); List<Integer> x = new ArrayList(); List<Integer> y = new ArrayList(); for(int i=0;i<n;i++) { int xx = fs.nextInt(); int yy = fs.nextInt(); x.add(xx); y.add(yy); } if(n%2==1) { System.out.println(1); continue a; } Collections.sort(x); Collections.sort(y); int x1 = x.get(n/2); int x2 = x.get(n/2-1); int y1 = y.get(n/2); int y2 = y.get(n/2-1); long totalX = x1-x2+1; long totalY = y1-y2+1; System.out.println(totalX*totalY); } out.close(); } 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\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
d4d856cd6e47cbdfaa53699ef39f1a7c
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public final class Solution{ public static void main (String[] args) throws Exception { BufferedWriter op = new BufferedWriter(new OutputStreamWriter(System.out)); Reader sc= new Reader(); int t= sc.nextInt(); while(t-->0){ int n= sc.nextInt(); long[] x= new long[n]; long[] y= new long[n]; for(int i=0;i<n;i++){ x[i]=sc.nextLong(); y[i]= sc.nextLong(); } if(n==1){ op.write(1+"\n"); continue; } Arrays.sort(x); Arrays.sort(y); long one = x[n/2]-x[(n/2)-1]+1; long two = y[n/2]-y[(n/2)-1]+1; if(x.length%2!=0){ one=1; } if(y.length%2!=0){ two=1; } // System.out.println(one+" "+two); op.write(one*two+"\n"); } op.flush(); } } 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(); } } // BufferedWriter op = new BufferedWriter(new OutputStreamWriter(System.out)); // in comparator to sort in in order return -1 // in comparator to sort in increasing order return 1 // sorting in increasing // class Comp implements Comparator<pair>{ // public int compare(pair a,pair b){ // if(a.b>b.b){ // return 1; here // } // return -1; // } // }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
a97649888f94109ca0844a957a033167
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
/* Written by Kabir Kanha Arora @kabirkanha @Kabir */ import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { FastScanner scanner = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = scanner.nextInt(); while (t-- > 0) { int n = scanner.nextInt(); long[] x_arr = new long[n]; long[] y_arr = new long[n]; for (int i = 0; i < n; ++i) { x_arr[i] = scanner.nextLong(); y_arr[i] = scanner.nextLong(); } shuffleAndSort(x_arr); shuffleAndSort(y_arr); if (n == 1) out.println(1); else if (n == 2) { long l = Math.abs(x_arr[1] - x_arr[0]) + 1; long r = Math.abs(y_arr[1] - y_arr[0]) + 1; out.println(l * r); } else { if (n % 2 != 0) out.println(1); else { long xPossibilities = (x_arr[n / 2] - x_arr[n / 2 - 1] + 1); long yPossibilities = (y_arr[n / 2] - y_arr[n / 2 - 1] + 1); out.println(xPossibilities * yPossibilities); } } } out.close(); } // Shuffle and sort array static void shuffleAndSort(long[] arr) { for (int i = 0; i < arr.length; ++i) { int random_index = (int) (Math.random() * arr.length); long temp = arr[i]; arr[i] = arr[random_index]; arr[random_index] = temp; } Arrays.sort(arr); } // Fast IO 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[] readLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; ++i) a[i] = nextLong(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
9a7de74ff968ed8d3489e00ec00bc02c
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; public class B_Eastern { static int n; public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader scan = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); String[] in; int tt = parse(scan.readLine()); for(int t = 0; t < tt; t++) { n = parse(scan.readLine()); long[][] house = new long[n][2]; for(int i = 0; i < n; i++) { in = scan.readLine().split(" "); house[i][0] = parse(in[0]); house[i][1] = parse(in[1]); } long ans = getNumPos(0, house) * getNumPos(1, house); out.println(ans); } out.flush(); } private static long getNumPos(int index, long[][] house) { if(house.length % 2 == 1) return 1; Arrays.sort(house, (a, b)->Long.compare(a[index], b[index])); return house[house.length/2][index] - house[house.length/2 - 1][index] + 1; } /*private static long getNumPos(int index, long[][] house) { long location = getSum(index, house)/n; long target = dist(location, house, index); long temp = dist(location + 1, house, index); if(temp < target) { location ++; target = temp; } long l = getLeft(target, location, index, house); long r = getRight(target, location, index, house); return r - l + 1; } private static long getRight(long target, long min, int index, long[][] house) { long low = min, high = (long) 1e9, mid; long valid = min; while(low <= high) { mid = (low + high) / 2; if(dist(mid, house, index) == target) { if(mid > valid) valid = mid; low = mid + 1; } else { high = mid - 1; } } return valid; } private static long getLeft(long target, long max, int index, long[][] house) { long low = 0, high = max, mid; long valid = max; while(low <= high) { mid = (low + high) / 2; if(dist(mid, house, index) == target) { if(mid < valid) valid = mid; high = mid - 1; } else { low = mid + 1; } } return valid; } private static long dist(long average, long[][] house, int index) { long dist = 0; for(long[] point : house) dist += Math.abs(point[index] - average); return dist; } private static long getSum(int index, long[][] house) { long sum = 0; for(long[] point : house) sum += point[index]; return sum; } */ public static int parse(String num) { return Integer.parseInt(num); } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
94750e50065801284382fbadd862541c
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.io.*; import java.util.*; public class eexhibit { public static void main(String agrs[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer in = new StringTokenizer(br.readLine()); PrintWriter out = new PrintWriter(System.out); long t = Integer.parseInt(in.nextToken()); long j; for(long i = 0; i < t; i++) { in = new StringTokenizer(br.readLine()); long n = Long.parseLong(in.nextToken()); long d; long Cx = 0, Cy = 0; // d = delta, Cx = counter for process x, Cy = counter for process y TreeMap<Long, Long> Dx_ts = new TreeMap<>(), Dy_ts = new TreeMap<>(); for(j = 1; j <= n; j++){ in = new StringTokenizer(br.readLine()); long x = Long.parseLong(in.nextToken()); if(Dx_ts.get(x) == null) Dx_ts.put(x, 0l); Dx_ts.replace(x, Dx_ts.get(x) + 2); Cx += x; long y = Long.parseLong(in.nextToken()); if(Dy_ts.get(y) == null) Dy_ts.put(y, 0l); Dy_ts.replace(y, Dy_ts.get(y) + 2); Cy += y; } Cx -= Dx_ts.firstKey() * n; Cy -= Dy_ts.firstKey() * n; long Sx = Dx_ts.size(), Sy = Dy_ts.size(); // process x long[][] Dx = new long[(int)Sx + 1][2]; j = 1; for(Long k : Dx_ts.keySet()){ Dx[(int)j][0] = k; Dx[(int)j][1] = Dx_ts.get(k); j++; } TreeMap<Long, Long> Tx = new TreeMap<>(); d = -1 * n; Tx.put(Cx, 1l); for(j = 1; j < Sx; j++){ d += Dx[(int)j][1]; Cx += d * (Dx[(int)j + 1][0] - Dx[(int)j][0]); if(d == 0) { if(Tx.get(Cx) == null) Tx.put(Cx, 0l); Tx.replace(Cx, Tx.get(Cx) + (Dx[(int)j + 1][0] - Dx[(int)j][0])); }else { if(Tx.get(Cx) == null) Tx.put(Cx, 0l); Tx.replace(Cx, Tx.get(Cx) + 1); } } // process y long[][] Dy = new long[(int)Sy + 1][2]; j = 1; for(Long k : Dy_ts.keySet()){ Dy[(int)j][0] = k; Dy[(int)j][1] = Dy_ts.get(k); j++; } TreeMap<Long, Long> Ty = new TreeMap<>(); d = -1 * n; Ty.put(Cy, 1l); for(j = 1; j < Sy; j++){ d += Dy[(int)j][1]; Cy += d * (Dy[(int)j + 1][0] - Dy[(int)j][0]); if(d == 0) { if(Ty.get(Cy) == null) Ty.put(Cy, 0l); Ty.replace(Cy, Ty.get(Cy) + (Dy[(int)j + 1][0] - Dy[(int)j][0])); }else { if(Ty.get(Cy) == null) Ty.put(Cy, 0l); Ty.replace(Cy, Ty.get(Cy) + 1); } } out.println(Tx.firstEntry().getValue()*Ty.firstEntry().getValue()); } out.close(); } } /* 1 8 756764518 412103839 722460568 195282969 979780191 450793610 492197753 953546232 2676986 367487969 48946904 641467344 532147443 443507707 794863955 592048652 * */
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
2d38ec42479f20b40d4287120f36c7d6
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.io.*; import java.lang.*; import java.util.*; public class ComdeFormces { public static void main(String[] args) throws Exception{ // TODO Auto-generated method stub // Reader.init(System.in); FastReader sc=new FastReader(); BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out)); // OutputStream out = new BufferedOutputStream ( System.out ); int t=sc.nextInt(); while(t--!=0) { int n=sc.nextInt(); ArrayList<pair> ar=new ArrayList<>(); for(int i=0;i<n;i++) { ar.add(new pair(sc.nextInt(),sc.nextInt())); } Collections.sort(ar,(aa,bb)->{ return aa.a-bb.a; }); long x=0; if(ar.size()%2!=0)x=1; else x=ar.get(ar.size()/2).a-ar.get((ar.size()/2)-1).a+1; Collections.sort(ar,(aa,bb)->{ return aa.b-bb.b; }); long y=0; if(ar.size()%2!=0)y=1; else y=ar.get(ar.size()/2).b-ar.get((ar.size()/2)-1).b+1; log.write(x*y+" "); log.write("\n"); log.flush(); } } static int ev(int s,int e,int e2,int l) { for(int i=s;i<=e;i++) { int ts=i; int vl2=0; boolean cv=false; int ct=0; while(ts!=0) { int num=ts%10; if(num==0 || num==1 || num==2 || num==5 || num==8) { if(num==2)num=5; else if(num==5)num=2; vl2=vl2*10+num; ct++; } else { cv=true; break; } ts/=10; } if(ct==1) { vl2*=10; } if(cv || vl2>=e2)continue; else return i; } return -1; } static int evv(int cnt[],int cnt2[]) { int ans=0; for(int i=1;i<cnt.length;i++) { if(cnt[i]>cnt2[i]) { ans+=cnt[i]-cnt2[i]; } } return ans; } public static void fb(HashMap<Long,Integer> hm,HashSet<Long> hs, long s) { if(hs.contains(s)) { hm.put(s,hm.get(s)-1); if(hm.get(s)==0)hs.remove(s); return; } else if(s<=1)return; fb(hm,hs,s/2); fb(hm,hs,(s+1)/2); } public static void radixSort(int a[]) { int n=a.length; int res[]=new int[n]; int p=1; for(int i=0;i<=8;i++) { int cnt[]=new int[10]; for(int j=0;j<n;j++) { a[j]=res[j]; cnt[(a[j]/p)%10]++; } for(int j=1;j<=9;j++) { cnt[j]+=cnt[j-1]; } for(int j=n-1;j>=0;j--) { res[cnt[(a[j]/p)%10]-1]=a[j]; cnt[(a[j]/p)%10]--; } p*=10; } } static int bits(long n) { int ans=0; while(n!=0) { if((n&1)==1)ans++; n>>=1; } return ans; } static long flor(ArrayList<Long> ar,long el) { int s=0; int e=ar.size()-1; while(s<=e) { int m=s+(e-s)/2; if(ar.get(m)==el)return ar.get(m); else if(ar.get(m)<el)s=m+1; else e=m-1; } return e>=0?e:-1; } public static int kadane(int a[]) { int sum=0,mx=Integer.MIN_VALUE; for(int i=0;i<a.length;i++) { sum+=a[i]; mx=Math.max(mx, sum); if(sum<0) sum=0; } return mx; } public static int m=1000000007; public static int mul(int a, int b) { return ((a%m)*(b%m))%m; } public static long mul(long a, long b) { return ((a%m)*(b%m))%m; } public static int add(int a, int b) { return ((a%m)+(b%m))%m; } public static long add(long a, long b) { return ((a%m)+(b%m))%m; } //debug public static <E> void p(E[][] a,String s) { System.out.println(s); for(int i=0;i<a.length;i++) { for(int j=0;j<a[0].length;j++) { System.out.print(a[i][j]+" "); } System.out.println(); } } public static void p(int[] a,String s) { System.out.print(s+"="); for(int i=0;i<a.length;i++)System.out.print(a[i]+" "); System.out.println(); } public static void p(long[] a,String s) { System.out.print(s+"="); for(int i=0;i<a.length;i++)System.out.print(a[i]+" "); System.out.println(); } public static <E> void p(E a,String s){ System.out.println(s+"="+a); } public static <E> void p(ArrayList<E> a,String s){ System.out.println(s+"="+a); } public static <E> void p(LinkedList<E> a,String s){ System.out.println(s+"="+a); } public static <E> void p(HashSet<E> a,String s){ System.out.println(s+"="+a); } public static <E> void p(Stack<E> a,String s){ System.out.println(s+"="+a); } public static <E> void p(Queue<E> a,String s){ System.out.println(s+"="+a); } //utils static ArrayList<Integer> divisors(int n){ ArrayList<Integer> ar=new ArrayList<>(); for (int i=2; i<=Math.sqrt(n); i++){ if (n%i == 0){ if (n/i == i) { ar.add(i); } else { ar.add(i); ar.add(n/i); } } } return ar; } static int primeDivisor(int n){ ArrayList<Integer> ar=new ArrayList<>(); int cnt=0; boolean pr=false; while(n%2==0) { pr=true; n/=2; } if(pr)ar.add(2); for(int i=3;i*i<=n;i+=2) { pr=false; while(n%i==0) { n/=i; pr=true; } if(pr)ar.add(i); } if(n>2) ar.add(n); return ar.size(); } static long gcd(long a,long b) { if(b==0)return a; else return gcd(b,a%b); } static int gcd(int a,int b) { if(b==0)return a; else return gcd(b,a%b); } static long factmod(long n,long mod,long img) { if(n==0)return 1; long ans=1; long temp=1; while(n--!=0) { if(temp!=img) { ans=((ans%mod)*((temp)%mod))%mod; } temp++; } return ans%mod; } static int ncr(int n, int r){ if(r>n-r)r=n-r; int ans=1; for(int i=0;i<r;i++){ ans*=(n-i); ans/=(i+1); } return ans; } public static class trip{ int a,b; int c; public trip(int a,int b,int c) { this.a=a; this.b=b; this.c=c; } public int compareTo(trip q) { return this.b-q.b; } } static void mergesort(long[] a,int start,int end) { if(start>=end)return ; int mid=start+(end-start)/2; mergesort(a,start,mid); mergesort(a,mid+1,end); merge(a,start,mid,end); } static void merge(long[] a, int start,int mid,int end) { int ptr1=start; int ptr2=mid+1; long b[]=new long[end-start+1]; int i=0; while(ptr1<=mid && ptr2<=end) { if(a[ptr1]<=a[ptr2]) { b[i]=a[ptr1]; ptr1++; i++; } else { b[i]=a[ptr2]; ptr2++; i++; } } while(ptr1<=mid) { b[i]=a[ptr1]; ptr1++; i++; } while(ptr2<=end) { b[i]=a[ptr2]; ptr2++; i++; } for(int j=start;j<=end;j++) { a[j]=b[j-start]; } } public static class FastReader { BufferedReader b; StringTokenizer s; public FastReader() { b=new BufferedReader(new InputStreamReader(System.in)); } String next() { while(s==null ||!s.hasMoreElements()) { try { s=new StringTokenizer(b.readLine()); } catch(IOException e) { e.printStackTrace(); } } return s.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str=""; try { str=b.readLine(); } catch(IOException e) { e.printStackTrace(); } return str; } boolean hasNext() { if (s != null && s.hasMoreTokens()) { return true; } String tmp; try { b.mark(1000); tmp = b.readLine(); if (tmp == null) { return false; } b.reset(); } catch (IOException e) { return false; } return true; } } public static class pair{ int a; int b; public pair(int a,int b) { this.a=a; this.b=b; } public int compareTo(pair b) { return this.a-b.a; } // public int compareToo(pair b) { // return this.b-b.b; // } @Override public String toString() { return "{"+this.a+" "+this.b+"}"; } } static long pow(long a, long pw) { long temp; if(pw==0)return 1; temp=pow(a,pw/2); if(pw%2==0)return temp*temp; return a*temp*temp; } static int pow(int a, int pw) { int temp; if(pw==0)return 1; temp=pow(a,pw/2); if(pw%2==0)return temp*temp; return a*temp*temp; } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
18c6ff5359eff5a597f34aef677da0a7
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.util.*; import java.io.*; public class cf { static Reader sc = new Reader(); static PrintWriter out = new PrintWriter(System.out); static int mod = (int) 1e9 + 7; public static void main(String[] args) { int t = sc.ni(); while (t-- > 0) { int n = sc.ni(); int[] a = new int[n], b = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.ni(); b[i] = sc.ni(); } sort(a); sort(b); if (n % 2 != 0) { out.println(1); } else { long x = a[n / 2] - a[n / 2 - 1] + 1; long y = b[n / 2] - b[n / 2 - 1] + 1; out.println(x * y); } } out.close(); } public static long pow(long a, long b, long m) { if (b == 0) { return 1; } if (b % 2 == 0) { return pow((a * a) % m, b / 2, m) % m; } else { return (a * pow((a * a) % m, b / 2, m)) % m; } } // snippets static class Pair implements Comparable<Pair> { int x; int y; Pair(int x, int y) { this.x = x; this.y = y; } @Override public int compareTo(Pair o) { if (this.x > o.x) return 1; else if (this.x < o.x) return -1; else { if (this.y > o.y) return 1; else if (this.y < o.y) return -1; else return 0; } } public int hashCode() { int ans = 1; ans = x * 31 + y * 13; return ans; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null) { return false; } if (this.getClass() != o.getClass()) { return false; } Pair other = (Pair) o; if (this.x == other.x && this.y == other.y) { return true; } return false; } } static void add_map(HashMap<Integer, Integer> map, int v) { if (!map.containsKey(v)) { map.put(v, 1); } else { map.put(v, map.get(v) + 1); } } static void remove_map(HashMap<Integer, Integer> map, int v) { if (map.containsKey(v)) { map.put(v, map.get(v) - 1); if (map.get(v) == 0) map.remove(v); } } static int 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 sort(int[] arr) { // shuffle Random rand = new Random(); for (int i = 0; i < arr.length; i++) { int j = rand.nextInt(i + 1); int tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp; } Arrays.sort(arr); } static void sort(long[] arr) { // shuffle Random rand = new Random(); for (int i = 0; i < arr.length; i++) { int j = rand.nextInt(i + 1); long tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp; } Arrays.sort(arr); } static boolean isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq = Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static boolean isPrime(long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; double sq = Math.sqrt(n); for (int i = 5; i <= sq; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static void print_arr(int A[]) { for (int i : A) { System.out.print(i + " "); } System.out.println(); } static void print_arr(long A[]) { for (long i : A) { System.out.print(i + " "); } System.out.println(); } static void print_arr(char A[]) { for (char i : A) { System.out.print(i + " "); } System.out.println(); } static int min(int a, int b) { return Math.min(a, b); } static int min(int a, int b, int c) { return Math.min(a, Math.min(b, c)); } static int min(int a, int b, int c, int d) { return Math.min(a, Math.min(b, Math.min(c, d))); } static int max(int a, int b) { return Math.max(a, b); } static int max(int a, int b, int c) { return Math.max(a, Math.max(b, c)); } static int max(int a, int b, int c, int d) { return Math.max(a, Math.max(b, Math.max(c, d))); } static long min(long a, long b) { return Math.min(a, b); } static long min(long a, long b, long c) { return Math.min(a, Math.min(b, c)); } static long min(long a, long b, long c, long d) { return Math.min(a, Math.min(b, Math.min(c, d))); } static long max(long a, long b) { return Math.max(a, b); } static long max(long a, long b, long c) { return Math.max(a, Math.max(b, c)); } static long max(long a, long b, long c, long d) { return Math.max(a, Math.max(b, Math.max(c, d))); } static int max(int A[]) { int max = Integer.MIN_VALUE; for (int i = 0; i < A.length; i++) { max = Math.max(max, A[i]); } return max; } static int min(int A[]) { int min = Integer.MAX_VALUE; for (int i = 0; i < A.length; i++) { min = Math.min(min, A[i]); } return min; } static long max(long A[]) { long max = Long.MIN_VALUE; for (int i = 0; i < A.length; i++) { max = Math.max(max, A[i]); } return max; } static long min(long A[]) { long min = Long.MAX_VALUE; for (int i = 0; i < A.length; i++) { min = Math.min(min, A[i]); } return min; } static long sum(int A[]) { long sum = 0; for (int i : A) { sum += i; } return sum; } static long sum(long A[]) { long sum = 0; for (long i : A) { sum += i; } return sum; } static ArrayList<Integer> sieve(int n) { ArrayList<Integer> primes = new ArrayList<>(); boolean[] isPrime = new boolean[n]; Arrays.fill(isPrime, true); isPrime[0] = isPrime[1] = false; for (int i = 2; i * i <= n; i++) { if (isPrime[i]) { for (int j = i * i; j < n; j += i) { isPrime[j] = false; } } } for (int i = 2; i < n; i++) { if (isPrime[i]) primes.add(i); } return primes; } static class Reader { BufferedReader br; StringTokenizer st; Reader() { br = new BufferedReader(new InputStreamReader(System.in)); st = new StringTokenizer(""); } Reader(File f) throws FileNotFoundException { br = new BufferedReader(new FileReader(f)); st = new StringTokenizer(""); } String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { } return st.nextToken(); } int ni() { return Integer.parseInt(next()); } long nl() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } int[] nai(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = ni(); return a; } long[] nal(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nl(); return a; } } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
f795faa4c00747ddfc909c2750ab735f
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.util.*; import java.io.*; public class cf { static Reader sc = new Reader(); // static Scanner sc = new Scanner(System.in); static PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) { int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int[] a = new int[n], b = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); b[i] = sc.nextInt(); } Arrays.sort(a); Arrays.sort(b); long cx = 0, cy = 0; if (n % 2 == 0) { cx = a[n / 2] - a[n / 2 - 1] + 1; cy = b[n / 2] - b[n / 2 - 1] + 1; } else { cx = 1; cy = 1; } out.println(cx * cy); } out.close(); } static class Reader { 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) { } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
28e4b355092bb3e43e28716fa5846413
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; public class Main { private static Scanner scanner; static { scanner = new Scanner(System.in); } public static void main(String[] args) { int T = scanner.nextInt(); for (int t = 0; t < T; t++) { int n; n = scanner.nextInt(); List<Long> x = new ArrayList<>(); List<Long> y = new ArrayList<>(); for (int i = 0; i < n; i++) { x.add(scanner.nextLong()); y.add(scanner.nextLong()); } Collections.sort(x); Collections.sort(y); Long xs = x.get(x.size() / 2) - x.get((x.size() - 1) / 2) + 1; Long ys = y.get(y.size() / 2) - y.get((y.size() - 1) / 2) + 1; System.out.println(xs * ys); } scanner.close(); } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
862f46b3807dd27030ca46d666bd5c03
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Jaynil */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); BEasternExhibition solver = new BEasternExhibition(); int testCount = Integer.parseInt(in.next()); for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); } static class BEasternExhibition { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); Long x[] = new Long[n]; Long y[] = new Long[n]; long count1 = 1; long count2 = 1; for (int i = 0; i < n; i++) { x[i] = in.nextLong(); y[i] = in.nextLong(); } Arrays.sort(x); Arrays.sort(y); long min = Long.MAX_VALUE; long curr = 0; long prev = -1; for (int i = 0; i < n; i++) { curr = 0; for (int j = 0; j < n; j++) { curr += Math.abs(x[i] - x[j]); } if (curr < min) { min = curr; count1 = 1; } if (prev == min && curr == min) { count1 = Math.max(count1, x[i] - x[i - 1] + 1); } // System.out.println(curr + " " + count1); prev = curr; } min = Long.MAX_VALUE; curr = 0; prev = -1; for (int i = 0; i < n; i++) { curr = 0; for (int j = 0; j < n; j++) { curr += Math.abs(y[i] - y[j]); } if (curr < min) { min = curr; count2 = 1; } if (prev == min && curr == min) { count2 = Math.max(count2, y[i] - y[i - 1] + 1); } prev = curr; } out.println(count1 * count2); } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
d5f3c7d2315bbcc8acc2a7ec200c4377
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
/* JAI MATA DI */ import java.util.*; import java.io.*; import java.math.BigInteger; public class Codechef { static class FR{ BufferedReader br; StringTokenizer st; public FR() { 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 int mod = 1000000007; static int 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 boolean[] prime(int num) { boolean[] bool = new boolean[num]; for (int i = 0; i< bool.length; i++) { bool[i] = true; } for (int i = 2; i< Math.sqrt(num); i++) { if(bool[i] == true) { for(int j = (i*i); j<num; j = j+i) { bool[j] = false; } } } if(num >= 0) { bool[0] = false; bool[1] = false; } return bool; } static class Pair implements Comparable<Pair>{ int first; int second; Pair(int key , int value){ this.first = key; this.second = value; } @Override public int compareTo(Pair o) { if(this.second == o.second) { return this.first - o.first; } // if(this.first == o.first) this.second - o.second; return -(this.second - o.second); } @Override public int hashCode(){ return first + second; } } public static void main(String args[]) { FR sc = new FR(); int t = sc.nextInt(); StringBuilder sb = new StringBuilder(); while(t-- > 0 ) { int n = sc.nextInt(); long[][] arr = new long[n][2]; long xmax = -1 , xmin = Integer.MAX_VALUE , ymax = -1 , ymin = Integer.MAX_VALUE; LinkedList<Long> ax = new LinkedList<Long>(); LinkedList<Long> ay = new LinkedList<Long>(); Set<Long> setx = new HashSet<Long>(); Set<Long> sety = new HashSet<Long>(); for(int i=0 ; i<n ; i++) { long x = sc.nextInt(); long y = sc.nextInt(); ax.add(x); ay.add(y); } Collections.sort(ax); Collections.sort(ay); int x = ax.size(); int y = ay.size(); long county = 0 , countx = 0; if(x % 2 == 1) countx = 1; else if(x%2 == 0) { int num = x/2 -1; while(num-->0) ax.removeFirst(); // System.out.println(ax); countx = Math.abs(ax.remove()-ax.remove())+1; } if(y % 2 == 1) county = 1; else if(y%2 == 0) { int num = y/2 -1; while(num-->0) ay.removeFirst(); // System.out.println(ay); county = Math.abs(ay.remove()-ay.remove())+1; } sb.append(countx*county); sb.append("\n"); } System.out.println(sb); } static long disx(long[][] arr , long x) { long dis = 0; for(int i=0 ; i<arr.length ; i++) { dis += Math.abs(arr[i][0]-x) ; } return dis; } static long disy(long[][] arr , long y) { long dis = 0; for(int i=0 ; i<arr.length ; i++) { dis += Math.abs(arr[i][1]-y) ; } return dis; } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
0e49a3fd43ece67dd146b0a782da1a2e
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.util.*; public class cf703 { public static int problemA(int n, int arr[]){ long tillNow=0; for(int i=0; i<n; i++){ tillNow+=arr[i]; if(tillNow<i) return 0; tillNow-=i; } return 1; } public static int binSrch(int arr[], int T){ //get index k of arr which is last element arr[k]<T and arr[k+1]>=T int n = arr.length; int start = 0, end=n-1; while(start<end){ int mid = (start+end)/2; if(arr[mid]<T && arr[mid+1]>=T) return mid; else if(arr[mid]>=T) end=mid-1; else start=mid; } return (end==0)?end:-1; } public static long calcD(int n, int id, long[] pr, int v){ long sum=0; if(id>=0){ sum = Math.abs((id+1)*v-pr[id])+Math.abs((pr[n-1]-pr[id]) - v* (n-1-id)); } else { sum= Math.abs((pr[n-1]) - v* (n)); } return sum; } public static long problemB(int n, int x[], int y[]){ // int maxX = 1000000000; // int maxY = 1000000000; Arrays.sort(x); Arrays.sort(y); long res1 = x[(n/2)]-x[(n-1)/2] +1; long res2 = y[(n/2)]-y[(n-1)/2] +1; return res1*res2; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int tcases; tcases = sc.nextInt(); while(tcases>0){ int n = sc.nextInt(); int x[] = new int[n]; int y[] = new int[n]; for(int i=0; i<n; i++) { x[i] = sc.nextInt(); y[i] = sc.nextInt(); } System.out.println(problemB(n,x,y)); tcases--; } // int x[] = {3,4,7,11,12,19}; // System.out.println(binSrch(x,19)); } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
65ba3a58efee5b42e834aace6afceb15
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.util.*; public final class P2 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int testCount = scanner.nextInt(); for (int i = 0; i < testCount; i++) { int n = scanner.nextInt(); int[] xs = new int[n]; int[] ys = new int[n]; for (int j = 0; j < n; j++) { xs[j] = scanner.nextInt(); ys[j] = scanner.nextInt(); } // System.out.println(testBF(xs, ys) + " " + testFast(xs, ys)); System.out.println(testFast(xs, ys)); } } private static long testFast(int[] xs, int[] ys) { int n = xs.length; // Single median for odd points if (n % 2 == 1) return 1; Arrays.sort(xs); Arrays.sort(ys); // All optimal points are between left and right median long xcnt = xs[n / 2] - xs[n / 2 - 1] + 1L; long ycnt = ys[n / 2] - ys[n / 2 - 1] + 1L; return xcnt * ycnt; } private static long testBF(long[] xs, long[] ys) { long minx = Long.MAX_VALUE, miny = Long.MAX_VALUE, maxx = Long.MIN_VALUE, maxy = Long.MIN_VALUE; for (int i = 0; i < xs.length; i++) { minx = Math.min(minx, xs[i]); miny = Math.min(miny, ys[i]); maxx = Math.max(maxx, xs[i]); maxy = Math.max(maxy, ys[i]); } TreeMap<Long,Long> cnt = new TreeMap<>(); for (long x = minx; x <= maxx; x++) { for (long y = miny; y <= maxy; y++) { long sd = 0; for (int i = 0; i < xs.length; i++) { sd += Math.abs(x - xs[i]) + Math.abs(y - ys[i]); } cnt.put(sd, cnt.getOrDefault(sd, 0L) + 1L); } } return cnt.firstEntry().getValue(); } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
46e897ae8c2160f3bc1789942dc1d24e
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.util.*; public final class P2 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int testCount = scanner.nextInt(); for (int i = 0; i < testCount; i++) { int n = scanner.nextInt(); long[] xs = new long[n]; long[] ys = new long[n]; for (int j = 0; j < n; j++) { xs[j] = scanner.nextLong(); ys[j] = scanner.nextLong(); } // System.out.println(testBF(xs, ys) + " " + testFast(xs, ys)); System.out.println(testFast(xs, ys)); } } private static long testFast(long[] xs, long[] ys) { int n = xs.length; // Single median for odd points if (n % 2 == 1) return 1; Arrays.sort(xs); Arrays.sort(ys); // All optimal points are between left and right median long xcnt = xs[n / 2] - xs[n / 2 - 1] + 1L; long ycnt = ys[n / 2] - ys[n / 2 - 1] + 1L; return xcnt * ycnt; } private static long testBF(long[] xs, long[] ys) { long minx = Long.MAX_VALUE, miny = Long.MAX_VALUE, maxx = Long.MIN_VALUE, maxy = Long.MIN_VALUE; for (int i = 0; i < xs.length; i++) { minx = Math.min(minx, xs[i]); miny = Math.min(miny, ys[i]); maxx = Math.max(maxx, xs[i]); maxy = Math.max(maxy, ys[i]); } TreeMap<Long,Long> cnt = new TreeMap<>(); for (long x = minx; x <= maxx; x++) { for (long y = miny; y <= maxy; y++) { long sd = 0; for (int i = 0; i < xs.length; i++) { sd += Math.abs(x - xs[i]) + Math.abs(y - ys[i]); } cnt.put(sd, cnt.getOrDefault(sd, 0L) + 1L); } } return cnt.firstEntry().getValue(); } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
9626a6e2d78e8c5e858d56e0afcc6895
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class B { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int cases = scn.nextInt(); while (cases-- > 0) { int n = scn.nextInt(); int[] xS = new int[n]; int[] yS = new int[n]; for (int i = 0; i < n; i++) { xS[i] = scn.nextInt(); yS[i] = scn.nextInt(); } if (n % 2 == 1) { System.out.println(1); continue; } Arrays.sort(xS); Arrays.sort(yS); int mid = (n - 1) / 2; long nrX = (xS[mid + 1] - xS[mid] + 1); long nrY = (yS[mid + 1] - yS[mid] + 1); long ans = nrX*nrY; System.out.println(ans); } } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
e87d9eadda0c0991267c3703ff795780
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.util.*; public class Test { static Scanner sc; public static void main(String args[]) { sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { solve(); } } public static void solve() { int n = sc.nextInt(); int[] x = new int[n]; int[] y = new int[n]; for (int i = 0; i < n; i++) { x[i] = sc.nextInt(); y[i] = sc.nextInt(); } if(n%2 == 1){ System.out.println(1); return; } Arrays.sort(x); Arrays.sort(y); long x_median = x[n / 2] - x[(n - 1) / 2] + 1; long y_median = y[n / 2] - y[(n - 1) / 2] + 1; long ans = x_median * y_median; System.out.println(x_median * y_median); } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
7eda3622f8d12cf9702bbac9bda4a851
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.util.*; public class Test { static Scanner sc; public static void main(String args[]) { sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { solve(); } } public static void solve() { int n = sc.nextInt(); int[] x = new int[n]; int[] y = new int[n]; for (int i = 0; i < n; i++) { x[i] = sc.nextInt(); y[i] = sc.nextInt(); } Arrays.sort(x); Arrays.sort(y); long x_median = x[n / 2] - x[(n - 1) / 2] + 1; long y_median = y[n / 2] - y[(n - 1) / 2] + 1; long ans = x_median * y_median; System.out.println(x_median * y_median); } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
bfb5b9b0fb1c245bcde54e65d39d9c4b
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; public class ProblemB { final Scanner scanner; public static void main(String[] args) { new ProblemB().solve(); } ProblemB() { scanner = new Scanner(System.in); // try { // var in = new FileInputStream("b.txt"); // scanner = new Scanner(in); // } catch (FileNotFoundException e) { // throw new RuntimeException(); // } } void solve() { int t = scanner.nextInt(); for (int i = 0; i < t; ++i) { int n = scanner.nextInt(); List<Long> housesX = new ArrayList<>(); List<Long> housesY = new ArrayList<>(); for (int j = 0; j < n; ++j) { housesX.add(scanner.nextLong()); housesY.add(scanner.nextLong()); } Collections.sort(housesX); Collections.sort(housesY); var answerX = solveForSingleDimension(housesX); var answerY = solveForSingleDimension(housesY); System.out.println(answerX * answerY); } scanner.close(); } long solveForSingleDimension(List<Long> houses) { if (houses.size() % 2 == 1) { return 1; } int middle = houses.size() / 2; return houses.get(middle) - houses.get(middle - 1) + 1; } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
8e244dea8b5a6aafb4c915b9681f4ed1
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
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 time=fs.nextInt(); while(time-->0) { int n=fs.nextInt(); int x[]=new int[n]; int y[] =new int[n]; for(int i=0;i<n;i++) { x[i]=fs.nextInt(); y[i]=fs.nextInt(); } if((n&1)==1) { System.out.println(1); continue; } mysort(x); mysort(y); System.out.println((long)(x[n/2]-x[n/2-1]+1)*(long)(y[n/2]-y[n/2-1]+1)); } } 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\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
3aa23813dedbfce6e6bf7ddce8f5e435
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.util.*; import static java.lang.Math.log; import static java.lang.Math.min; public class Main { //------------------------------------------CONSTANTS--------------------------------------------------------------- public static final int MOD = (int) (1e9 + 7); //---------------------------------------------I/0------------------------------------------------------------------ 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 print(String s) { System.out.println(s); } public static void main(String[] args) { FastReader sc = new FastReader(); int t = 1; t = sc.nextInt(); for(int i = 0; i<t; i++) { System.out.println(solve(sc)); } } //------------------------------------------------SOLVE------------------------------------------------------------- public static long solve(FastReader sc) { int n = sc.nextInt(); int[] x = new int[n]; int[] y = new int[n]; for (int i = 0; i<n; i++) { x[i] = sc.nextInt(); y[i] = sc.nextInt(); } if (n == 1) return 1; Arrays.sort(x); Arrays.sort(y); int l = 0; int r; int t = 0; int b; if (n%2==1) { l = x[n/2]; r = x[n/2]; t = y[n/2]; b = y[n/2]; } else { l = x[n/2-1]; r = x[n/2]; t = y[n/2-1]; b = y[n/2]; } return (long)(r - l + 1)*(long)(b - t + 1); } //-----------------------------------------------FUNCTIONS---------------------------------------------------------- public static String printArray(int[] a) { StringBuilder r = new StringBuilder(""); for(int i = 0; i<a.length; i++) { r.append(a[i] + " "); } return r.toString(); } public static <T> String printList(List<T> a) { StringBuilder r = new StringBuilder(""); for (T x: a) { r.append(x.toString() + " "); } return r.toString(); } // first element that is not less than target public static int lowerBound(int[] arr, int begin, int end, int target) { while(begin < end) { int mid = begin + (end - begin) / 2; // When the element is less than the mid target if(arr[mid] < target) // begin to mid + 1, arr [begin] value is less than or equal target begin = mid + 1; // When the mid target element when greater than or equal else if(arr[mid] >= target) end = mid; } return begin; } // first element that is greater than target public static int upperBound(int[] arr, int begin, int end, int target) { while(begin < end) { int mid = begin + (end - begin) / 2; if(arr[mid] <= target) begin = mid + 1; else end = mid; } return begin; } // generate permutations (call search and access through permutations) public static class Permutations { List<List<Integer>> permutations = new ArrayList<>(); List<Integer> permutation = new ArrayList<>(); boolean[] taken; int[] a; public Permutations(int[] a) { this.a = a; taken = new boolean[a.length]; } void search() { if (permutation.size()==a.length) { permutations.add(new ArrayList<>(permutation)); } else { for (int i = 0; i<a.length; i++) { if (taken[i]) { continue; } taken[i] = true; permutation.add(a[i]); search(); taken[i] = false; permutation.remove(permutation.size()-1); } } } } // generate subsets (call search and access subsets) public static class Subsets { List<List<Integer>> subsets = new ArrayList<>(); List<Integer> subset = new ArrayList<>(); void search(int[] a, int x) { if (x == a.length) { subsets.add(new ArrayList<>(subset)); } else { subset.add(a[x]); search(a, x+1); subset.remove(subset.size() - 1); search(a, x+1); } } } // NUMBER THEORY FUNCTIONS public static int gcd(int a, int b) { // O(log n) if (b==0) return a; return gcd(b, a%b); } public static int lcm(int a, int b) { return (a*b)/gcd(a, b); } public static boolean isPrime(int n) { if (n < 2) return false; for (int x = 2; x*x <= n; x++) { if (n % x == 0) return false; } return true; } public static List<Integer> factors(int n) { List<Integer> f = new ArrayList<>(); for (int x = 2; x*x <= n; x++) { while (n % x == 0) { f.add(x); n /= x; } } if (n > 1) f.add(n); return f; } public static int numberOfDivisors(int n) { List<Integer> fp = factors(n); int x = 1; int t = 0; for (int i = 0; i<fp.size()-1; i++) { t++; if (fp.get(i+1)!=fp.get(i)) { x *= (t+1); t = 0; } } t++; x *= (t+1); return x; } // returns an array sieve s.t. sieve[x] = 0 if x is prime or contains a prime factor if x isn't prime O(quasi-n) public static int[] sieve(int n) { int[] sieve = new int[n+1]; for (int x = 2; x <= n; x++) { if (sieve[x] != 0) continue; for (int u = 2*x; u <= n; u += x) { sieve[u] = x; } } return sieve; } // number of coprimes of n between 1 and n public static int totient(int n) { List<Integer> pf = factors(n); Map<Integer, Integer> fMap = new HashMap<>(); for (int x: pf) { if (!fMap.containsKey(x)) { fMap.put(x, 0); } fMap.put(x, fMap.get(x) + 1); } int totient = 1; for (Map.Entry<Integer, Integer> e: fMap.entrySet()) { int p = e.getKey(); int ex = e.getValue(); totient *= Math.pow(p, ex-1)*(p-1); } return totient; } // fast exponentiation public static int modpow(int x, int p, int mod) { if (p == 0) return 1 % mod; long u = modpow(x, p / 2, mod); // just because it should contain temporary a big number u = (u * u) % mod; if (p % 2 == 1) u = (u * x) % mod; return (int)u; } // --------------------------------------------------------********************************************************* public static int[][] prefixSum2D(int[][] a) { int n = a.length; int m = a[0].length; int[][] ps = new int[n][m]; ps[0][0] = a[0][0]; for (int j = 1; j<m; j++) { ps[0][j] = ps[0][j-1] + a[0][j]; } for (int i = 1; i<n; i++) { ps[i][0] = ps[i-1][0] + a[i][0]; } for (int i = 1; i<n; i++) { for (int j = 1; j<m; j++) { ps[i][j] = ps[i-1][j] + ps[i][j-1] - ps[i-1][j-1] + a[i][j]; } } return ps; } public static double log2(double a) { return log(a)/log(2); } //----------------------------------------DATA-STRUCTURES----------------------------------------------------------- // Range queries (i.e. RMQ) in O(1), others with functions in O(log n) public static class SparseTable { int[][] st; int n; int k; public SparseTable(int[] a) { n = a.length; k = (int) log2(n); st = new int[n][k+1]; for (int i = 0; i<n; i++) { st[i][0] = a[i]; } // 1<<j == 2^j for (int j = 1; j<=k; j++) { for (int i = 0; i + (1 << j) <= n; i++) { st[i][j] = min(st[i][j-1], st[i + (1 << (j - 1))][j - 1]); } } } //not always available O(log n) -- change the constructor to use it public long sumQuery(int l, int r) { long sum = 0; for (int j = k; j>=0; j--) { if ((1 << j) <= r - l + 1) { sum += st[l][j]; l += 1 << j; } } return sum; } //always available O(1) -- change this and the constructor for rangeMaxQuery public int rangeMinQuery(int l, int r) { int j = (int) log2(r - l + 1); int min = min(st[l][j], st[r - (1 << j) + 1][j]); return min; } } //Range Sum Dynamic Queries O(log n) public static class BinaryIndexedTree { int[] bit; public BinaryIndexedTree(int[] a) { int n = a.length; bit = new int[n+1]; // Store the actual values in BITree[] // using update() for(int i = 0; i < n; i++) updateBit(i, a[i]); } // O(log n) update delta at index in the array (do it on the array and then call this function) public void updateBit(int index, int delta) { index += 1; while (index <= bit.length) { bit[index] += delta; index += index & (-index); } } // Computes sum a[0...index] in O(log n) public int getSum(int index) { int sum = 0; index += 1; while (index > 0) { sum += bit[index]; index -= index & (-index); } return sum; } } public static class UnionFind { int[] link; int[] size; UnionFind(int n) { link = new int[n]; size = new int[n]; for (int i = 0; i<n; i++) { link[i] = i; size[i] = 1; } } int find(int x) { while (x != link[x]) x = link[x]; return x; } boolean same(int a, int b) { return find(a) == find(b); } void unite(int a, int b) { a = find(a); b = find(b); if (size[a] < size[b]) { int temp = a; a = b; b = temp; } size[a] += size[b]; link[b] = a; } } public static class SegmentTree { int st[]; public SegmentTree(int arr[]) { int n = arr.length; int x = (int) (Math.ceil(log2(n))); int maxSize = 2 * (int) Math.pow(2, x) - 1; st = new int[maxSize]; build(arr, 0, n-1, 0); } int build(int arr[], int ss, int se, int si) { if (ss == se) { st[si] = arr[ss]; return arr[ss]; } int mid = ss + (se - ss) / 2; //ss+se/2 st[si] = build(arr, ss, mid, si * 2 + 1) + build(arr, mid + 1, se, si * 2 + 2); return st[si]; } private int getSumUtil(int ss, int se, int l, int r, int si) { if (l <= ss && r >= se) { return st[si]; } if (se < l || ss > r) { return 0; } int mid = ss + (se - ss) / 2; return getSumUtil(ss, mid, l, r, 2 * si + 1) + getSumUtil(mid + 1, se, l, r, 2 * si + 2); } void updateValueUtil(int ss, int se, int i, int diff, int si) { if (i < ss || i > se) { return; } st[si] = st[si] + diff; if (se != ss) { int mid = ss + (se - ss) / 2; updateValueUtil(ss, mid, i, diff, 2 * si + 1); updateValueUtil(mid + 1, se, i, diff, 2 * si + 2); } } int getSum(int n, int l, int r) { if (l < 0 || r > n - 1 || l > r) { return -1; } return getSumUtil(0, n-1, l, r, 0); } // don't do it directly on the array but use this function that will // do everything for you void updateValue(int arr[], int n, int i, int newValue) { if (i < 0 || i > n - 1) { return; } int diff = newValue - arr[i]; arr[i] = newValue; updateValueUtil(0, n - 1, i, diff, 0); } } // Similar to Pair in c++, non-null objects as parameters public static class Pair<T extends Comparable<T>, Q extends Comparable<Q>> implements Comparable<Pair<T, Q>>{ T a; Q b; public Pair(T a, Q b) { this.a = a; this.b = b; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pair<?, ?> pair = (Pair<?, ?>) o; return a.equals(pair.a) && b.equals(pair.b); } @Override public int hashCode() { return Objects.hash(a, b); } @Override public int compareTo(Pair<T, Q> tqPair) { int compareA = this.a.compareTo(tqPair.a); if (compareA == 0) { return this.b.compareTo(tqPair.b); } else { return compareA; } } } // Uses Map + TreeSet to get the structure public static class OrderedMultiSet<T extends Comparable<T>> { private final TreeSet<T> set = new TreeSet<>(); private final Map<T, Integer> frequencies = new HashMap<>(); private int size = 0; public OrderedMultiSet() {} public OrderedMultiSet(List<T> a) { for (T x: a) { this.add(x); size++; } } public void add(T element) { set.add(element); if (!frequencies.containsKey(element)) { frequencies.put(element, 0); } frequencies.put(element, frequencies.get(element) + 1); size++; } public boolean remove(T element) { if (frequencies.containsKey(element)) { int x = frequencies.get(element); x--; if (x == 0) { frequencies.remove(element); set.remove(element); } else { frequencies.put(element, frequencies.get(element) - 1); } size--; return true; } return false; } public int size() { return size; } public T first() { return set.first(); } public T last() { return set.last(); } public T pollFirst() { T t = set.first(); remove(t); return t; } public T pollLast() { T t = set.last(); set. remove(t); return t; } } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
fd9aaa469df2f9eab860bf4bd11259f2
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Template { 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(); // //solve(); // //Scanner sc = new Scanner(System.in) // int testcases = sc.nextInt(); // nTest is the number of treasure hunts. // //// int testcases = 3; // while(testcases-- > 0) // { // String s = sc.next(); // solve(s); // // } // // } public static void main(String[] args) { FastReader fs=new FastReader(); int T=fs.nextInt(); for (int tt=0; tt<T; tt++) { int n = fs.nextInt(); long x[] = new long[n]; long y[] = new long[n]; for(int i=0;i<n;i++) { x[i] = fs.nextLong(); y[i] = fs.nextLong(); } if(n%2 == 1) { System.out.println("1"); continue; } Arrays.sort(x); Arrays.sort(y); System.out.println( (x[n/2] - x[n/2 - 1] + 1) * (y[n/2] - y[n/2 - 1] + 1)); } } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
a861f3c6186135becb056932a7cb1ec2
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
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 x[] = new long[(int) n]; long y[] = new long[(int) n]; for(int i =0;i<n;i++) { x[i] = sc.nextInt(); y[i] = sc.nextInt(); } Arrays.sort(x); Arrays.sort(y); if(n % 2 != 0) { System.out.println(1); } else { System.out.println((x[(int) (n/2)] - x[(int) (n/2 - 1)] + 1)*(y[(int) (n/2)] - y[(int) (n/2 - 1)] + 1)); } } 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\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
2ee4d76ff53288b4edc0cc1f8290164f
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; 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.Map; import java.util.Map.Entry; import java.util.PriorityQueue; import java.util.Queue; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; //import graph_representation.edge; public class hacker49 { public static int r1=0; 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 HashMap<Long,Integer> e=new HashMap<>(); public static void main(String[] args) { OutputStream outputStream =System.out; PrintWriter out =new PrintWriter(outputStream); FastReader s=new FastReader(); int t=s.nextInt(); while(t>0) { int n=s.nextInt(); long d1=0; long d2=0; // HashMap<Long,Integer> e1=new HashMap<>(); // HashMap<Long,Integer> e2=new HashMap<>(); ArrayList<Long> e3=new ArrayList<>(); ArrayList<Long> e4=new ArrayList<>(); for(int i=1;i<=n;i++) { long x=s.nextLong(); long y=s.nextLong(); // if(!e1.containsKey(x)) { e3.add(x); // e1.put(x, 1); // } // if(!e2.containsKey(y)) { e4.add(y); // e2.put(y, 1); // } } Collections.sort(e3); Collections.sort(e4); if(e3.size()%2!=0) { d1=1; }else { int f1=e3.size()/2; int f2=f1-1; d1=e3.get(f1)-e3.get(f2)+1; } if(e4.size()%2!=0) { d2=1; }else { int f1=e4.size()/2; int f2=f1-1; d2=e4.get(f1)-e4.get(f2)+1; } d1=(long)(d1*d2); out.println(d1); t--; } out.close(); } static class pair5{ private int a; private int b; pair5(int a,int b){ this.a=a; this.b=b; } } static ArrayList<Integer>[] t=new ArrayList[200001]; static int[] vis=new int[200001]; static int g=0; static boolean p=true; static void dfs(int node,int par) { vis[node]=1; g++; // boolean p=true; if(t[node].size()>2) { p= false; } // boolean p=false; int c=0; for(int i=0;i<t[node].size();i++) { if(vis[t[node].get(i)]==0) { c++; dfs(t[node].get(i),par); } } if(c==0) { if(!t[node].contains(par) || t[node].size()<2) { p= false; } } // return p; } static class pair implements Comparable<pair>{ private long i; private long v; pair(long i,long v){ this.i=i; this.v=v; } public int compareTo(pair o) { // if(o.v<this.v) { // return -1; // }else { // return 1; // } return Long.compare(this.v, o.v); } } static int nextPowerOf2(int n) { n--; n |= n >> 1; n |= n >> 2; n |= n >> 4; n |= n >> 8; n |= n >> 16; n++; return n; } // static class node{ // private int a; // private int b; // private int c; // private int d; // // } public static class node{ private int a; private int b; node(int a,int b){ this.a=a; this.b=b; } } public static long GCD(long a,long b) { if(b==(long)0) { return a; } return GCD(b , a%b); } // public static void Create(node[] arr,node[] segtree,int low,int high,int pos) { // if(low==high) { // segtree[pos]=arr[low]; // return; // } // int mid=(low+high)/2; // Create(arr,segtree,low,mid,2*pos+1); // Create(arr,segtree,mid+1,high,2*pos+2); // if(segtree[2*pos+1].a+segtree[2*pos+2].a>=10) { // int a=segtree[2*pos+1].a; // int b=segtree[2*pos+2].a; // int c=segtree[2*pos+1].b; // int d=segtree[2*pos+2].b; // segtree[pos]=new node((a+b)%10,1+c+d); // }else { // int a=segtree[2*pos+1].a; // int b=segtree[2*pos+2].a; // int c=segtree[2*pos+1].b; // int d=segtree[2*pos+2].b; // segtree[pos]=new node(a+b,c+d); // // } // } // public static node Query(node[] segtree,int qlow,int qhigh,int low,int high,int pos) { // if(low>=qlow && high<=qhigh) { // return segtree[pos]; // } // if(qhigh<low || qlow>high) { // return new node(0,0); // } // int mid=(low+high)/2; // node a=Query(segtree,qlow,qhigh,low,mid,2*pos+1); // node b=Query(segtree,qlow,qhigh,mid+1,high,2*pos+2); // int c=a.a; // int d=b.a; // if(c+d>=10) { // node e=new node((c+d)%10,1+a.b+b.b); // return e; // }else { // node e=new node(c+d,a.b+b.b); // return e; // } // } // static class pair1 implements Comparable<pair1>{ private int a; private int b; private int c; private int d; pair1(int a,int b,int c,int d){ this.a=a; this.b=b; this.c=c; this.d=d; } public int compareTo(pair1 o) { if(this.a<o.a) { return 1; }else if(this.a==o.a) { if(this.b<o.b) { return 1; }else { return -1; } }else { return -1; } } } public static void update(long[] segtree,int low,int high,int qlow,int qhigh,long val,int pos) { if(qlow>high || qhigh<low) { return ; } if(low>=qlow &&qhigh>=high) { segtree[pos]+=val; return; } int mid=(low+high)/2; update(segtree,low,mid,qlow,qhigh,val,2*pos); update(segtree,mid+1,high,qlow,qhigh,val,2*pos+1); } public static long query(long[] segtree,int low,int high,int index,int pos) { if(low==high) { return segtree[pos]; } int mid=(low+high)/2; long res=0; if(index<=mid) { res= query(segtree,low,mid,index,2*pos); }else { res=query(segtree,mid+1,high,index,2*pos+1); } return res+segtree[pos]; } // public static class pair5{ // private int a; // private int b; // pair5(int a,int b){ // this.a=a; // this.b=b; // } // public int compareTo(pair5 o) { // return Integer.compare(o.b, this.b); // } // } // public static pair5[] merge_sort(pair5[] A, int start, int end) { // if (end > start) { // int mid = (end + start) / 2; // pair5[] v = merge_sort(A, start, mid); // pair5[] o = merge_sort(A, mid + 1, end); // return (merge(v, o)); // } else { // pair5[] y = new pair5[1]; // y[0] = A[start]; // return y; // } // } // public static pair5[] merge(pair5 a[], pair5 b[]) { //// int count=0; // pair5[] temp = new pair5[a.length + b.length]; // int m = a.length; // int n = b.length; // int i = 0; // int j = 0; // int c = 0; // while (i < m && j < n) { // if (a[i].a < b[j].a) { // temp[c++] = a[i++]; // } else { // temp[c++] = b[j++]; // } // } // while (i < m) { // temp[c++] = a[i++]; // } // while (j < n) { // temp[c++] = b[j++]; // } // return temp; // } //// public static int upper_bound(int[] a ,int n,int x) { int l=-1; int r=n; while(r>l+1) { int mid=(l+r)/2; if(a[mid]<x) { l=mid; }else { r=mid; } } return r; } // // public static int lower_bound(pair[] a ,int n,long x) { int l=0; int r=n+1; while(r>l+1) { int mid=(l+r)/2; if(a[mid].i<x) { l=mid; }else { r=mid; } } return l; } public static int ty(int[] a, int x, int y) { Arrays.sort(a); int count=0; int n=a.length; for(int i=0;i<n;i++) { int g=0; if(x%a[i]==0) { g=x/a[i]; }else { g=x/a[i]+1; } int k1=upper_bound(a,n,g); if(k1==n) { count+=0; }else { int g1=0; if(y%a[i]==0) { g1=y/a[i]; }else { g1=y/a[i]+1; } // int k2=lower_bound(a,n,g1); // if(k2>=k1) { // count+=(k2-k1+1); // } } // System.out.println(count); } return count; } static boolean isValid(int x,int y,int n,int m) { if(x>=1 && x<=n && y>=1 && y<=m) { return true; }else { return false; } } static long[] fac=new long[1000001]; static void fac() { fac[0]=1; for(int i=1;i<=1000000;i++) { // fac[i]=((fac[i-1]%mod)*(i%mod))%mod; } } static ArrayList<Integer>[] f=new ArrayList[2001]; public static void init(int n) { for(int j=1;j<=n;j++) { for (int l=1; l<=Math.sqrt(j); l++) { if (j%l==0) { // If divisors are equal, print only one if (j/l == l) { f[j].add(l);} else { // Otherwise print both // System.out.print(i+" " + n/i + " " ); f[j].add(l); f[j].add(j/l); } } } } } public static long[] merge_sort(long[] A, int start, int end) { if (end > start) { int mid = (end + start) / 2; long[] v = merge_sort(A, start, mid); long[] o = merge_sort(A, mid + 1, end); return (merge(v, o)); } else { long[] y = new long[1]; y[0] = A[start]; return y; } } public static long[] merge(long a[], long b[]) { // int count=0; long[] temp = new long[a.length + b.length]; int m = a.length; int n = b.length; int i = 0; int j = 0; int c = 0; while (i < m && j < n) { if (a[i] < b[j]) { temp[c++] = a[i++]; } else { temp[c++] = b[j++]; } } while (i < m) { temp[c++] = a[i++]; } while (j < n) { temp[c++] = b[j++]; } return temp; } public static long[] merge_sort1(long[] A, int start, int end) { if (end > start) { int mid = (end + start) / 2; long[] v = merge_sort1(A, start, mid); long[] o = merge_sort1(A, mid + 1, end); return (merge1(v, o)); } else { long[] y = new long[1]; y[0] = A[start]; return y; } } public static long[] merge1(long a[], long b[]) { // int count=0; long[] temp = new long[a.length + b.length]; int m = a.length; int n = b.length; int i = 0; int j = 0; int c = 0; while (i < m && j < n) { if (a[i] < b[j]) { temp[c++] = a[i++]; } else { temp[c++] = b[j++]; } } while (i < m) { temp[c++] = a[i++]; } while (j < n) { temp[c++] = b[j++]; } return temp; } static long MOD=1000000007; static class pair2{ private long a; private int b; pair2(long a,int b){ this.a=a; this.b=b; } } // for(int i=2;i<=100000;i++) { }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
0c2ecdbff7390bae9e4f9fdb461db036
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.io.*; import java.util.*; public class test3 { static int mod = (int)10e9 +7; public static void main(String[] args) throws IOException { FastReader f = new FastReader(); int t = f.nextInt(); while(t-->0) { int n = f.nextInt(); ArrayList<Integer> x = new ArrayList<Integer>(); ArrayList<Integer> y = new ArrayList<Integer>(); for(int i = 0;i<n;i++) { x.add(f.nextInt()); y.add(f.nextInt()); } Collections.sort(x);Collections.sort(y); int v1 = x.get(n/2)-x.get((n-1)/2)+1; int v2 = y.get(n/2)-y.get((n-1)/2)+1; System.out.println((long)v1*(long)v2); } } static boolean isPrime(int n) { // Check if number is less than // equal to 1 if (n <= 1) return false; // Check if number is 2 else if (n == 2) return true; // Check if n is a multiple of 2 else if (n % 2 == 0) return false; // If not, then just check the odds for (int i = 3; i <= Math.sqrt(n); i += 2) { if (n % i == 0) return false; } return true; } static void print(int x,int y,int d,int n) { int i = 0; System.out.print(x+" "+y+" "); for(int j = x+d;j<y;j+=d) { System.out.print(j+" "); i++; } for(int j = x-d;j>0;j-=d) { if(i==n)return; System.out.print(j+" "); i++; } for(int j = y+d;j<1000000000;j+=d) { if(i==n)return; System.out.print(j+" "); i++; } } static int prime(int n){ int ret = 0; while(n%2==0){ ret++; n/=2; } for(int i=3;i<=Math.sqrt(n);i+=2){ while(n%i==0){ ret++; n/=i; } } if(n>2)ret++; return ret; } static long nCr(int n, int r) { if(n<r) { return 0; } long[] C=new long[r+1]; C[0] = 1; for (int i = 1; i <= n; i++) { for (int j = Math.min(i, r); j > 0; j--) C[j] = (C[j] + C[j-1]); } return C[r]; } static int power(int a,int n, int p) { int res = 1; a = a % p; while (n > 0) { if ((n & 1) == 1) res = (res * a) % p; n = n >> 1; a = (a * a) % p; } return res; } static boolean isPrime(int n, int k) { if (n <= 1 || n == 4) return false; if (n <= 3) return true; while (k > 0) { int a = 2 + (int)(Math.random() % (n - 4)); if (power(a, n - 1, n) != 1) return false; k--; } return true; } static long GCD(long a,long b) { if(a%b==0)return b; else return GCD(b,a%b); } static ArrayList<Integer> readArray(FastReader f,int size){ ArrayList<Integer> ret = new ArrayList<Integer>(); for(int i=0;i<size;i++) { ret.add(f.nextInt()); }return ret; } 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\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
46a430c45a666c336bc2883cc4b0c944
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.io.*; import java.util.*; public class P1486B { static InputReader in = new InputReader(System.in); static PrintWriter pw = new PrintWriter(System.out); static long mod = (long) (Math.pow(10, 9)) + 7; static HashMap<Integer, List<Integer>> adjList = new HashMap<>(); static boolean[] visited; public static void main(String[] args) { int test = in.nextInt(); while(test-->0) { solve(); } pw.close(); } static void solve() { int n = in.nextInt(); List<Integer> xVals = new ArrayList<>(); List<Integer> yVals = new ArrayList<>(); //all same x values or y values -> distance between for (int i = 0; i < n; i++) { int x = in.nextInt(), y = in.nextInt(); xVals.add(x); yVals.add(y); } Collections.sort(xVals); Collections.sort(yVals); long x = 1, y = 1; if (xVals.size() % 2 == 0) { int min = xVals.get(n / 2 - 1); int max = xVals.get(n / 2); x = max - min + 1; } if (yVals.size() % 2 == 0) { int min = yVals.get(n / 2 - 1); int max = yVals.get(n / 2); y = max - min + 1; } pw.println(x * y); } 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), temp=a[i]; a[i]=a[oi]; a[oi]=temp; } Arrays.sort(a); } public static List<Long> getFactors(long num) { List<Long> res = new ArrayList(); res.add(num); for (long d = 2; d <= (long)Math.sqrt(num); d++) { if (num % d == 0) { res.add(d); if ((num / d) != d) { res.add(num / d); } } } return res; } static long fast_pow(long a, long b) { if(b == 0) return 1L; long val = fast_pow(a, b / 2); if(b % 2 == 0) return val * val % mod; else return val * val % mod * a % mod; } static void sort(long[] a) //check for long { ArrayList<Long> l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } 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 void addEdge(int u, int v) { adjList.putIfAbsent(u, new ArrayList<>()); adjList.get(u).add(v); } static int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } static int lcm (int a, int b) { return a / gcd(a, b) * b; } static boolean[] sieve(int n) { boolean[] isPrime = new boolean[n + 1]; isPrime[0] = false; isPrime[1] = false; for (int i = 2; i <= n; i++) { if (isPrime[i] && i * i <= n) { for (int j = i * i; j <= n; j += i) { isPrime[i] = false; } } } return isPrime; } static boolean isPrime(int n) { for (int d = 2; d * d <= n; d++) { if (n % d == 0) { return false; } } return true; } //ternary search on a graph that is concave down static int high(int[] a) { int lo = 0, hi = a.length - 1; int error = 3; while (hi - lo > error) { int right = hi - (hi - lo) / 3; int left = lo + (hi - lo) / 3; if (a[left] < a[right]) { lo = left; } else { hi = right; } } //check for the lowest from a[l, h] int ans = lo; for (int i = lo; i <= hi; i++) { if (a[ans] < a[i]) { ans = i; } } return ans; } //ternary search on a concave up graph static int low(int[] a) { int lo = 0, hi = a.length - 1; int error = 3; while (hi - lo > error) { int right = hi - (hi - lo) / 3; int left = lo + (hi - lo) / 3; if (a[left] < a[right]) { hi = right; } else { lo = left; } } //check for the lowerst from a[l, h] int ans = lo; for (int i = lo; i <= hi; i++) { if (a[ans] > a[i]) { ans = i; } } return ans; } static boolean contains(int[] a, int key) { int ans = 0; int low = 0, high = a.length - 1; while (low <= high) { int mid = low + (high - low) / 2; int midVal = a[mid]; if (midVal < key) { low = mid + 1; } else if (midVal > key) { high = mid - 1; } else if (midVal == key) { ans = 1; break; } } return ans == 1; } static int first(int[] a, int key) { int ans = -1; int low = 0, high = a.length - 1; while (low <= high) { int mid = low + (high - low + 1) / 2; int midVal = a[mid]; if (midVal < key) { low = mid + 1; } else if (midVal > key) { high = mid - 1; } else if (midVal == key) { ans = mid; high = mid - 1; } } return ans; } static int last(int[] a, int key) { int ans = -1; int low = 0, high = a.length - 1; while (low <= high) { int mid = low + (high - low + 1) / 2; int midVal = a[mid]; if (midVal < key) { low = mid + 1; } else if (midVal > key) { high = mid - 1; } else if (midVal == key) { ans = mid; low = mid + 1; } } return ans; } static int greaterOrEqual(int[] a, int key) { int ans = -1; int low = 0, high = a.length - 1; while (low <= high) { int mid = low + (high - low + 1) / 2; int midVal = a[mid]; if (midVal < key) { low = mid + 1; } else if (midVal > key) { ans = mid; high = mid - 1; } else if (midVal == key) { return mid; } } return ans; } static int lesserOrEqual(int[] a, int key) { int ans = -1; int low = 0, high = a.length - 1; while (low <= high) { int mid = low + (high - low + 1) / 2; int midVal = a[mid]; if (midVal < key) { ans = mid; low = mid + 1; } else if (midVal > key) { high = mid - 1; } else if (midVal == key) { return mid; } } return ans; } static class SegTree { long st[]; public SegTree(long[] arr, int n) { int x = (int) (Math.ceil(Math.log(n) / Math.log(2))); int max_size = 2 * (int) Math.pow(2, x) - 1; st = new long[max_size]; constructSTUtil(arr, 0, n - 1, 0); } int getMid(int s, int e) { return s + (e - s) / 2; } long getSumUtil(int ss, int se, int qs, int qe, int si) { if (qs <= ss && qe >= se) return st[si]; if (se < qs || ss > qe) return 0; int mid = getMid(ss, se); return getSumUtil(ss, mid, qs, qe, 2 * si + 1) + getSumUtil(mid + 1, se, qs, qe, 2 * si + 2); } void updateValueUtil(int ss, int se, int i, long diff, int si) { if (i < ss || i > se) return; st[si] = st[si] + diff; if (se != ss) { int mid = getMid(ss, se); updateValueUtil(ss, mid, i, diff, 2 * si + 1); updateValueUtil(mid + 1, se, i, diff, 2 * si + 2); } } void updateValue(long arr[], int n, int i, int new_val) { if (i < 0 || i > n - 1) { System.out.println("Invalid Input"); return; } long diff = new_val - arr[i]; arr[i] = new_val; updateValueUtil(0, n - 1, i, diff, 0); } long getSum(int n, int qs, int qe) { if (qs < 0 || qe > n - 1 || qs > qe) { System.out.println("Invalid Input"); return -1; } return getSumUtil(0, n - 1, qs, qe, 0); } long constructSTUtil(long arr[], int ss, int se, int si) { if (ss == se) { st[si] = arr[ss]; return arr[ss]; } int mid = getMid(ss, se); st[si] = constructSTUtil(arr, ss, mid, si * 2 + 1) + constructSTUtil(arr, mid + 1, se, si * 2 + 2); return st[si]; } } static class UnionFind { // Number of connected components private int count; // Store a tree private int[] parent; // Record the "weight" of the tree private int[] size; public UnionFind(int n) { this.count = n; parent = new int[n]; size = new int[n]; for (int i = 0; i < n; i++) { parent[i] = i; size[i] = 1; } } public void union(int p, int q) { int rootP = find(p); int rootQ = find(q); if (rootP == rootQ) return; // The small tree is more balanced under the big tree if (size[rootP] > size[rootQ]) { parent[rootQ] = rootP; size[rootP] += size[rootQ]; } else { parent[rootP] = rootQ; size[rootQ] += size[rootP]; } count--; } public boolean connected(int p, int q) { int rootP = find(p); int rootQ = find(q); return rootP == rootQ; } private int find(int x) { while (parent[x] != x) { // Path compression parent[x] = parent[parent[x]]; x = parent[x]; } return x; } public int count() { return count; } } static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; public InputReader(InputStream st) { this.stream = st; } public int read() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int [] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public long[] nextLongArray(int n) { long [] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextLong(); } return a; } public static int[] shuffle(int[] a, Random gen) { for(int i = 0, n = a.length;i < n;i++) { int ind = gen.nextInt(n-i)+i; int d = a[i]; a[i] = a[ind]; a[ind] = d; } return a; } public String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
64781454607bb34146197e27c3ee9ce7
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class EasternExhibition { BufferedReader input; BufferedWriter output; StringTokenizer st; // My Solution void solve() throws IOException { int t = getInt(); while (t-->0){ int n = getInt(); long[] x = new long[n]; long[] y = new long[n]; for (int i = 0; i < n; i++) { x[i] = getLong(); y[i] = getLong(); } Arrays.sort(x); Arrays.sort(y); long possibleX = x[Math.floorDiv(n+2, 2)-1]-x[Math.floorDiv(n+1, 2)-1]+1; long possibleY = y[Math.floorDiv(n+2, 2)-1]-y[Math.floorDiv(n+1, 2)-1]+1; long ans = possibleX * possibleY; print(ans+"\n"); } } // Some basic functions int min(int...i){ int min = Integer.MAX_VALUE; for (int value : i) min = Math.min(min, value); return min; } int max(int...i){ int max = Integer.MIN_VALUE; for (int value : i) max = Math.max(max, value); return max; } // Printing stuff void print(int... i) throws IOException { for (int value : i) output.write(value + " "); } void print(long... l) throws IOException { for (long value : l) output.write(value + " "); } void print(String... s) throws IOException { for (String value : s) output.write(value); } void nextLine() throws IOException { output.write("\n"); } // Taking Inputs int[][] getIntMat(int n, int m) throws IOException { int[][] mat = new int[n][m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) mat[i][j] = getInt(); return mat; } char[][] getCharMat(int n, int m) throws IOException { char[][] mat = new char[n][m]; for (int i = 0; i < n; i++) { String s = input.readLine(); for (int j = 0; j < m; j++) mat[i][j] = s.charAt(j); } return mat; } int getInt() throws IOException { if(st ==null || !st.hasMoreTokens()) st = new StringTokenizer(input.readLine()); return Integer.parseInt(st.nextToken()); } int[] getInts(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = getInt(); return a; } long getLong() throws IOException { if(st==null || !st.hasMoreTokens()) st = new StringTokenizer(input.readLine()); return Long.parseLong(st.nextToken()); } long[] getLongs(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = getLong(); return a; } // Checks whether the code is running on OnlineJudge or LocalSystem boolean isOnlineJudge() { if (System.getProperty("ONLINE_JUDGE") != null) return true; try { return System.getProperty("LOCAL")==null; } catch (Exception e) { return true; } } // Handling CodeExecution public static void main(String[] args) throws Exception { new EasternExhibition().run(); } void run() throws IOException { // Defining Input Streams if (isOnlineJudge()) { input = new BufferedReader(new InputStreamReader(System.in)); output = new BufferedWriter(new OutputStreamWriter(System.out)); } else { input = new BufferedReader(new FileReader("input.txt")); output = new BufferedWriter(new FileWriter("output.txt")); } // Running Logic solve(); output.flush(); // Run example test cases if (!isOnlineJudge()) { BufferedReader output = new BufferedReader(new FileReader("output.txt")); BufferedReader answer = new BufferedReader(new FileReader("answer.txt")); StringBuilder outFile = new StringBuilder(); StringBuilder ansFile = new StringBuilder(); String temp; while ((temp = output.readLine()) != null) outFile.append(temp.trim()); while ((temp = answer.readLine()) != null) ansFile.append(temp.trim()); if (outFile.toString().equals(ansFile.toString())) System.out.println("Test Cases Passed!!!"); else System.out.println("Failed..."); } } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
56fd105fe11a949da099ff369fb21bb9
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.io.*; import java.util.*; public class Template { public static void main(String[] args) { FastScanner sc = new FastScanner(); int yo = sc.nextInt(); while (yo-- > 0) { int n =sc.nextInt(); int[] x = new int[n]; int[] y = new int[n]; for(int i = 0; i < n; i++) { x[i] = sc.nextInt(); y[i] = sc.nextInt(); } solve(x,y,n); } } private static void solve(int[] x, int[] y, int n) { if(n%2 == 1) { System.out.println(1); return; } Arrays.sort(x);Arrays.sort(y); long px = x[n/2]-x[n/2-1]+1; long py = y[n/2]-y[n/2-1]+1; long ans = px*py; System.out.println(ans); } static class Pair { int x; int y; public Pair(int x, int y) { this.x = x; this.y = y; } } 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), temp = a[i]; a[i] = a[oi]; a[oi] = temp; } Arrays.sort(a); } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static boolean[] sieve(int n) { boolean isPrime[] = new boolean[n + 1]; for (int i = 2; i <= n; i++) { if (isPrime[i]) continue; for (int j = 2 * i; j <= n; j += i) { isPrime[j] = true; } } return isPrime; } static int mod = 1000000007; static long pow(int a, long b) { if (b == 0) { return 1; } if (b == 1) { return a; } if (b % 2 == 0) { long ans = pow(a, b / 2); return ans * ans; } else { long ans = pow(a, (b - 1) / 2); return a * ans * ans; } } 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()); } } // For Input.txt and Output.txt // FileInputStream in = new FileInputStream("input.txt"); // FileOutputStream out = new FileOutputStream("output.txt"); // PrintWriter pw = new PrintWriter(out); // Scanner sc = new Scanner(in); }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
1e890e5c68a178437c3104ff2ca2a531
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.io.*; import java.util.*; public class Solution { public static void main(String args[]) throws Exception { BufferedReader Rb = new BufferedReader(new InputStreamReader(System.in)); int count = Integer.valueOf(Rb.readLine()); int counter = 0; while(counter++<count) { int n = Integer.valueOf(Rb.readLine()); long x[] = new long[n]; long y[] = new long[n]; for(int i = 0; i < n; i++) { String temp[] = Rb.readLine().split(" "); x[i] = Long.valueOf(temp[0]); y[i] = Long.valueOf(temp[1]); } Arrays.sort(x); Arrays.sort(y); long output = (n % 2 == 1)?1:(x[n / 2] - x[n / 2 - 1] + 1)*(y[n / 2] - y[n / 2 - 1] + 1); System.out.println(output); } } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
ca5e5f3d21ad11bdc9a231090f004c53
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.util.*; import java.io.*; public class B { 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) { int n = sc.nextInt(); int[] x = new int[n], y = new int[n]; for (int i = 0; i < n; ++i) { x[i] = sc.nextInt(); y[i] = sc.nextInt(); } if ((n&1) == 1) {out.println(1); continue;} Arrays.sort(x); Arrays.sort(y); out.println(((long)x[n>>1]-x[(n-1)>>1]+1)*((long)y[n>>1]-y[(n-1)>>1]+1)); } out.close(); } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
b3bc03b7bdf31ec082cd2c50351e1af0
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import javax.swing.*; import java.io.*; import java.util.*; import java.lang.*; public class B { 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[] x = new int[n]; int[] y = new int[n]; for(int i = 0; i < n; i++){ x[i] = sc.nextInt(); y[i] = sc.nextInt(); } ruffleSort(x); ruffleSort(y); long x1 = x[((n-1)/2)]; long x2 = x[n/2]; long y1 = y[((n-1)/2)]; long y2 = y[n/2]; out.println((x2-x1+1)*(y2-y1+1)); } //Pair Class static class Pair implements Comparable<Pair> { int x;int y; public Pair(int x, int y) { this.x = x; this.y = y; } @Override public int compareTo(Pair o) { return this.x-o.x; } } //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; // } // } static class FastReader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public FastReader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } 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(); } 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; } } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
e43326ec667dec4103573d500d3a8eea
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
//Author : Debojyoti Mandal //Attribute : Some of the methods are copied from GeeksforGeeks Website import java.util.*; import java.lang.*; import java.io.*; public class Main { static PrintWriter out=new PrintWriter(System.out); static Reader sc=new Reader(); //static FastReader sc=new FastReader(System.in); static double find(double x, double y, int [][] p) { double mind = 0; for(int i = 0; i < p.length; i++) { double a = p[i][0], b = p[i][1]; double add=Math.abs(x-a) + Math.abs(y-b); mind += add; } return mind; } // Function to calculate the minimum sum // of the euclidean distances to all points static double getMinDistSum(int [][]p) { // Calculate the centroid double x = 0, y = 0; for(int i = 0; i < p.length; i++) { x += p[i][0]; y += p[i][1]; } x = x / p.length; y = y / p.length; // Calculate distance of all // points double mind = find(x, y, p); return mind; } public static void main (String[] args) throws java.lang.Exception { try{ // long n=sc.nextLong(); // int n=sc.nextInt(); // String s=sc.next(); // boolean flag=true; // flag(flag); // ArrayList<Long> al=new ArrayList<>(); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int x[]=new int[n]; int y[]=new int[n]; int p[][]=new int[n][2]; for(int i=0;i<n;i++) { x[i]=sc.nextInt(); y[i]=sc.nextInt(); p[i][0]=x[i]; p[i][1]=y[i]; } int ans=0; double min=getMinDistSum(p); //for(int i=0;i<n;i++) // { // for(int j=0;j<n;j++) // { // find(i,j) // } // } long res=1; if(n%2==0) {sort(x); sort(y); int ind=n/2; long val1=x[ind]-x[ind - 1]; val1++; long val2=y[ind]-y[ind - 1]; val2++; res=val1*val2; } out.println(res); } out.flush(); out.close(); } catch(Exception e) {} } //Soluntion Ends Here.............................................ereH sdnE noitnuloS //Template// static void flag(boolean flag) { out.println(flag ? "YES" : "NO"); out.flush(); } // Map<Long,Long> map=new HashMap<>(); // for(int i=0;i<n;i++) // { // if(!map.containsKey(a[i])) // map.put(a[i],1); // else // map.replace(a[i],map.get(a[i])+1); // } // Set<Map.Entry<Long,Long>> hmap=map.entrySet(); // for(Map.Entry<Long,Long> data : hmap) // { // } 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 void sort(long[] a) { ArrayList<Long> l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b%a, a); } static void calcsubarray(long a[],long x[], int n, int c) { for (int i=0; i<(1<<n); i++) { long s = 0; for (int j=0; j<n; j++) if ((i & (1<<j))==0) s += a[j+c]; x[i] = s; } } static class FastReader{ byte[] buf = new byte[2048]; int index, total; InputStream in; FastReader(InputStream is) { in = is; } int scan() throws IOException { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) { return -1; } } return buf[index++]; } String next() throws IOException { int c; for (c = scan(); c <= 32; c = scan()); StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) { sb.append((char) c); } return sb.toString(); } int nextInt() throws IOException { int c, val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } long nextLong() throws IOException { int c; long val = 0; for (c = scan(); c <= 32; c = scan()); boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } } 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(); } } } // Thank You !
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
407936e77a6722b5c93c4534610d05ab
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.util.*; public class Main{ 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(); ArrayList<Long> x=new ArrayList<>(); ArrayList<Long> y=new ArrayList<>(); for(int i=1;i<=n;i++) { long a = sc.nextLong(); long b = sc.nextLong(); x.add(a); y.add(b); } if(n%2!=0) { System.out.print(1+"\n"); } else { Collections.sort(x); Collections.sort(y); long diff=x.get(n/2)-x.get(n/2-1)+1; long diff1=y.get(n/2)-y.get(n/2-1)+1; System.out.println(diff*diff1); } } } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
cf6ca8ef2835e512556f352aedb4710e
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int t=scn.nextInt(); while(t-->0) { int n=scn.nextInt(); long[] x=new long[n]; long[] y=new long[n]; for(int i=0;i<n;i++){ x[i]=scn.nextLong(); y[i]=scn.nextLong(); } if((n&1)!=0){ System.out.println(1); }else{ Arrays.sort(x); Arrays.sort(y); long ans=(x[n/2]-x[n/2-1]+1)*(y[n/2]-y[n/2-1]+1); System.out.println(ans); } } }}
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
9b133ee73c0eed66afec157278f5b26d
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.io.*; import java.util.*; public class easternExhibition { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); long x[] = new long[n]; long y[] = new long[n]; for(int i =0; i<n; i++) { x[i] = sc.nextInt(); y[i] = sc.nextInt(); } ruffleSort(x); ruffleSort(y); if(n%2==0) { long xx = x[n/2]-x[(n/2)-1]; xx++; long yy = y[n/2]-y[(n/2)-1]; yy++; long ans = xx*yy; System.out.println(ans); } else{ System.out.println(1); } } } static void ruffleSort(long a[]) { int n = a.length; Random r = new Random(); for (int i = 0; i < n; i++) { int oi = r.nextInt(n); long temp = a[oi]; a[oi] = a[i]; a[i] = temp; } Arrays.sort(a); } static long find(long sumx, long sumy, long a, long b) { long dist = Math.abs(sumx-a) + Math.abs(sumy-b); return dist; } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
7c77332a184acba66e5e9175ca3ca162
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.util.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class B_Eastern_Exhibition { public static void s() { int n=sc.nextInt(); long[] x = new long[n], y = new long[n]; for(int i=0; i<n; i++) { x[i] = sc.nextInt(); y[i] = sc.nextInt(); } Arrays.sort(x); Arrays.sort(y); if(n%2 == 1) { p.writeln(1); return; } else { p.writeln((x[n/2]-x[n/2-1]+1)*(y[n/2]-y[n/2-1]+1)); } } public static void main(String[] args) { int t = 1; t = sc.nextInt(); while (t-- != 0) { s(); } p.print(); } public static boolean debug = false; static void debug(String st) { if(debug) p.writeln(st); } static final Integer MOD = (int) 1e9 + 7; static final FastReader sc = new FastReader(); static final Print p = new Print(); static class Functions { 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 void sort(long... a) { ArrayList<Long> l = new ArrayList<>(); for (long i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static int max(int... a) { int max = Integer.MIN_VALUE; for (int val : a) max = Math.max(val, max); return max; } static int min(int... a) { int min = Integer.MAX_VALUE; for (int val : a) min = Math.min(val, min); return min; } static long min(long... a) { long min = Long.MAX_VALUE; for (long val : a) min = Math.min(val, min); return min; } static long max(long... a) { long max = Long.MIN_VALUE; for (long val : a) max = Math.max(val, max); return max; } static long sum(long... a) { long sum = 0; for (long val : a) sum += val; return sum; } static int sum(int... a) { int sum = 0; for (int val : a) sum += val; return sum; } public static long mod_add(long a, long b) { return (a % MOD + b % MOD + MOD) % MOD; } public static long pow(long a, long b) { long res = 1; while (b > 0) { if ((b & 1) != 0) res = mod_mul(res, a); a = mod_mul(a, a); b >>= 1; } return res; } public static long mod_mul(long a, long b) { long res = 0; a %= MOD; while (b > 0) { if ((b & 1) > 0) { res = mod_add(res, a); } a = (2 * a) % MOD; b >>= 1; } return res; } public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } public static long factorial(long n) { long res = 1; for (int i = 1; i <= n; i++) { res = (i % MOD * res % MOD) % MOD; } return res; } public static int count(int[] arr, int x) { int count = 0; for (int val : arr) if (val == x) count++; return count; } public static ArrayList<Integer> generatePrimes(int n) { boolean[] primes = new boolean[n]; for (int i = 2; i < primes.length; i++) primes[i] = true; for (int i = 2; i < primes.length; i++) { if (primes[i]) { for (int j = i * i; j < primes.length; j += i) { primes[j] = false; } } } ArrayList<Integer> arr = new ArrayList<>(); for (int i = 0; i < primes.length; i++) { if (primes[i]) arr.add(i); } return arr; } } static class Print { StringBuffer strb = new StringBuffer(); public void write(Object str) { strb.append(str); } public void writes(Object str) { char c = ' '; strb.append(str).append(c); } public void writeln(Object str) { char c = '\n'; strb.append(str).append(c); } public void writeln() { char c = '\n'; strb.append(c); } public void yes() { char c = '\n'; writeln("YES"); } public void no() { writeln("NO"); } public void writes(int... arr) { for (int val : arr) { write(val); write(' '); } } public void writes(long... arr) { for (long val : arr) { write(val); write(' '); } } public void writeln(int... arr) { for (int val : arr) { writeln(val); } } public void print() { System.out.print(strb); } public void println() { System.out.println(strb); } } 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()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } double[] readArrayDouble(int n) { double[] a = new double[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } String nextLine() { String str = new String(); try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
9de73de61d7a69a8df89e95317aa3a60
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class EasternExibition { public static void main(String[] args) { int[] xs, ys; Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); xs = new int[n]; ys = new int[n]; for (int i = 0; i < n; i++) { int x = sc.nextInt(); int y = sc.nextInt(); xs[i] = x; ys[i] = y; } Arrays.sort(xs); Arrays.sort(ys); if (n % 2 == 0) { long xmids =xs[n / 2] - xs[n / 2 - 1] ; long ymids = ys[n / 2] - ys[n / 2 - 1] ; System.out.println((xmids + 1) * (ymids + 1)); } else { System.out.println("1"); } } sc.close(); } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
803dfabaeff96fdc62a11d2c902dbd95
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.io.*; import java.util.*; import java.math.*; public class Solution{ public static void main(String[] args) { TaskA solver = new TaskA(); int t = in.nextInt(); for (int i = 1; i <= t ; i++) { solver.solve(i, in, out); } // solver.solve(1, in, out); out.flush(); out.close(); } static class TaskA { public void solve(int testNumber, InputReader in, PrintWriter out) { int n=in.nextInt(); int[]x=new int[n]; int[]y=new int[n]; for(int i=0;i<n;i++) { x[i]=in.nextInt(); y[i]=in.nextInt(); } Arrays.sort(x);Arrays.sort(y); if(n%2==1) { println(1);return; } else { long x1=(x[n/2]-x[n/2-1]+1); long y2=(y[n/2]-y[n/2-1]+1); println(x1*y2); } } } static boolean check(Pair[]arr,int mid,int n) { int c=0; for(int i=0;i<n;i++) { if(mid-1-arr[i].first<=c&&c<=arr[i].second) { c++; } } return c>=mid; } static long sum(int[]arr) { long s=0; for(int x:arr) { s+=x; } return s; } static long sum(long[]arr) { long s=0; for(long x:arr) { s+=x; } return s; } static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } static void sort(int[] a) { ArrayList<Integer> q = new ArrayList<>(); for (int i : a) q.add(i); Collections.sort(q); for (int i = 0; i < a.length; i++) a[i] = q.get(i); } static void sort(long[] a) { ArrayList<Long> q = new ArrayList<>(); for (long i : a) q.add(i); Collections.sort(q); for (int i = 0; i < a.length; i++) a[i] = q.get(i); } static void println(int[][]arr) { for(int i=0;i<arr.length;i++) { for(int j=0;j<arr[0].length;j++) { print(arr[i][j]+" "); } print("\n"); } } static void println(long[][]arr) { for(int i=0;i<arr.length;i++) { for(int j=0;j<arr[0].length;j++) { print(arr[i][j]+" "); } print("\n"); } } static void println(int[]arr){ for(int i=0;i<arr.length;i++) { print(arr[i]+" "); } print("\n"); } static void println(long[]arr){ for(int i=0;i<arr.length;i++) { print(arr[i]+" "); } print("\n"); } static long[]input(int n){ long[]arr=new long[n]; for(int i=0;i<n;i++) { arr[i]=in.nextInt(); } return arr; } static long[]input(){ long n= in.nextInt(); long[]arr=new long[(int)n]; for(int i=0;i<n;i++) { arr[i]=in.nextLong(); } return arr; } //////////////////////////////////////////////////////// static class Pair { long first; long second; Pair(long x, long y) { this.first = x; this.second = y; } } static void sortS(Pair arr[]) { Arrays.sort(arr, new Comparator<Pair>() { @Override public int compare(Pair p1, Pair p2) { return (int)(p1.second - p2.second); } }); } static void sortF(Pair arr[]) { Arrays.sort(arr, new Comparator<Pair>() { @Override public int compare(Pair p1, Pair p2) { return (int)(p1.first - p2.first); } }); } ///////////////////////////////////////////////////////////// static InputStream inputStream = System.in; static OutputStream outputStream = System.out; static InputReader in = new InputReader(inputStream); static PrintWriter out = new PrintWriter(outputStream); static void println(long c) { out.println(c); } static void print(long c) { out.print(c); } static void print(int c) { out.print(c); } static void println(int x) { out.println(x); } static void print(String s) { out.print(s); } static void println(String s) { out.println(s); } static void println(boolean b) { out.println(b); } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
82310a7db6860cdba95f91d3c1aaa50f
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import static java.lang.Math.*; import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { InputReader fs = new InputReader(System.in); PrintWriter pw = new PrintWriter(System.out); int t = fs.readInt(); for (int tt = 0; tt < t; tt++) { int n = fs.readInt(); ArrayList<Integer> X = new ArrayList<>(); ArrayList<Integer> Y = new ArrayList<>(); for (int nn = 0; nn < n; nn++) { int x = fs.readInt(); int y = fs.readInt(); X.add(x); Y.add(y); } Collections.sort(X); Collections.sort(Y); int res = 0; long a = X.get((n)/2) - X.get((n-1)/2) + 1; long b = Y.get((n)/2) - Y.get((n-1)/2) + 1; pw.println(a*b); } pw.flush(); pw.close(); } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public double readDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, readInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, readInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public long readLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public int[] readIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = readInt(); } return a; } public int[] readIntArrayShifted(int n) { int[] a = new int[n + 1]; for (int i = 0; i < n; i++) { a[i + 1] = readInt(); } return a; } public long[] readLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = readLong(); } return a; } public String next() { return readString(); } interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
2a2bae1872e1842d32080a8acd9382d0
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.util.*; import java.util.Map.Entry; import java.math.*; public class Simple{ public static class Pair{ int x; long y; public Pair(int x,long y){ this.x = x; this.y = y; } } static int power(int x, int y, int p) { // Initialize result int res = 1; // Update x if it is more than or // equal to p x = x % p; while (y > 0) { // If y is odd, multiply x // with result if (y % 2 == 1) res = (res * x) % p; // y must be even now y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } // Returns n^(-1) mod p static int modInverse(int n, int p) { return power(n, p - 2, p); } // Returns nCr % p using Fermat's // little theorem. static int nCrModPFermat(int n, int r, int p) { if (n<r) return 0; // Base case if (r == 0) return 1; // Fill factorial array so that we // can find all factorial of r, n // and n-r int[] fac = new int[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; } static int nCrModp(int n, int r, int p) { if (r > n - r) r = n - r; // The array C is going to store last // row of pascal triangle at the end. // And last entry of last row is nCr int C[] = new int[r + 1]; C[0] = 1; // Top row of Pascal Triangle // One by constructs remaining rows of Pascal // Triangle from top to bottom for (int i = 1; i <= n; i++) { // Fill entries of current row using previous // row values for (int j = Math.min(i, r); j > 0; j--) // nCj = (n-1)Cj + (n-1)C(j-1); C[j] = (C[j] + C[j - 1]) % p; } return C[r]; } // public static int helper(int mat[][],int n,int m,int i,int j,int min,int max){ // if(j==m){ // return max- min; // } // if(dp[i][j]){ // return dp[] // } // int ans1 = Integer.MAX_VALUE; // int ans2 = Integer.MAX_VALUE; // //we take that element // for(int k = 0;k<n;k++){ // ans1 = Math.min(ans1,helper(mat, n, m, i+k, j+1, Math.min(min,mat[i+k][j+1]), Math.max(max,mat))); // } // //we do not take that element // return dp[i][j] = Math.min(ans1,ans2); // } public static void main(String args[]){ //System.out.println("Hello Java"); Scanner s = new Scanner(System.in); int t = s.nextInt(); for(int t1 = 1;t1<=t;t1++){ int n = s.nextInt(); long xsum = 0; long ysum = 0; long x[] = new long[n]; long y[] = new long[n]; for(int i=0;i<n;i++){ x[i] = s.nextInt(); y[i] = s.nextInt(); } if(n%2==1){ System.out.println(1); continue; } Arrays.sort(x); Arrays.sort(y); long xd = x[n/2] - x[n/2 - 1]+1; long yd = y[n/2] - y[n/2 - 1]+1; long ans = xd*yd; System.out.println(ans); } } } /* 4 2 2 7 0 2 5 -2 3 5 0*x1 + 1*x2 + 2*x3 + 3*x4 */
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
dc73c5a8c73d1e40c82d6ccde34c36be
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.io.*; import java.util.Arrays; import java.util.InputMismatchException; /** * Provide prove of correctness before implementation. Implementation can cost a lot of time. * Anti test that prove that it's wrong. * <p> * Do not confuse i j k g indexes, upTo and length. Do extra methods!!! Write more informative names to simulation * <p> * Will program ever exceed limit? * Try all approaches with prove of correctness if task is not obvious. * If you are given formula/rule: Try to play with it. * Analytic solution/Hardcoded solution/Constructive/Greedy/DP/Math/Brute force/Symmetric data * Number theory * Game theory (optimal play) that consider local and global strategy. */ public class MS_7_B { private void solveOne() { int m = nextInt(); int[] b = new int[m]; int[] c = new int[m]; for (int i = 0; i < m; i++) { b[i] = nextInt(); c[i] = nextInt(); } long delta1 = 0; long delta2 = 0; radixSort2(b); radixSort2(c); if(m % 2 == 0) { delta1 = b[(m - 1) / 2 + 1] - b[(m - 1) / 2]; delta2 = c[(m - 1) / 2 + 1] - c[(m - 1) / 2]; } System.out.println((delta1 + 1) * (delta2 + 1)); } public static int[] radixSort2(int[] a) { int n = a.length; int[] c0 = new int[0x101]; int[] c1 = new int[0x101]; int[] c2 = new int[0x101]; int[] c3 = new int[0x101]; for (int v : a) { c0[(v & 0xff) + 1]++; c1[(v >>> 8 & 0xff) + 1]++; c2[(v >>> 16 & 0xff) + 1]++; c3[(v >>> 24 ^ 0x80) + 1]++; } for (int i = 0; i < 0xff; i++) { c0[i + 1] += c0[i]; c1[i + 1] += c1[i]; c2[i + 1] += c2[i]; c3[i + 1] += c3[i]; } int[] t = new int[n]; for (int v : a) t[c0[v & 0xff]++] = v; for (int v : t) a[c1[v >>> 8 & 0xff]++] = v; for (int v : a) t[c2[v >>> 16 & 0xff]++] = v; for (int v : t) a[c3[v >>> 24 ^ 0x80]++] = v; return a; } private void solve() { int t = nextInt(); for (int tt = 0; tt < t; tt++) { solveOne(); } } class AssertionRuntimeException extends RuntimeException { AssertionRuntimeException(Object expected, Object actual, Object... input) { super("expected = " + expected + ",\n actual = " + actual + ",\n " + Arrays.deepToString(input)); } } private int nextInt() { return System.in.readInt(); } private long nextLong() { return System.in.readLong(); } private String nextString() { return System.in.readString(); } private int[] nextIntArr(int n) { return System.in.readIntArray(n); } private long[] nextLongArr(int n) { return System.in.readLongArray(n); } public static void main(String[] args) { new MS_7_B().run(); } static class System { private static FastInputStream in; private static FastPrintStream out; } private void run() { System.in = new FastInputStream(java.lang.System.in); System.out = new FastPrintStream(java.lang.System.out); solve(); System.out.flush(); } private static class FastPrintStream { private static final int BUF_SIZE = 8192; private final byte[] buf = new byte[BUF_SIZE]; private final OutputStream out; private int ptr = 0; private FastPrintStream() { this(java.lang.System.out); } public FastPrintStream(OutputStream os) { this.out = os; } public FastPrintStream(String path) { try { this.out = new FileOutputStream(path); } catch (FileNotFoundException e) { throw new RuntimeException("FastWriter"); } } public FastPrintStream print(byte b) { buf[ptr++] = b; if (ptr == BUF_SIZE) innerflush(); return this; } public FastPrintStream print(char c) { return print((byte) c); } public FastPrintStream print(char[] s) { for (char c : s) { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerflush(); } return this; } public FastPrintStream print(String s) { s.chars().forEach(c -> { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerflush(); }); return this; } //can be optimized public FastPrintStream print0(char[] s) { if (ptr + s.length < BUF_SIZE) { for (char c : s) { buf[ptr++] = (byte) c; } } else { for (char c : s) { buf[ptr++] = (byte) c; if (ptr == BUF_SIZE) innerflush(); } } return this; } //can be optimized public FastPrintStream print0(String s) { if (ptr + s.length() < BUF_SIZE) { for (int i = 0; i < s.length(); i++) { buf[ptr++] = (byte) s.charAt(i); } } else { for (int i = 0; i < s.length(); i++) { buf[ptr++] = (byte) s.charAt(i); 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 FastPrintStream print(int x) { if (x == Integer.MIN_VALUE) { return print((long) x); } if (ptr + 12 >= BUF_SIZE) innerflush(); if (x < 0) { print((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 FastPrintStream print(long x) { if (x == Long.MIN_VALUE) { return print("" + x); } if (ptr + 21 >= BUF_SIZE) innerflush(); if (x < 0) { print((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 FastPrintStream print(double x, int precision) { if (x < 0) { print('-'); x = -x; } x += Math.pow(10, -precision) / 2; // if(x < 0){ x = 0; } print((long) x).print("."); x -= (long) x; for (int i = 0; i < precision; i++) { x *= 10; print((char) ('0' + (int) x)); x -= (int) x; } return this; } public FastPrintStream println(int[] a, int from, int upTo, char separator) { for (int i = from; i < upTo; i++) { print(a[i]); print(separator); } print('\n'); return this; } public FastPrintStream println(int[] a) { return println(a, 0, a.length, ' '); } public FastPrintStream println(long[] a, int from, int upTo, char separator) { for (int i = from; i < upTo; i++) { print(a[i]); print(separator); } print('\n'); return this; } public FastPrintStream println(long[] a) { return println(a, 0, a.length, ' '); } public FastPrintStream println(char c) { return print(c).println(); } public FastPrintStream println(int x) { return print(x).println(); } public FastPrintStream println(long x) { return print(x).println(); } public FastPrintStream println(String x) { return print(x).println(); } public FastPrintStream println(double x, int precision) { return print(x, precision).println(); } public FastPrintStream println() { return print((byte) '\n'); } public FastPrintStream printf(String format, Object... args) { return print(String.format(format, args)); } 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"); } } } private static class FastInputStream { private boolean finished = false; private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public FastInputStream(InputStream stream) { this.stream = stream; } public double[] readDoubleArray(int size) { double[] array = new double[size]; for (int i = 0; i < size; i++) { array[i] = readDouble(); } return array; } public String[] readStringArray(int size) { String[] array = new String[size]; for (int i = 0; i < size; i++) { array[i] = readString(); } return array; } public char[] readCharArray(int size) { char[] array = new char[size]; for (int i = 0; i < size; i++) { array[i] = readCharacter(); } return array; } public void readIntArrays(int[]... arrays) { for (int i = 0; i < arrays[0].length; i++) { for (int j = 0; j < arrays.length; j++) { arrays[j][i] = readInt(); } } } public void readLongArrays(long[]... arrays) { for (int i = 0; i < arrays[0].length; i++) { for (int j = 0; j < arrays.length; j++) { arrays[j][i] = readLong(); } } } public void readDoubleArrays(double[]... arrays) { for (int i = 0; i < arrays[0].length; i++) { for (int j = 0; j < arrays.length; j++) { arrays[j][i] = readDouble(); } } } public char[][] readTable(int rowCount, int columnCount) { char[][] table = new char[rowCount][]; for (int i = 0; i < rowCount; i++) { table[i] = this.readCharArray(columnCount); } return table; } public int[][] readIntTable(int rowCount, int columnCount) { int[][] table = new int[rowCount][]; for (int i = 0; i < rowCount; i++) { table[i] = readIntArray(columnCount); } return table; } public double[][] readDoubleTable(int rowCount, int columnCount) { double[][] table = new double[rowCount][]; for (int i = 0; i < rowCount; i++) { table[i] = this.readDoubleArray(columnCount); } return table; } public long[][] readLongTable(int rowCount, int columnCount) { long[][] table = new long[rowCount][]; for (int i = 0; i < rowCount; i++) { table[i] = readLongArray(columnCount); } return table; } public String[][] readStringTable(int rowCount, int columnCount) { String[][] table = new String[rowCount][]; for (int i = 0; i < rowCount; i++) { table[i] = this.readStringArray(columnCount); } return table; } public String readText() { StringBuilder result = new StringBuilder(); while (true) { int character = read(); if (character == '\r') { continue; } if (character == -1) { break; } result.append((char) character); } return result.toString(); } public void readStringArrays(String[]... arrays) { for (int i = 0; i < arrays[0].length; i++) { for (int j = 0; j < arrays.length; j++) { arrays[j][i] = readString(); } } } public long[] readLongArray(int size) { long[] array = new long[size]; for (int i = 0; i < size; i++) { array[i] = readLong(); } return array; } public int[] readIntArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = readInt(); } return array; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int peek() { if (numChars == -1) { return -1; } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { return -1; } if (numChars <= 0) { return -1; } } return buf[curChar]; } public int peekNonWhitespace() { while (isWhitespace(peek())) { read(); } return peek(); } public int readInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long readLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) { res.appendCodePoint(c); } c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private String readLine0() { StringBuilder buf = new StringBuilder(); int c = read(); while (c != '\n' && c != -1) { if (c != '\r') { buf.appendCodePoint(c); } c = read(); } return buf.toString(); } public String readLine() { String s = readLine0(); while (s.trim().length() == 0) { s = readLine0(); } return s; } public String readLine(boolean ignoreEmptyLines) { if (ignoreEmptyLines) { return readLine(); } else { return readLine0(); } } public char readCharacter() { int c = read(); while (isSpaceChar(c)) { c = read(); } return (char) c; } public double readDouble() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') { return res * Math.pow(10, readInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') { return res * Math.pow(10, readInt()); } if (c < '0' || c > '9') { throw new InputMismatchException(); } m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public boolean isExhausted() { int value; while (isSpaceChar(value = peek()) && value != -1) { read(); } return value == -1; } public String next() { return readString(); } public SpaceCharFilter getFilter() { return filter; } public void setFilter(SpaceCharFilter filter) { this.filter = filter; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
1adfc578d191d6d6c6396c5743eee2dd
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
import java.io.*; import java.lang.*; import java.util.*; public class Main { public static int mod = (int) 1e9 + 7; // **** -----> Disjoint Set Union(DSU) Start ********** public static int findPar(int node, int[] parent) { if (parent[node] == node) return node; return parent[node] = findPar(parent[node], parent); } public static boolean union(int u, int v, int[] rank, int[] parent) { u = findPar(u, parent); v = findPar(v, parent); if(u == v) return false; if (rank[u] < rank[v]) parent[u] = v; else if (rank[u] > rank[v]) parent[v] = u; else { parent[u] = v; rank[v]++; } return true; } // **** DSU Ends *********** public static String toBinary(int decimal) {StringBuilder sb = new StringBuilder();while (decimal > 0) {sb.append(decimal % 2);decimal = decimal / 2;}return sb.reverse().toString();} public static boolean isPalindrome(String s) {int i = 0, j = s.length() - 1;while (i < j) {if (s.charAt(i) != s.charAt(j))return false;i++;j--;}return true;} public static boolean isPalindrome(int[] arr) {int i = 0, j = arr.length - 1;while (i < j) {if (arr[i] != arr[j])return false;}return true;} public static int pow(int x, int y) {int res = 1;x = x % mod;if (x == 0)return 0;while (y > 0) {if ((y & 1) != 0)res = (res * x) % mod;y = y >> 1;x = (x * x) % mod;}return res;} public static int gcd(int a, int b) {if (b == 0)return a;return gcd(b, a % b);} public static long gcd(long a, long b) {if (b == 0)return a;return gcd(b, a % b);} public static void sort(long[] a) {Random rnd = new Random();for (int i = 0; i < a.length; i++) {int pos = i + rnd.nextInt(a.length - i);long temp = a[i];a[i] = a[pos];a[pos] = temp;}Arrays.sort(a);} public static void reverse(int a[]) {int i, k, t, n = a.length;for (i = 0; i < n / 2; i++) {t = a[i];a[i] = a[n - i - 1];a[n - i - 1] = t;}} public static void sort(int[] a) {Random rnd = new Random();for (int i = 0; i < a.length; i++) {int pos = i + rnd.nextInt(a.length - i);int temp = a[i];a[i] = a[pos];a[pos] = temp;}Arrays.sort(a);} public static void revSort(int[] a) {Random rnd = new Random();for (int i = 0; i < a.length; i++) {int pos = i + rnd.nextInt(a.length - i);int temp = a[i];a[i] = a[pos];a[pos] = temp;}Arrays.sort(a);reverse(a);} public static long LCM(long a, long b) {if (a > b) {long t = a;a = b;b = t;}a /= gcd(a, b);return (a * b);} public static int findMax(int[] a, int left, int right) {int res = left;int max = a[left];for (int i = left + 1; i <= right; i++) {if (a[i] > max) {max = a[i];res = i;}}return res;} public static long findClosest(long arr[], long target) {int n = arr.length;if (target <= arr[0])return arr[0];if (target >= arr[n - 1])return arr[n - 1];int i = 0, j = n, mid = 0;while (i < j) {mid = (i + j) / 2;if (arr[mid] == target)return arr[mid];if (target < arr[mid]) {if (mid > 0 && target > arr[mid - 1])return getClosest(arr[mid - 1], arr[mid], target);j = mid;} else {if (mid < n - 1 && target < arr[mid + 1])return getClosest(arr[mid], arr[mid + 1], target);i = mid + 1;}}return arr[mid];} public static long getClosest(long val1, long val2, long target) {if (target - val1 >= val2 - target)return val2;else return val1;} public static int findClosest(int arr[], int target) { int n = arr.length; if (target <= arr[0]) return arr[0]; if (target >= arr[n - 1]) return arr[n - 1]; int i = 0, j = n, mid = 0; while (i < j) { mid = (i + j) / 2; if (arr[mid] == target) return arr[mid];if (target < arr[mid]) {if (mid > 0 && target > arr[mid - 1])return getClosest(arr[mid - 1], arr[mid], target);j = mid;} else {if (mid < n - 1 && target < arr[mid + 1])return getClosest(arr[mid], arr[mid + 1], target);i = mid + 1;}}return arr[mid];} public static int getClosest(int val1, int val2, int target) {if (target - val1 >= val2 - target)return val2;else return val1;} public static String reverse(String str) {String nstr = "";char ch;for (int i = 0; i < str.length(); i++) {ch = str.charAt(i);nstr = ch + nstr;}return nstr;} public static boolean isPrime(int 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 * i <= n; i = i + 6)if (n % i == 0 || n % (i + 2) == 0)return false;return true;} public static int xorSum(int arr[], int n){int bits = 0;for (int i = 0; i < n; ++i)bits |= arr[i];int ans = bits * (int)Math.pow(2, n-1);return ans;} public static ArrayList<Integer> primeFactors(int n) { ArrayList<Integer> res = new ArrayList<>();while (n%2 == 0) { res.add(2); n = n/2; } for (int i = 3; i <= Math.sqrt(n); i = i+2) { while (n%i == 0) { res.add(i); n = n/i; } } if (n > 2) res.add(n);return res;} public static ArrayList<Long> primeFactors(long n) { ArrayList<Long> res = new ArrayList<>();while (n%2 == 0) { res.add(2L); n = n/2; } for (long i = 3; i <= Math.sqrt(n); i = i+2) { while (n%i == 0) { res.add(i); n = n/i; } } if (n > 2) res.add(n);return res;} static int lower_bound(int array[], int low, int high, int key){ int mid; while (low < high) { mid = low + (high - low) / 2; if (key <= array[mid]) high = mid; else low = mid + 1; } if (low < array.length && array[low] < key) low++; return low; } /********************************* Start Here ***********************************/ // int mod = 1000000007; // static HashMap<Integer, HashMap<Long, Integer>> map; public static void main(String[] args) throws java.lang.Exception { if (System.getProperty("ONLINE_JUDGE") == null) { PrintStream ps = new PrintStream(new File("output.txt")); System.setOut(ps); } FastScanner sc = new FastScanner("input.txt"); int T = sc.nextInt(); // int T = 1; while (T-- > 0) { int n = sc.nextInt(); long[] even = new long[n]; long[] odd = new long[n]; for(int i=0;i<n;i++) { even[i] = sc.nextLong(); odd[i] = sc.nextLong(); } if(n%2 == 1) System.out.println("1"); else { Arrays.sort(even); Arrays.sort(odd); System.out.println((even[n/2] - even[n/2 - 1] + 1) * (odd[n/2] - odd[n/2 - 1] + 1)); } } System.out.close(); } public static int solve(long[] arr, int i, long k){ int res = 0; return res; } public static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(String s) { try { br = new BufferedReader(new FileReader(s)); } catch (FileNotFoundException e) { br = new BufferedReader(new InputStreamReader(System.in)); } } String nextToken() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return st.nextToken(); } public String nextLine() { if (st == null || !st.hasMoreTokens()) { try { return br.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } return st.nextToken("\n"); } public String[] readStringArray(int n) { String[] a = new String[n]; for (int i = 0; i < n; i++) { a[i] = next(); } return a; } int nextInt() { return Integer.parseInt(nextToken()); } String next() { return nextToken(); } long nextLong() { return Long.parseLong(nextToken()); } double nextDouble() { return Double.parseDouble(nextToken()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } int[][] read2dArray(int n, int m) { int[][] a = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { a[i][j] = nextInt(); } } return a; } long[][] read2dlongArray(int n, int m) { long[][] a = new long[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { a[i][j] = nextLong(); } } return a; } } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output
PASSED
aa69af860551df813e038d279e36d614
train_110.jsonl
1613658900
You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.
256 megabytes
// package com.company; import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); StringBuilder sb = new StringBuilder(); while(t-- > 0) { int n = in.nextInt(); int[] x = new int[n]; int[] y = new int[n]; for(int i = 0; i < n; ++i) { x[i] = in.nextInt(); y[i] = in.nextInt(); } Arrays.sort(x); Arrays.sort(y); long answer = 0; if(n % 2 == 0) { int first = n / 2 - 1; int second = n / 2; answer = (long) (x[second] - x[first] + 1) * (long) (y[second] - y[first] + 1); } else { answer = 1; } sb.append(answer + "\n"); } System.out.print(sb.toString()); } }
Java
["6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0"]
1 second
["1\n4\n4\n4\n3\n1"]
NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.
Java 11
standard input
[ "binary search", "geometry", "shortest paths", "sortings" ]
e0a1dc397838852957d0e15ec98d5efe
First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.
1,500
For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.
standard output