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
sequencelengths
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
49c0e49f70b936456ce26fd10b488490
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { // write your code here Scanner sc=new Scanner(System.in); int n=sc.nextInt(); for(int j=0; j<n; j++){ int[] arr=new int[3]; for(int i=0; i<3; i++){ arr[i]=sc.nextInt(); } if(arr[0]==1){ System.out.println(1); continue; } else{ int a=arr[0]-1; int b=Math.abs(arr[1]-arr[2]) + arr[2]-1; if(a==b){ System.out.println(3); continue; } else{ int c=(Math.min(a,b)); if(c==a){ System.out.println(1); continue; } else{ System.out.println(2); continue; } } } } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
117fb043736c9d05485013a986ec1abf
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.io.IOException; import java.util.Scanner; public class Elevators { public static void main(String[] args) throws IOException { Scanner scanner = new Scanner(System.in); int [] arr = new int [3]; String message = scanner.nextLine().trim(); int numOfInputs = Integer.valueOf(message); for (int i = 0; i < numOfInputs; i++) { String input = scanner.nextLine(); String[] arrOfStr = input.split(" "); solve(Integer.valueOf(arrOfStr[0]), Integer.valueOf(arrOfStr[1]), Integer.valueOf(arrOfStr[2])); } } private static void solve(int a, int b, int c) { boolean isSecondGoingDown = false; int secondTime = 0; if (c < b) { isSecondGoingDown = true; } if (isSecondGoingDown) { secondTime = b; } else { secondTime = (c - b) + (c); } // if (a == secondTime) return 3; // return a < secondTime ? 1 : 2; if (a == secondTime) { System.out.println(3); return; } if (a < secondTime) { System.out.println(1); } else { System.out.println(2); } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
3828788b67e9ef02c2553410fe8bc56e
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.io.BufferedInputStream; import java.io.BufferedWriter; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.Scanner; public class A { static PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); static Scanner scanner=new Scanner(new BufferedInputStream(System.in)); public static void main(String[] args) { int num = scanner.nextInt(); while (num--!=0){ int a,b,c; a = scanner.nextInt(); b = scanner.nextInt(); c = scanner.nextInt(); a--; c= c -1 + Math.abs(b-c); if (a <c ){ out.println(1); }else if (a>c){ out.println(2); }else { out.println(3); } } out.flush(); } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
6d8f3fe2437980d5b8267807fcf8366f
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.io.BufferedInputStream; import java.io.BufferedWriter; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.Scanner; public class A { static PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); static Scanner scanner=new Scanner(new BufferedInputStream(System.in)); public static void main(String[] args) { int num = scanner.nextInt(); while (num--!=0){ int a,b,c; a = scanner.nextInt(); b = scanner.nextInt(); c = scanner.nextInt(); a--; c= c -1 + Math.abs(b-c); if (a <c ){ out.println(1); }else if (a>c){ out.println(2); }else { out.println(3); } } out.flush(); } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
4afef9fa7ba0c81cb87c3cad97e93ac9
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int T=sc.nextInt(); while(T>0) { int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); int t1=0; int t2=0; int t3=0; if(b>c) { t2=b-c; }else{ t2=c-b; } t1=a*1-1; t3=t2+(c*1-1); if(t3>t1){ System.out.println(1); }else if(t1>t3){ System.out.println(2); }else{ System.out.println(3); } T--; } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
df30d4f4019c75fb248643b975b03b06
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.Scanner; public class App { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); scanner.nextLine(); for (int i = 0; i < t; i++) { String line = scanner.nextLine(); String[] arr = line.split("\\s"); int a = Integer.parseInt(arr[0]); int b = Integer.parseInt(arr[1]); int c = Integer.parseInt(arr[2]); if (a == 1) { System.out.println(1); } else { int val = Math.abs(b - c) + (c - 1); if ((a - 1) > val) { System.out.println(2); } else if ((a - 1) < val) { System.out.println(1); } else { System.out.println(3); } } } scanner.close(); } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
c61aeab255aa5347f23cf332ab77c2ac
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.Scanner; public class Main{ public static void main(String[] args) { try(Scanner scanner = new Scanner(System.in)){ long t = scanner.nextInt(); while (t-- != 0){ long a, b, c; a = scanner.nextLong(); b = scanner.nextLong(); c = scanner.nextLong(); long first = a - 1; long second = Math.abs(c - b) + c - 1; if (first == second){ System.out.println(3); continue; } System.out.println(first < second ? 1 : 2); } } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
ad9657408a849f908fd86feb787f68e4
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Elevator { public static void main(String[] args) { FastReader f = new FastReader(); int x = f.nextInt(); for (int i = 0; i < x; i++) { int c = 0; int[] y = {f.nextInt(), f.nextInt(), f.nextInt()}; if (y[2] < y[1]) c = y[1] - 1; else c = 2 * y[2] - y[1] - 1; if (y[0] == 1){ System.out.println(1); } else { if(c > y[0]-1) System.out.println(1); else if(c < y[0]-1) System.out.println(2); else if(c == y[0]-1) System.out.println(3); } } } 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 { if(st.hasMoreTokens()){ str = st.nextToken("\n"); } else{ str = br.readLine(); } } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
3aa4a016309f454e772d46342b955650
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); int t=in.nextInt(); while(t-->0){ int a=in.nextInt(); int b=in.nextInt(); int c=in.nextInt(); int k=(c-b); if(b>=c){ if(a>b) System.out.println("2"); else if(a<b) System.out.println("1"); else System.out.println("3"); } else{ b+=k; a-=k; if(a>b) System.out.println("2"); else if(a<b) System.out.println("1"); else System.out.println("3"); } } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
a6bd07d9851572e47fe79d98d120adda
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int T = scanner.nextInt(); while (T-->0) { int a = scanner.nextInt(); int b = scanner.nextInt(); int c = scanner.nextInt(); int one = Math.abs(a-1); int two = Math.abs(b-c) + c-1; if (one < two) { System.out.println(1); } else if (one > two) { System.out.println(2); } else { System.out.println(3); } } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
ca225e8589276b357b2b66861ef02a69
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a, b, c,d; int length = sc.nextInt(); for (int i = 0; i < length; i++) { a = sc.nextInt(); b = sc.nextInt(); c = sc.nextInt(); d = Math.abs(b - c) + (c - 1); if ((a - 1) < d) { System.out.println("1"); } else if ((a - 1) > d) System.out.println("2"); else System.out.println("3"); } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
5dd21b221245b8a5e76576a453e934e2
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
/*Author: Jatin Yadav*/ import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class practice{ 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[10000]; // 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(); } } public static boolean good(long x,long w, long h, long n) { return (x/w)*(x/h)>=n; } public static void main(String args[])throws IOException { Reader s = new Reader(); int t = s.nextInt(); while (t-- > 0) { int a = s.nextInt(); int b = s.nextInt(); int c = s.nextInt(); int t1 = a - 1; int t2 = 0; if (b>c) { t2 = Math.max(b,c) - 1; }else { t2 = Math.abs(b - c) + c - 1; } if(t1>t2){ System.out.println(2); }else if(t1==t2){ System.out.println(3); }else{ System.out.println(1); } } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
bb8a96ebecd7c0381c3675776e351fd5
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Solution { static PrintWriter out = new PrintWriter(System.out); 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) { } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } String nextLine() { try { return br.readLine(); } catch (IOException ioe) { return ""; } } } public static void main(String[] args) { FastScanner fs = new FastScanner(); int T = fs.nextInt(); for (int i = 0; i < T; i++) { // INSERT CODE HERE int a = fs.nextInt(); int b = fs.nextInt(); int c = fs.nextInt(); int first = a-1; int second = Math.abs(b-c) + (c - 1); if (first == second) out.println(3); else if (first > second) out.println(2); else out.println(1); } out.close(); } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
82daeff8d04f21f32c3b993e14308c2e
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.*; public class ab { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int i=1;i<=t;i++) { int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); int z1 = a-1; int z2 = Math.abs(c-b)+c-1; if(z1<z2) System.out.println("1"); else if(z2<z1) System.out.println("2"); else System.out.println("3"); } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
e827e2952bac835bccd4fe74d9fd48ba
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
/* * * * * * * * * * * P A U L A * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ import java.io.*; import java.math.*; import java.util.*; import static java.lang.Double.*; import static java.lang.Float.*; import static java.lang.Integer.*; import static java.lang.Long.*; import static java.lang.Math.*; public class Main { static final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); static final InputStream inputStream = System.in; static final FastReader in = new FastReader(inputStream); public static void main(String[] args) throws IOException { int numOfTestCase = 1;//in.nextInt() ; while (numOfTestCase-- > 0) Task.solve(in, out); finish(); } static class Task { public static void solve(FastReader input, BufferedWriter out) throws IOException { /* ---------------------------------------------------------------------------------------------------------- كود بيتاكد ان كل الحروف الابجدية موجودة ف الاسترنج distinct() ميثود بتحذف تكرار الحروف يعني مثلا aabbcc هتكون abc int n=input.nextInt(); System.out.println(input.next().toLowerCase().chars().distinct().count()>=26?"YES":"NO"); ---------------------------------------------------------------------------------------------------------- >>>>>>>>> soooooort String <<<<<<<<<<<< String s = in.next(); //cba char[] Arr = s.toCharArray(); Arrays.sort(Arr); String x = new String(Arr); System.out.println(x); ---------------------------------------------------------------------------------------------------------- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>MMMMMMAAAAAAAAPPPPPPPP<<<<<<<<<<<<<<<<<<<<<<< int n = in.nextInt(); HashMap<String,Integer> mp = new HashMap<>(); for (int i = 1 ; i<=n ; i++) { String s = in.next(); if (!mp.containsKey(s)) { mp.put(s,0); System.out.println("OK"); } else { mp.put(s,mp.get(s)+1); System.out.println(s+mp.get(s)); } } ---------------------------------------------------------------------------------------------------------- >>>>>>>>>>>>>>>مودلس للاسترنج>>>>>>>>>>>>>>>>> String s= input.next(); BigInteger b =new BigInteger(s); if (b.mod(new BigInteger("9")).equals(new BigInteger("0"))) System.out.println("YES"); else System.out.println("NO"); ********************************************** String s= input.next(); int i=0; for (int j = 0; j <s.length() ; j++) { i=(i+(s.charAt(s.length()-1-j) -'0')%9) % 9; } System.out.println(i==0?"YES" : "NO"); ------------------------------------------------------------------------------------------------------------ <<<<<<<<<<<<<<<<<<<< PREFEX SUM<<<<<<<<<<<<<<<<<<<<<<< int size=input.nextInt(); int range=input.nextInt(); long arr[]=new long [size]; for (int i = 0; i <size ; i++) { arr[i]=input.nextInt(); if (i==0) continue; arr[i]+=arr[i-1]; } for (int i = 0; i <range ; i++) { int ind1=input.nextInt(); int ind2=input.nextInt(); System.out.print(ind1 -1 ==0?arr[--ind2] +"\n" : arr[--ind2] - arr[ind1-2]+"\n"); } ----------------------------------------------------------------------------------------------------------------- */ //---------------------------------------------------------------------------------------------------------// int t=input.nextInt(); while (t-->0){ int a ,b ,c; a=input.nextInt(); // 1 2 3 b=input.nextInt(); c=input.nextInt(); long res1=Math.abs(a-1); long res2=Math.abs(Math.abs(b-c) + Math.abs(c-1)); if (res1<res2) System.out.println(1); else if (res1>res2) System.out.println(2); else System.out.println(3); } // --------------------------------------------------------------------------------------------------------// } } static int[] readArray1d(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = in.nextInt(); return a; } static int[][] readArray2d(int row, int col) throws IOException { int[][] a = new int[row][col]; for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { a[i][j] = in.nextInt(); } } return a; } static long[][] readArray2d(long row, long col) throws IOException { long[][] a = new long[(int) row][(int) col]; for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { a[i][j] = in.nextLong(); } } return a; } private static void printArray(int[] numbers) throws IOException { for (int number : numbers) { out.write(number + " "); } } private static void printArray(long[] numbers) throws IOException { for (long number : numbers) { out.write(number + " "); } } static class FastReader { private static byte[] buf = new byte[1024]; private static int index; private static InputStream in; private static int total; public FastReader(InputStream in) { FastReader.in = in; } public static int scan() throws IOException { if (total < 0) throw new InputMismatchException(); if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) return -1; } return buf[index++]; } public int nextInt() throws IOException { int integer = 0; int n = scan(); while (isWhiteSpace(n)) n = scan(); int neg = 1; if (n == '-') { neg = -1; n = scan(); } while (!isWhiteSpace(n)) { if (n >= '0' && n <= '9') { integer *= 10; integer += n - '0'; n = scan(); } else { throw new InputMismatchException(); } } return neg * integer; } public double nextDouble() throws IOException { return parseDouble(next()); } public double nextFloat() throws IOException { return parseFloat(next()); } public long nextLong() throws IOException { long integer = 0; long n = scan(); while (isWhiteSpace(n)) n = scan(); long neg = 1; if (n == '-') { neg = -1; n = scan(); } while (!isWhiteSpace(n)) { if (n >= '0' && n <= '9') { integer *= 10; integer += n - '0'; n = scan(); } else { throw new InputMismatchException(); } } return neg * integer; } public String next() throws IOException { StringBuilder sb = new StringBuilder(); int n = scan(); while (isWhiteSpace(n)) n = scan(); while (!isWhiteSpace(n)) { sb.append((char) n); n = scan(); } return sb.toString(); } public String nextLine() throws IOException { StringBuilder sb = new StringBuilder(); int n = scan(); while (isWhiteSpace(n)) n = scan(); while (!newLine(n)) { sb.append((char) n); n = scan(); } return sb.toString(); } private static boolean isWhiteSpace(long n) { return n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1; } private boolean newLine(long n) { return n == '\n' || n == -1; } } static void finish () throws IOException { out.flush(); out.close(); } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
4817b1d8f3429295c7f8085029a1d247
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.Scanner; public class TwoElevators { public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); int x=0,y=0,f=0; while(t-->0){ int a = s.nextInt(); int b= s.nextInt(); int c = s.nextInt(); x = a; y = (b-c); if(y<0){ y=-y; } f=y+c; if(x>f){ System.out.println("2"); } if(f>x){ System.out.println("1"); } if(f==x){ System.out.println("3"); } } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
1fb3f4ba9474b1730a030d47eb703379
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.io.PrintWriter; public class MyClass { public static void main(String[] args) { InputReader scanner = new InputReader(System.in); PrintWriter output = new PrintWriter(System.out); int T = scanner.nextInt(); while (T-- > 0) { long a = scanner.nextLong(); long b = scanner.nextLong(); long c = scanner.nextLong(); long f = a - 1; long s = c > b ? (c - b) + (c - 1) : b - 1; output.println(f < s ? 1 : f > s ? 2 : 3); } output.close(); } static class InputReader { BufferedReader reader; StringTokenizer tokenizer; InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.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 = reader.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
d8a0bfbe56137f90278d37f817d4bcab
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.Scanner; public class TwoElevators { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); for(int i=0; i<n; i++) { int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); int x=Math.abs(b-c)+Math.abs(c-1); int y=Math.abs(a-1); if(x>y) { System.out.println(1); } else if(x<y) { System.out.println(2); } else { System.out.println(3); } } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
14b214743511bf5bae0602d445e9b19c
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.*; public class App { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); while(t-- > 0) { int a = in.nextInt(); int b = in.nextInt(); int c = in.nextInt(); int first = a - 1; int second = 0; if(b > c) second = b - 1; else if(c > b) second = 2 * c - b - 1; if(first < second) System.out.println("1"); else if(first == second) System.out.println("3"); else System.out.println("2"); } in.close(); } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
2f3c7321ef6277638c1c0ccf43ab9a6f
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.Scanner; public class Elevator { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t>0) { int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); int first =0; int second =0; if(a==1) { System.out.println(1); } else { first = a-1; second =0; if(b>c) { second = b-1; } else { second = c-b; second+= c-1; } if(first<second) { System.out.println(1); } else if(first == second) { System.out.println(3); } else { System.out.println(2); } } t--; } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
9f3641a817a1b752650a4c14dfe1216c
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.*; public class HelloWorld { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); while(t-->0){ int a = scan.nextInt(); int b = scan.nextInt(); int c = scan.nextInt(); int x = Math.abs(b-c) + c-1; int y = a-1; if(x>y){ System.out.println(1); }else if(x<y){ System.out.println(2); }else{ System.out.println(3); } } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
50883c0b523a51d136d157fbd94935db
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.io.*; import java.util.*; import java.lang.Math; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int size = sc.nextInt(); for(int i=0; i<size; i++) { long a = sc.nextLong(); long b = sc.nextLong(); long c = sc.nextLong(); if((a-1) < ((Math.abs(c-b)) + (c-1))) { System.out.println(1); } else if((a-1) > ((Math.abs(c-b)) + (c-1))) { System.out.println(2); } else if((a-1) == ((Math.abs(c-b)) + (c-1))) { System.out.println(3); } } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
9147273a7133e9ddb6c17add380d7888
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.*; import java.io.*; public class Solution { public static void main(String args[]){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int i=0;i<t;i++){ int a =sc.nextInt(); int b =sc.nextInt(); int c =sc.nextInt(); int x = Math.abs(a-1); int y = Math.abs(b-c); int z = Math.abs(c-1); y=y+z; if(x>y){ System.out.println("2"); } else if(y>x){ System.out.println("1"); } else{ System.out.println("3"); } } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
d871e9ecc654ad068c7b3aff3de141ea
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); while (t--!=0) { int a = in.nextInt() , b = in.nextInt() , c = in.nextInt(); System.out.println((a) > (Math.abs(b-c) + (c)) ? 2 : (a) < (Math.abs(b-c) + c) ? 1 : 3); } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
2abefc1a8fe7e66fce968fa135e8be78
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.Scanner; public class A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int cases = sc.nextInt(); while (cases != 0) { cases--; int a = Integer.parseInt(sc.next()); int b = Integer.parseInt(sc.next()); int c = Integer.parseInt(sc.next()); int lift1 = Math.abs(a - 1); int lift2 = Math.abs(b - c); lift2 += Math.abs(c - 1); if (lift1 < lift2) { System.out.println(1); } else if (lift1 > lift2) { System.out.println(2); } else { System.out.println(3); } } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
951137c6c551ec6f53aec85f703c0ee0
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.*; import java.lang.*; public class Main { public static void main (String[] args) throws java.lang.Exception { Scanner sc=new Scanner(System.in); int t= sc.nextInt(); while(t-->0){ int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); // int k = sc.nextInt(); // int[] num = new int[n]; solve(a, b, c); } } static void solve(int a, int b, int c){ int t2 = Math.abs(c-b); int t3 = t2+Math.abs(c-1); int t1 = Math.abs(a-1); if(t1<t3){ System.out.println(1); } else if(t1>t3){ System.out.println(2); } else{ System.out.println(3); } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
ae621add935068749047f330bf0a2c6a
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.io.*; import java.util.*; public class ProblemA { // Fast Reader Class public static class FastReader { // Reader object BufferedReader reader; // Constructor public FastReader(){ // Initialize the reader reader = new BufferedReader(new InputStreamReader(System.in)); } // String tokenizer StringTokenizer tokenizer; // Function to read integer public int ri() throws IOException{ return Integer.parseInt(reader.readLine()); } // Function to read a single long public long rl() throws IOException { return Long.parseLong(reader.readLine()); } // Function to read a array of numsInts integers in 1 line public int[] ria(int numInts) throws IOException { int[] nums = new int[numInts]; tokenizer = new StringTokenizer(reader.readLine()); // Input Numbers for (int i = 0; i < numInts; i++) { nums[i] = Integer.parseInt( tokenizer.nextToken()); } return nums; } // Function to read string public String rs() throws IOException{ return reader.readLine(); } } // Fast Writer Class public static class FastWriter { // Writer object BufferedWriter writer; // Constructor public FastWriter(){ // Initialize the writer writer = new BufferedWriter(new OutputStreamWriter(System.out)); } // Function to write single integer public void wi(int i)throws IOException{ writer.write(Integer.toString(i)); writer.newLine(); writer.flush(); } // Function to write a single long public void wl(long i) throws IOException{ writer.write(Long.toString(i)); writer.newLine(); writer.flush(); } // Function to write a Integer of array with spaces in 1 line public void wias(int[] nums) throws IOException{ for (int i = 0; i < nums.length; i++) { writer.write(nums[i] + " "); } writer.newLine(); writer.flush(); } // Function to write a Integer of array without spaces in 1 line public void wiaws(int[] nums) throws IOException { for (int i = 0; i < nums.length; i++) { writer.write(Integer.toString(nums[i])); } writer.newLine(); writer.flush(); } // Function to write a String public void ws(String s) throws IOException{ writer.write(s); writer.newLine(); writer.flush(); } } // Initialize a pair // Pair<Integer, Integer> x = new Pair<Integer, Integer>(1, 2); static class Pair implements Comparable<Pair> { int x; int y; Pair() { } Pair(int x, int y) { this.x = x; this.y = y; } public int compareTo(Pair o) { if(this.y == o.y) { return o.x - this.x; } else { return o.y - this.y; } } } public static void main(String[] args) throws IOException { FastReader fr = new FastReader(); FastWriter fw = new FastWriter(); int t = fr.ri(); while(t-- > 0) { String[] parts = fr.rs().split(" "); int a = Integer.parseInt(parts[0]); int b = Integer.parseInt(parts[1]); int c = Integer.parseInt(parts[2]); long val = Math.abs(b - c) + Math.abs(c - 1); a--; if(val > a) { System.out.println("1"); } else if(val < a) { System.out.println("2"); } else { System.out.println("3"); } } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
9b12a49b4c7fe05da276a410a25ffdcf
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.*; public class twoElevator { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-- > 0) { int a,b,c; a=sc.nextInt(); b=sc.nextInt(); c=sc.nextInt(); int c1,c2; c1=Math.abs(a-1); c2=Math.abs(b-c)+Math.abs(c-1); if(c1<c2) System.out.println(1); else if(c2<c1) System.out.println(2); else System.out.println(3); } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
92807743459a825003c0a74c51f3026f
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.io.BufferedReader; import java.io.PrintWriter; import java.lang.*; import java.io.IOException; import java.io.InputStreamReader; import java.net.SocketOption; import java.security.spec.RSAOtherPrimeInfo; import java.util.*; public class SEC { static long mod = (long) (1e9 + 7); static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static void sort(long[] arr) { ArrayList<Long> a = new ArrayList<>(); for (long i : arr) { a.add(i); } Collections.sort(a); for (int i = 0; i < a.size(); i++) { arr[i] = a.get(i); } } static long highestPowerof2(long x) { x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; return x ^ (x >> 1); } public static long fact(long number) { if (number == 0 || number == 1) { return 1; } else { return number * fact(number - 1); } } public static ArrayList<Long> primeFactors(long n) { ArrayList<Long> arr = new ArrayList<>(); long count = 0; while (n % 2 == 0) { arr.add(2l); n /= 2; } for (long i = 3; i <= Math.sqrt(n); i += 2) { while (n % i == 0) { arr.add(i); n /= i; } } if (n > 2) arr.add(n); return arr; } static public long[] prime(long number) { long n = number; long count = 0; long even = 0; for (long i = 2; i <= n / i; i++) { while (n % i == 0) { if (i % 2 == 1) { count++; } else { even++; } n /= i; } } if (n > 1) { if (n % 2 == 1) { count++; } else { even++; } } return new long[]{even, count}; } static void swap(int[] arr, int i, int j) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } static int search(ArrayList<Integer> arr, int tar) { int low = 0, hi = arr.size() - 1; int ans = -1; while (low <= hi) { int mid = (low + hi) / 2; if (arr.get(mid) > tar) { ans = arr.get(mid); hi = mid - 1; } else { low = mid + 1; } } return ans; } static long gcd(long a, long b) { // if b=0, a is the GCD if (b == 0) return a; else return gcd(b, a % b); } static long power(long x, long y, long p) { long res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if ((y & 1) != 0) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static int get(long[] arr, long tar) { int ans = -1; int l = 0; int h = arr.length - 1; while (l <= h) { int mid = l + (h - l) / 2; if (arr[mid] <= tar) { ans = mid; l = mid + 1; } else { h = mid - 1; } } return ans; } static void print_Array(int[] arr) { for (int i : arr) { System.out.print(i + " "); } System.out.println(); } static boolean con(char ch) { if (ch != 'a' && ch != 'e' && ch != 'i' && ch != 'o' && ch != 'u') return true; return false; } static void swap(char[] ch, int i, int j) { char c = ch[i]; ch[i] = ch[j]; ch[j] = c; } static void swap(long[] ch, int i, int j) { long c = ch[i]; ch[i] = ch[j]; ch[j] = c; } /* 5 12 1 1 1 1 1 2 2 2 1 1 2 2 2 2 2 4 2 2 2 2 3 3 2 2 2 4 3 3 3 3 2 2 8 7 7 7 7 7 7 7 (()) (((()))) (()()) */ public static void main(String[] args) throws Exception { FastReader sc = new FastReader(); PrintWriter out = new PrintWriter(System.out); int t = sc.nextInt(); while(t-- > 0) { long a = sc.nextLong(); long b = sc.nextLong(); long c = sc.nextLong(); long t1 = Math.abs(a-1); long t2 = Math.abs(Math.abs(c-b) + Math.abs(c - 1)); if(t1 == t2){ System.out.println(3); }else if(t1 < t2){ System.out.println(1); }else{ System.out.println(2); } } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
7ee8b8238eaa095ce57fe92dcbd60f52
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.*; import java.io.*; public class Balabizo { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int tt = sc.nextInt(); while(tt-->0){ long ans = sc.nextLong() , b = sc.nextLong() , c = sc.nextLong(); long x = c + Math.abs(b - c); if(ans < x) pw.println(1); else if(ans > x) pw.println(2); else pw.println(3); } pw.flush(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(String file) throws IOException { br = new BufferedReader(new FileReader(file)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public String readAllLines(BufferedReader reader) throws IOException { StringBuilder content = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { content.append(line); content.append(System.lineSeparator()); } return content.toString(); } 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 long[] nextlongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public Long[] nextLongArray(int n) throws IOException { Long[] a = new Long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
607459b3fcd6ebfdd980f3981551b555
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.io.*; import java.util.*; public class Main { static boolean isfile = false; static final String FileName = "input"; static PrintWriter out = new PrintWriter(System.out); static FastReader fr = new FastReader(); static int OO = (int) 1e9; public static void main(String[] args) throws FileNotFoundException { if (isfile) { fr = new FastReader(FileName + ".txt"); out = new PrintWriter(new File("output.txt")); } int tt = 1; tt = fr.nextInt(); while (tt-- > 0) { solve(); } out.close(); } public static void solve() { long a=fr.nextLong(),b=fr.nextLong(),c=fr.nextLong(); a--; c=Math.abs(b-c)+c-1; if (a<c) { out.println(1); }else if (a>c) { out.println(2); }else { out.println(3); } } static class FastReader { BufferedReader br; StringTokenizer st = new StringTokenizer(""); public FastReader(String s) throws FileNotFoundException { br = new BufferedReader(new FileReader(new File(s))); } public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { } return st.nextToken(); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } Long[] readArrayL(int n) { Long[] a = new Long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } int nextInt() { return Integer.parseInt(next()); } double nextDouble() { return Double.parseDouble(next()); } long nextLong() { return Long.parseLong(next()); } } public static int lcm(int a, int b) { return a * b / gcd(a, b); } public static int gcd(int a, int b) { while (b != 0) { int m = a % b; a = b; b = m; } return a; } public static long factorial(int n) { if (n == 0) return 1; long res = 1; for (int i = 2; i <= n; i++) res = res * i; return res; } public static long nCr(int n, int r) { return factorial(n) / (factorial(r) * factorial(n - r)); } public static ArrayList<Integer> factors(long n) { ArrayList<Integer> list = new ArrayList<>(); for (int i = 2; i < n / i; i++) { while (n % i == 0) { if (!list.contains(i)) { list.add(i); n /= i; } } } if (n > 2) { if (!list.contains((int) n)) { list.add((int) n); } } return list; } public static int numOfPrimes(int n) { if (n < 2) { return 0; } boolean[] bool = new boolean[n + 1]; outer: for (int i = 2; i < bool.length / i; i++) { if (bool[i]) { continue outer; } for (int j = 2 * i; j < bool.length; j += i) { bool[j] = true; } } int counter = 0; for (int i = 0; i < bool.length; i++) { if (!bool[i]) { counter++; } } return counter; } public static int numOfDivisors(int x) { int to = 0; for (int i = 1; i <= Math.sqrt(x); i++) { if (x % i == 0) { if (x / i == i) { to++; } else { to += 2; } } } return to; } public static long fastPow(long a, long n, long mod) { long ret = 1; int x = 63 - Long.numberOfLeadingZeros(n); for (; x >= 0; x--) { ret = ret * ret % mod; if (n << 63 - x < 0) ret = ret * a % mod; } return ret; } public static void sort2DGivenArray(int[][] arr, int colNum) { Arrays.sort(arr, (val1, val2) -> { if (val1[colNum] == val2[colNum]) { return 0; } else if (((Integer) (val1[colNum])).compareTo(((Integer) (val2[colNum]))) < 0) { return 1; } else { return -1; } }); } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
00ded5e7e4db863774a4ba519372b943
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.Scanner; public class Test1 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while (t-->0){ int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); int time=c<=b?b:2*c-b; if(a<time){ System.out.println(1); }else if(a>time){ System.out.println(2); } else { System.out.println(3); } } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
adcf8d895e64b03df89b91ee5c55ab48
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in=new Scanner (System.in); long a=in.nextLong(); for (int i = 0; i < a; i++) { long x=in.nextLong(),y=in.nextLong(), z=in.nextLong(); long test=Math.abs(z-y)+z; if(x<test)System.out.println("1"); else if(x==test)System.out.println("3"); else if(x>test)System.out.println("2"); } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
3de0011454e952f303f68561b2c360d8
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
/* ...|/G\/E\/O\/R\/G\/E\|... */ //Advanced Java //BufferedWriter //BufferedReader import java.io.*; import java.math.*; import java.util.*; import static java.lang.Double.*; import static java.lang.Float.*; import static java.lang.Integer.*; import java.util.ArrayList; import static java.lang.Long.*; import static java.lang.Math.*; public class Main { static final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); static final InputStream inputStream = System.in; static final FastReader in = new FastReader(inputStream); public static void main(String[] args) throws IOException { int numOfTestCase = 1;//in.nextInt() ; while (numOfTestCase-- > 0) Task.solve(in, out); finish(); } static class Task { public static void solve(FastReader in, BufferedWriter out) throws IOException { int t=in.nextInt(); while (t-->0){ int a ,b ,c; a=in.nextInt(); // 1 2 3 b=in.nextInt(); c=in.nextInt(); long res1=Math.abs(a-1); long res2=Math.abs(Math.abs(b-c) + Math.abs(c-1)); if (res1<res2) System.out.println(1); else if (res1>res2) System.out.println(2); else System.out.println(3); } } } static int[] readArray1d(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = in.nextInt(); return a; } static int[][] readArray2d(int row, int col) throws IOException { int[][] a = new int[row][col]; for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { a[i][j] = in.nextInt(); } } return a; } static long[][] readArray2d(long row, long col) throws IOException { long[][] a = new long[(int) row][(int) col]; for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { a[i][j] = in.nextLong(); } } return a; } private static void printArray(int[] numbers) throws IOException { for (int number : numbers) { out.write(number + " "); } } private static void printArray(long[] numbers) throws IOException { for (long number : numbers) { out.write(number + " "); } } static class FastReader { private static byte[] buf = new byte[1024]; private static int index; private static InputStream in; private static int total; public FastReader(InputStream in) { FastReader.in = in; } public static int scan() throws IOException { if (total < 0) throw new InputMismatchException(); if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) return -1; } return buf[index++]; } public int nextInt() throws IOException { int integer = 0; int n = scan(); while (isWhiteSpace(n)) n = scan(); int neg = 1; if (n == '-') { neg = -1; n = scan(); } while (!isWhiteSpace(n)) { if (n >= '0' && n <= '9') { integer *= 10; integer += n - '0'; n = scan(); } else { throw new InputMismatchException(); } } return neg * integer; } public double nextDouble() throws IOException { return parseDouble(next()); } public double nextFloat() throws IOException { return parseFloat(next()); } public long nextLong() throws IOException { long integer = 0; long n = scan(); while (isWhiteSpace(n)) n = scan(); long neg = 1; if (n == '-') { neg = -1; n = scan(); } while (!isWhiteSpace(n)) { if (n >= '0' && n <= '9') { integer *= 10; integer += n - '0'; n = scan(); } else { throw new InputMismatchException(); } } return neg * integer; } public String next() throws IOException { StringBuilder sb = new StringBuilder(); int n = scan(); while (isWhiteSpace(n)) n = scan(); while (!isWhiteSpace(n)) { sb.append((char) n); n = scan(); } return sb.toString(); } public String nextLine() throws IOException { StringBuilder sb = new StringBuilder(); int n = scan(); while (isWhiteSpace(n)) n = scan(); while (!newLine(n)) { sb.append((char) n); n = scan(); } return sb.toString(); } private static boolean isWhiteSpace(long n) { return n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1; } private boolean newLine(long n) { return n == '\n' || n == -1; } } static void finish () throws IOException { out.flush(); out.close(); } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
d2653d8bdaea667cf47b0b6966cb419e
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.math.BigInteger; import java.util.Scanner; public class meta { public static void main(String[] args) { Scanner real = new Scanner(System.in); int n= real.nextInt(); while (n--!=0){ int p= real.nextInt(); int q= real.nextInt(); int s= real.nextInt(); int d1=Math.abs(p-1); int d2=(Math.abs(q-s)+Math.abs(s-1)); if(d1==d2){ System.out.println(3); } else if (d1<d2) { System.out.println(1); }else { System.out.println(2); } } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
3d7beb81b7841bf6764ded3e4d1ccff7
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.Scanner; public class TwoElevator { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); while (t-- > 0) { int a = in.nextInt(); int b = in.nextInt(); int c = in.nextInt(); int ans1 = Math.abs(a - 1); int ans2 = Math.abs(b - c) + c - 1; if (ans1 < ans2) System.out.println(1); else if (ans1 > ans2) System.out.println(2); else if (ans1 == ans2) System.out.println(3); } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
11f4dd9610794744eaeac9138f0483aa
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
//https://codeforces.com/contest/1729/problem/A import java.util.Scanner; public class TwoElevators { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); while (t-- > 0) { int a = scan.nextInt(); int b = scan.nextInt(); int c = scan.nextInt(); int x = a - 1; int y = Math.abs(c - b) + (c - 1); if (x < y) System.out.println("1"); else if (y < x) System.out.println("2"); else System.out.println("3"); } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
16f5e394d7742b25c4e9ba2f4e9815a1
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.io.*; import java.util.*; /* */ public class A{ static FastReader sc=null; public static void main(String[] args) { sc=new FastReader(); int t=sc.nextInt(); for(int tt=0;tt<t;tt++) { int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(); int first=a-1; int second=Math.abs(b-c)+Math.abs(c-1); if(first==second)System.out.println(3); else System.out.println(first<second?1:2); } } static int[] ruffleSort(int a[]) { ArrayList<Integer> al=new ArrayList<>(); for(int i:a)al.add(i); Collections.sort(al); for(int i=0;i<a.length;i++)a[i]=al.get(i); return a; } static void print(int a[]) { for(int e:a) { System.out.print(e+" "); } System.out.println(); } static class FastReader{ StringTokenizer st=new StringTokenizer(""); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String next() { while(!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch(IOException e){ e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } int[] readArray(int n) { int a[]=new int[n]; for(int i=0;i<n;i++)a[i]=sc.nextInt(); return a; } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
96750375d960907292e124e09481633a
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.Scanner; public class TwoElevators { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int sum = sc.nextInt(); int[] times = new int[sum]; for (int i = 0; i < sum; i++) { int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); if (c>b){ if (b==1){ System.out.println(a==2*c-1?3:(a>2*c-1?2:1)); }else{ // if (a>2*c-b){ // System.out.println(2); // }else if (a<2*c-b){ // System.out.println(1); // }else{ // System.out.println(3); // } System.out.println(a==2*c-b?3:(a>2*c-b?2:1)); } }else{ // if (a>b){ // System.out.println(2); // }else if (a<b){ // System.out.println(1); // }else{ // System.out.println(3); // } System.out.println(a==b?3:(a>b?2:1)); } } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
659663e25fe1b43ad96d2f984aac8235
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t>0) { int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); a--; b = Math.abs(b-c) + (c-1); if (b==a) System.out.println("3"); else if (b>a) System.out.println("1"); else System.out.println("2"); t--; } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
442208d64f9df532b5bed667f4acf1df
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
//package two_elevators; import java.util.Scanner; public class Main { Scanner sc = new Scanner(System.in); public Main() { int t = sc.nextInt(); sc.nextLine(); for (int i = 0; i < t; i++) { String in = sc.nextLine(); int a = Integer.parseInt(in.split(" ")[0]); int b = Integer.parseInt(in.split(" ")[1]); int c = Integer.parseInt(in.split(" ")[2]); int l2 = Math.abs(c - b) + c - 1; if (a - 1 < l2) System.out.println(1); else if (a - 1 > l2) System.out.println(2); else System.out.println(3); } } public static void main(String[] args) { new Main(); } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
4698db7f623bbf6d8a68dd276e9192f0
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.io.*; import java.util.*; public class Skeleton { public Skeleton() { // TODO Auto-generated constructor stub } static class FastReader { public BufferedReader br; public StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); st = null; } public String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { if(st.hasMoreTokens()){ str = st.nextToken("\n"); } else{ str = br.readLine(); } } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader fr = new FastReader(); int t = fr.nextInt(); while(t-- > 0) { int a = fr.nextInt(); int b = fr.nextInt(); int c = fr.nextInt(); if(a-1 < Math.abs(c-b) + Math.abs(c-1)) System.out.println(1); else if(a-1 > Math.abs(c-b) + Math.abs(c-1)) System.out.println(2); else System.out.println(3); } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
040b23a5a1efb4d8c0feb3e15214af84
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.StringReader; import java.util.StringTokenizer; public class Solution { static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); static StringBuilder output = new StringBuilder(); public static void main(String[] args) throws NumberFormatException, IOException { // reader = new BufferedReader(new StringReader(str)); int T = Integer.parseInt(reader.readLine()); for (int t = 1; t <= T; t++) { StringTokenizer tokens = new StringTokenizer(reader.readLine()); int A = Integer.parseInt(tokens.nextToken()); int B = Integer.parseInt(tokens.nextToken()); int C = Integer.parseInt(tokens.nextToken()); int aTime = Math.abs(A - 1); int bTime = Math.abs(B - C) + Math.abs(C - 1); if (aTime < bTime) { output.append(1).append("\n"); }else if (bTime < aTime) { output.append(2).append("\n"); }else { output.append(3).append("\n"); } } System.out.print(output); } static String str = "3\r\n" + "1 2 3\r\n" + "3 1 2\r\n" + "3 2 1\r\n" + ""; }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
5aaba6d5bbf401346afa145025d39cd7
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.Scanner; /** * Created by Franz Andel <[email protected]> * on 13 September 2022. */ public class TwoElevators { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int testCases = scanner.nextInt(); for (int i = 0; i < testCases; i++) { int a = scanner.nextInt(); int b = scanner.nextInt(); int c = scanner.nextInt(); System.out.println(twoElevators(a, b, c)); } } private static int twoElevators(int a, int b, int c) { if (a == 1) { return 1; } int tempA = Math.abs(a - 1); int tempB = 0; if (c == 1) { tempB = Math.abs(c - b); } else { tempB = Math.abs(c - b) + Math.abs(c - 1); } if (tempA == tempB) { return 3; } else if (tempA > tempB) { return 2; } else { return 1; } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
23c91065298df7ebb639b6b60725392a
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
// package com.company; import java.io.*; import java.math.BigInteger; import java.util.*; import java.util.stream.IntStream; import java.math.*; public class Scanner { static boolean[] x; StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } 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 long[] nextlongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public Long[] nextLongArray(int n) throws IOException { Long[] a = new Long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } /*public static void luckyNumbers(int a, int b, ArrayList x) { if(a>Math.pow(10,9) || b>Math.pow(10,9)) return; x.add(a); x.add(b); luckyNumbers((a*10)+4,(b*10)+4,x); luckyNumbers((a*10)+7,(b*10)+7,x); } */ public static void prefixSum(long[] cost, long[] prefixSum) { // prefix Sum for the cost Array prefixSum[0] = cost[0]; for(int i=1;i<cost.length;i++) prefixSum[i] = prefixSum[i-1] + cost[i]; } public static void prefixSumSorted(Integer[] costSorted, long[] prefixSum) { // prefix Sum for the sorted cost Array prefixSum[0] = costSorted[0]; for(int i=1;i<costSorted.length;i++) prefixSum[i] = prefixSum[i-1] + costSorted[i]; } /* public static boolean isOperator(char c) { return c == '^' || c == '/' || c == '*' || c == '+' || c == '-'; } public static int getPrecedence(char c) { case '+', '-' -> 1; case '*', '/' -> 3; default -> 5; }; } */ public static boolean isPrime (int a) { for(int i=2;i<a;i++) { if(a%i == 0) return false; } return true; } /*public static int getP(int y) { int p = 0; for(int i=2;i<=y;i++) { if(y%i == 0 && x.contains(y)) p++; } return p; } */ public static void luckyNumbers(long a, ArrayList x) { if(a>Math.pow(10,15)) return; if(a!=0) x.add(a); luckyNumbers(a*10+4,x); luckyNumbers(a*10+7,x); } // CODE STARTS HERE 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 a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); int time1 = a-1; int time2 = Math.abs(b-c) + (c-1); if(time1<time2) System.out.println(1); else if(time1>time2) System.out.println(2); else System.out.println(3); } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
9f6df44ed462bd4969a6fea6d3938948
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.Scanner; public class Twoelevator { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); int Vald = 1; for(int i = 0; i < t; i++ ){ int a = scanner.nextInt(); int b = scanner.nextInt(); int c = scanner.nextInt(); int firstele = a - Vald; int x = Math.abs(c - b); int secondele = c - 1 + x; if(firstele < secondele){ System.out.println(1); }else if(firstele > secondele){ System.out.println(2); }else{ System.out.println(3); } } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
794217e12da617f47615c91180537d21
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.Scanner; public class planets { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0){ int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); int cheka = a-1; int chekb = Math.abs(b-c)+c-1; if(cheka==chekb){ System.out.println(3); } if (cheka<chekb){ System.out.println(1); } if (cheka>chekb){ System.out.println(2); } } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
6218608147afe99cb6ad415e987a1a29
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.io.*; import java.util.*; public class CodeForces { public static void main(String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); while(t-- > 0) { StringTokenizer tk = new StringTokenizer(br.readLine()); int a = Integer.parseInt(tk.nextToken()); int b = Integer.parseInt(tk.nextToken()); int c = Integer.parseInt(tk.nextToken()); if(Math.abs(a-1) == (Math.abs(b-c)+Math.abs(c-1))) System.out.println(3); else if(Math.abs(a-1) < (Math.abs(b-c)+Math.abs(c-1))) System.out.println(1); else System.out.println(2); } br.close(); } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
3c860642cb6b9a33ece64e3949a5a463
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.*; public class Main{ static void solve(int a,int c,int d) { int temp=Math.abs(c-d)+d; if(a<temp)System.out.println("1"); else if(a>temp)System.out.println("2"); else System.out.println("3"); } public static void main(String []args) { Scanner scn=new Scanner(System.in); int t=scn.nextInt(); while(t-->0) { int a=scn.nextInt(); int c=scn.nextInt(); int d=scn.nextInt(); solve(a,c,d); } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
7ea0d8ba1d5cec5477eb6add5db046c7
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
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 a=scn.nextInt(); int c=scn.nextInt(); int d=scn.nextInt(); int temp=Math.abs(c-d)+d; if(a<temp)System.out.println("1"); else if(a>temp)System.out.println("2"); else System.out.println("3"); } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
8ccd87a3800ed467f50b548f6f788d69
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.io.*; import java.util.*; import java.lang.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t; t=sc.nextInt(); while(t-- > 0) { int a,b,c; a=sc.nextInt(); b=sc.nextInt(); c=sc.nextInt(); int i = a-1; int j = ((b>c)?b-c:c-b) + c-1; if(i == j) { System.out.println("3"); } else if(i < j) { System.out.println("1"); } else { System.out.println("2"); } } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
dc68a4482a70849f5f6d54900d552dfa
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.Scanner; public class solution{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); int x=Math.abs(b-c)+Math.abs(c-1); int y=Math.abs(a-1); if(x==y) System.out.println("3"); else if(x<y) System.out.println("2"); else System.out.println("1"); } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
ac1374ce1e65370de5d096c0a319dfd3
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.io.*; import java.util.*; public class two_elevators{ public static void main(String[] args) throws IOException{ Scanner sc= new Scanner(System.in); int t,a,b,c; t=sc.nextInt(); while(t>=1){ a=sc.nextInt(); b=sc.nextInt(); c=sc.nextInt(); if(Math.abs(a)<Math.abs(b-c)+Math.abs(c)){ System.out.println(1); } else if(Math.abs(a)==Math.abs(b-c)+Math.abs(c)){ System.out.println(3); } else System.out.println(2); t--;; } sc.close(); } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
f9d211d5e9d59428a07a64214f5a1246
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class hello { public static void main (String[] args) throws java.lang.Exception { Scanner s = new Scanner(System.in); int t=s.nextInt(); for(int z=0;z<t;z++) { int a=s.nextInt(); int b=s.nextInt(); int c=s.nextInt(); int x=Math.abs(a-1); int y=Math.abs(b-c)+Math.abs(c-1); if(x<y) { System.out.println("1"); } else if(x>y) { System.out.println("2"); } else{ System.out.println("3"); } } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
c4bf3387b05af6f982833e793a71a2fe
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.Scanner; public class Codeforce14 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int x=0;x<t;x++){ long a=sc.nextLong(); long b=sc.nextLong(); long c=sc.nextLong(); long first=a; long second=Math.abs(b-c)+c; if(first<second) System.out.println(1); else if(second<first) System.out.println(2); else System.out.println(3); } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
05e2ae3f9b3ccfc0232dfe6ecb849fe4
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.Scanner; public class TwoElevators { public static void main(String[] args) { int t,a,b,c; Scanner sc = new Scanner(System.in); t = sc.nextInt(); while(t-->0){ a=sc.nextInt(); b=sc.nextInt(); c=sc.nextInt(); int x = Math.abs(a-1); int y = Math.abs(b-c)+Math.abs(c-1); if(x<y) System.out.println(1); else if(y<x) System.out.println(2); else System.out.println(3); } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
86167e047a0e9caa6e1d6329f2067a05
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.Scanner; public class test { public static void main(String[] args) { Scanner input = new Scanner(System.in); int t = input.nextInt(); while (t-- > 0) { int a, b, c; a = input.nextInt(); b = input.nextInt(); c = input.nextInt(); int d = (b > c) ? b : 2 * c - b; if (a < d){ System.out.println(1); } else if (a > d){ System.out.println(2); } else { System.out.println(3); } } input.close(); } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
fc712bb110deca2190cf73e77b8030d1
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.Scanner; public class TwoElevators { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t= sc.nextInt(); while(t-->0){ int a= sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); int t1 = a-1; int t2 = Math.abs(b-c)+c-1; if(t1==t2){ System.out.println("3"); } else{ System.out.println(t1>t2?"2":"1"); } } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
347a404cb6e4d01e79646b4510d2a5c1
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int test = sc.nextInt(); while(test-- > 0) { int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); int x = Math.abs(a - 1); int y = Math.abs(b - c) + Math.abs(c - 1); if(x == y) { System.out.println(3); } else if(x > y) { System.out.println(2); } else { System.out.println(1); } } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
6fb4d47930b15945776504c700fef700
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
/****************************************************************************** Online Java Compiler. Code, Compile, Run and Debug java program online. Write your code in this editor and press "Run" button to execute it. *******************************************************************************/ import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { int a, b, c, l1, l2; Scanner input= new Scanner(System.in); int t=input.nextInt(); for(int i=0; i<t; i++){ a=input.nextInt(); b=input.nextInt(); c=input.nextInt(); l1 = Math.abs(a-1); if(b<c){ l2=Math.abs(c-b)+Math.abs(c-1); } else{ l2 = Math.abs(b-1); } if(l1>l2){ System.out.println(2); } else if(l1<l2){ System.out.println(1); } else{ System.out.println(3); } }} }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
b969430c5e439f3ab061b18617c32669
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Random; import java.util.StringTokenizer; public class A { public static void main(String[] args) { FastScanner fs=new FastScanner(); PrintWriter out=new PrintWriter(System.out); int T=fs.nextInt(); for (int tt=0; tt<T; tt++) { int a=fs.nextInt(), b=fs.nextInt(), c=fs.nextInt(); // out.println(Math.min(a, Math.max(b-c, 0)+b)); int c1=a, c2; if (b<=c) { c2=(c-b+c); } else { c2=b; } if (c1==c2) { out.println(3); } else if (c1<c2) { out.println(1); } else out.println(2); } out.close(); } static final Random random=new Random(); static final int mod=1_000_000_007; static void ruffleSort(int[] a) { int n=a.length;//shuffle, then sort 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 long add(long a, long b) { return (a+b)%mod; } static long sub(long a, long b) { return ((a-b)%mod+mod)%mod; } static long mul(long a, long b) { return (a*b)%mod; } static long exp(long base, long exp) { if (exp==0) return 1; long half=exp(base, exp/2); if (exp%2==0) return mul(half, half); return mul(half, mul(half, base)); } static long[] factorials=new long[2_000_001]; static long[] invFactorials=new long[2_000_001]; static void precompFacts() { factorials[0]=invFactorials[0]=1; for (int i=1; i<factorials.length; i++) factorials[i]=mul(factorials[i-1], i); invFactorials[factorials.length-1]=exp(factorials[factorials.length-1], mod-2); for (int i=invFactorials.length-2; i>=0; i--) invFactorials[i]=mul(invFactorials[i+1], i+1); } static long nCk(int n, int k) { return mul(factorials[n], mul(invFactorials[k], invFactorials[n-k])); } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
3bfabea0eddd5362d28e8a7546d97dbc
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.*; import java.io.*; public class Solution { public static void solve(InputReader in, PrintWriter out) { int t = in.nextInt(); while (t-- > 0) { int a = in.nextInt(); int b = in.nextInt(); int c = in.nextInt(); a -= 1; c = (c - 1) + Math.abs(b - c); if (a == c) { out.println(3); } else if (a < c) { out.println(1); } else { out.println(2); } } } public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); solve(in, out); 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 nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } String nextLine() throws Exception{ String str = ""; try{ str = reader.readLine(); }catch (IOException e){ throw new Exception(e.toString()); } return str; } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
0999d82f33f7b92bcee7fe12d7cd610c
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.*; public class code { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int t= sc.nextInt(); while(t-->0){ solve(); } } static void solve() { int x= sc.nextInt(); int y=sc.nextInt(); int z= sc.nextInt(); int a=Math.abs(x-1); int b=Math.abs(y-z)+Math.abs(z-1); if(a<b) System.out.println(1); else if(a==b) System.out.println(3); else System.out.println(2); } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
e5cb6ea202103438b4101cd713cf63c3
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.io.*; import java.util.*; public class Main { static PrintWriter out = new PrintWriter(System.out); static Scanner in = new Scanner(System.in); static BufferedReader re = new BufferedReader(new InputStreamReader(System.in)); static BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(System.out)); //String[] strs = re.readLine().split(" "); int a = Integer.parseInt(strs[0]); public static void main(String[] args) throws IOException { PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); //String[] strs = re.readLine().split(" "); //int T=Integer.parseInt(strs[0]); int T=in.nextInt(); //nt T=1; while(T>0){ //String[] strs1 = re.readLine().split(" "); //int n=Integer.parseInt(strs1[0]); //String s=re.readLine(); //char arr[]=s.toCharArray(); //Set<Integer>set=new HashSet<>(); //Map<Integer,Integer>map=new HashMap<>(); int a=in.nextInt(); int b=in.nextInt(); int c=in.nextInt(); //out.println((a-1)+" "+(c+c-b-1)); int sum=0; if(c>b){sum=c-b+c-1;} else{ sum=b-1; } if(a-1<sum)out.println("1"); else if(a-1>sum)out.println("2"); else if(a-1==sum)out.println("3"); //out.println(Math.min(a,b)); T--; } out.flush(); } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
8ea7549ab6400eb469e48b595c6e3981
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; import java.util.concurrent.ConcurrentHashMap; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { static final int INF=Integer.MAX_VALUE; static final long LINF=Long.MAX_VALUE; static FastReader in; static { try { in = new FastReader(); } catch (FileNotFoundException e) { e.printStackTrace(); } } static PrintWriter out = new PrintWriter(System.out); static int n; static int a; static int b; static int c; public static void main(String[] args) throws FileNotFoundException { int t=in.nextInt(); while(t-->0){ a=in.nextInt(); b=in.nextInt(); c=in.nextInt(); solve(); } out.flush(); in.close(); } static private void solve(){ int e1min=Math.abs(a-1); int e2min=(Math.abs(c-1)+Math.abs(c-b)); if(e1min<e2min){ out.println(1); }else if(e2min<e1min){ out.println(2); }else{ out.println(3); } } } class FastReader { BufferedReader br; StringTokenizer st; public FastReader() throws FileNotFoundException { //br = new BufferedReader(new InputStreamReader(new FileInputStream("/home/chaitanya/gitrepo/ds/src/main/resources/ts2_input.txt"))); 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; } void close(){ try { br.close(); } catch (IOException e) { e.printStackTrace(); } } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
68874061a670fb45d8cabddb91b8c40b
train_110.jsonl
1662993300
Vlad went into his appartment house entrance, now he is on the $$$1$$$-th floor. He was going to call the elevator to go up to his apartment.There are only two elevators in his house. Vlad knows for sure that: the first elevator is currently on the floor $$$a$$$ (it is currently motionless), the second elevator is located on floor $$$b$$$ and goes to floor $$$c$$$ ($$$b \ne c$$$). Please note, if $$$b=1$$$, then the elevator is already leaving the floor $$$1$$$ and Vlad does not have time to enter it. If you call the first elevator, it will immediately start to go to the floor $$$1$$$. If you call the second one, then first it will reach the floor $$$c$$$ and only then it will go to the floor $$$1$$$. It takes $$$|x - y|$$$ seconds for each elevator to move from floor $$$x$$$ to floor $$$y$$$.Vlad wants to call an elevator that will come to him faster. Help him choose such an elevator.
256 megabytes
import java.util.*; import java.io.*; public class Main { static long startTime = System.currentTimeMillis(); // for global initializations and methods starts here // global initialisations and methods end here static void run() { boolean tc = true; AdityaFastIO r = new AdityaFastIO(); //FastReader r = new FastReader(); try (OutputStream out = new BufferedOutputStream(System.out)) { //long startTime = System.currentTimeMillis(); int testcases = tc ? r.ni() : 1; int tcCounter = 1; // Hold Here Sparky------------------->>> // Solution Starts Here start: while (testcases-- > 0) { long a = r.nl(); long b = r.nl(); long c = r.nl(); long firstE = a - 1; long secondE = Math.abs(c - b) + c - 1; long min = Math.min(firstE, secondE); if (firstE == secondE) out.write((3 + " ").getBytes()); else if (min == firstE) out.write((1 + " ").getBytes()); else out.write((2 + " ").getBytes()); out.write(("\n").getBytes()); } // Solution Ends Here } catch (IOException e) { e.printStackTrace(); } } static class AdityaFastIO { final private int BUFFER_SIZE = 1 << 16; private final DataInputStream din; private final byte[] buffer; private int bufferPointer, bytesRead; public BufferedReader br; public StringTokenizer st; public AdityaFastIO() { br = new BufferedReader(new InputStreamReader(System.in)); din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public AdityaFastIO(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String word() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public String line() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public String readLine() throws IOException { byte[] buf = new byte[100000001]; // 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 ni() 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 nl() 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 nd() 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(); } } public static void main(String[] args) throws Exception { run(); } static int[] readIntArr(int n, AdityaFastIO r) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = r.ni(); return arr; } static long[] readLongArr(int n, AdityaFastIO r) throws IOException { long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = r.nl(); return arr; } static List<Integer> readIntList(int n, AdityaFastIO r) throws IOException { List<Integer> al = new ArrayList<>(); for (int i = 0; i < n; i++) al.add(r.ni()); return al; } static List<Long> readLongList(int n, AdityaFastIO r) throws IOException { List<Long> al = new ArrayList<>(); for (int i = 0; i < n; i++) al.add(r.nl()); return al; } static long mod = 998244353; static long modInv(long base, long e) { long result = 1; base %= mod; while (e > 0) { if ((e & 1) > 0) result = result * base % mod; base = base * base % mod; e >>= 1; } return result; } static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String word() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } String line() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int ni() { return Integer.parseInt(word()); } long nl() { return Long.parseLong(word()); } double nd() { return Double.parseDouble(word()); } } static int MOD = (int) (1e9 + 7); static long powerLL(long x, long n) { long result = 1; while (n > 0) { if (n % 2 == 1) result = result * x % MOD; n = n / 2; x = x * x % MOD; } return result; } static long powerStrings(int i1, int i2) { String sa = String.valueOf(i1); String sb = String.valueOf(i2); long a = 0, b = 0; for (int i = 0; i < sa.length(); i++) a = (a * 10 + (sa.charAt(i) - '0')) % MOD; for (int i = 0; i < sb.length(); i++) b = (b * 10 + (sb.charAt(i) - '0')) % (MOD - 1); return powerLL(a, b); } static long gcd(long a, long b) { if (a == 0) return b; else return gcd(b % a, a); } static long lcm(long a, long b) { return (a * b) / gcd(a, b); } static long lower_bound(int[] arr, int x) { int l = -1, r = arr.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (arr[m] >= x) r = m; else l = m; } return r; } static int upper_bound(int[] arr, int x) { int l = -1, r = arr.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (arr[m] <= x) l = m; else r = m; } return l + 1; } static void addEdge(ArrayList<ArrayList<Integer>> graph, int edge1, int edge2) { graph.get(edge1).add(edge2); graph.get(edge2).add(edge1); } public static class Pair implements Comparable<Pair> { int first; int second; public Pair(int first, int second) { this.first = first; this.second = second; } public String toString() { return "(" + first + "," + second + ")"; } public int compareTo(Pair o) { // TODO Auto-generated method stub if (this.first != o.first) return (int) (this.first - o.first); else return (int) (this.second - o.second); } @Override public int hashCode() { int hash = 5; hash = 17 * hash + this.first; return hash; } @Override public boolean equals(Object obj) { if (obj == null) return false; if (getClass() != obj.getClass()) return false; final Pair other = (Pair) obj; return this.first == other.first; } } public static class PairC<X, Y> implements Comparable<PairC> { X first; Y second; public PairC(X first, Y second) { this.first = first; this.second = second; } public String toString() { return "(" + first + "," + second + ")"; } public int compareTo(PairC o) { // TODO Auto-generated method stub return o.compareTo((PairC) first); } } static boolean isCollectionsSorted(List<Long> list) { if (list.size() == 0 || list.size() == 1) return true; for (int i = 1; i < list.size(); i++) if (list.get(i) <= list.get(i - 1)) return false; return true; } static boolean isCollectionsSortedReverseOrder(List<Long> list) { if (list.size() == 0 || list.size() == 1) return true; for (int i = 1; i < list.size(); i++) if (list.get(i) >= list.get(i - 1)) return false; return true; } }
Java
["3\n\n1 2 3\n\n3 1 2\n\n3 2 1"]
1 second
["1\n3\n2"]
NoteIn the first test case of the example, the first elevator is already on the floor of $$$1$$$.In the second test case of the example, when called, the elevators would move as follows: At the time of the call, the first elevator is on the floor of $$$3$$$, and the second one is on the floor of $$$1$$$, but is already going to another floor; in $$$1$$$ second after the call, the first elevator would be on the floor $$$2$$$, the second one would also reach the floor $$$2$$$ and now can go to the floor $$$1$$$; in $$$2$$$ seconds, any elevator would reach the floor $$$1$$$. In the third test case of the example, the first elevator will arrive in $$$2$$$ seconds, and the second in $$$1$$$.
Java 8
standard input
[ "math" ]
aca2346553f9e7b6e944ca2c74bb0b3d
The first line of the input contains the only $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, three integers each $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$, $$$b \ne c$$$) — floor numbers described in the statement.
800
Output $$$t$$$ numbers, each of which is the answer to the corresponding test case. As an answer, output: $$$1$$$, if it is better to call the first elevator; $$$2$$$, if it is better to call the second one; $$$3$$$, if it doesn't matter which elevator to call (both elevators will arrive in the same time).
standard output
PASSED
e0688f2cdee6b9e15ba7578e3c4dc6da
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
import java.io.*; import java.util.*; import java.util.concurrent.ThreadLocalRandom; public class Main { private static void solve(int[] x, int[] y) { int n = x.length; int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = y[i] - x[i]; } shuffleArray(a); Arrays.sort(a); int l = 0; int r = n - 1; int ans = 0; while (l < r) { long res = a[l] + a[r]; if (res >= 0) { ans++; l++; r--; } else { l++; } } System.out.println(ans); } static long calc(StringBuilder builder) { long ans = 0; long curr = 0; for (int i = 0; i < builder.length(); i++) { if (builder.charAt(i) == 'X') { curr++; } else { int val = builder.charAt(i) - '0'; ans += (long) val * curr; } } return ans; } static class BIT { int[] array; // 1-indexed array, In this array We save cumulative information to perform efficient range queries and updates public BIT(int size) { array = new int[size + 1]; } /** * Range Sum query from 1 to ind * ind is 1-indexed * <p> * Time-Complexity: O(log(n)) * * @param ind index * @return sum */ public int rsq(int ind) { assert ind > 0; int sum = 0; while (ind > 0) { sum += array[ind]; //Extracting the portion up to the first significant one of the binary representation of 'ind' and decrementing ind by that number ind -= ind & (-ind); } return sum; } /** * Range Sum Query from a to b. * Search for the sum from array index from a to b * a and b are 1-indexed * <p> * Time-Complexity: O(log(n)) * * @param a left index * @param b right index * @return sum */ public int rsq(int a, int b) { assert b >= a && a > 0 && b > 0; return rsq(b) - rsq(a - 1); } /** * Update the array at ind and all the affected regions above ind. * ind is 1-indexed * <p> * Time-Complexity: O(log(n)) * * @param ind index * @param value value */ public void update(int ind, int value) { assert ind > 0; while (ind < array.length) { array[ind] += value; //Extracting the portion up to the first significant one of the binary representation of 'ind' and incrementing ind by that number ind += ind & (-ind); } } public int size() { return array.length - 1; } } public static void main(String[] args) throws FileNotFoundException { FastScanner sc = new FastScanner(); int t = sc.nextInt(); for (int i = 0; i < t; i++) { int n = sc.nextInt(); int[] a = sc.readArrayInt(n); int[] b = sc.readArrayInt(n); solve(a, b); } } static <T> void shuffleArray(T[] ar) { // If running on Java 6 or older, use `new Random()` on RHS here Random rnd = ThreadLocalRandom.current(); for (int i = ar.length - 1; i > 0; i--) { int index = rnd.nextInt(i + 1); // Simple swap T a = ar[index]; ar[index] = ar[i]; ar[i] = a; } } static void shuffleArray(int[] ar) { // If running on Java 6 or older, use `new Random()` on RHS here Random rnd = ThreadLocalRandom.current(); for (int i = ar.length - 1; i > 0; i--) { int index = rnd.nextInt(i + 1); // Simple swap int a = ar[index]; ar[index] = ar[i]; ar[i] = a; } } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); FastScanner() throws FileNotFoundException { } String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long[] readArrayLong(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } int[] readArrayInt(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } } // 1 2 3
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
72ad3bd4d15444ea701a9482dd6ee517
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
//codeforces //package someAlgorithms; import java.util.*; import java.io.*; import java.lang.*; import java.io.File; public class Main { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); public static void main(String[] args) throws IOException{ String[] strNums = br.readLine().split(" "); int t=Integer.parseInt(strNums[0]); // int ot=t; // FileWriter fw = new FileWriter("C:\\Users\\Lenovo\\Desktop\\output.txt"); // fw.write(""); // fw.close(); while(t-->0) { //todo String[] strNums1 = br.readLine().split(" "); long n=Long.parseLong(strNums1[0]); // long b=Long.parseLong(strNums1[1]); // long c=Long.parseLong(strNums1[2]); // long c=Long.parseLong(strNums1[3]); // long d=Long.parseLong(strNums1[4]); // String str = br.readLine(); // String str2 = br.readLine(); Long[] arr = new Long[(int)n]; StringTokenizer tk = new StringTokenizer(br.readLine().trim()); for(int i=0;i<n;i++) { arr[i]=Long.parseLong(tk.nextToken()); } Long[] arr1 = new Long[(int)n]; StringTokenizer tk1 = new StringTokenizer(br.readLine().trim()); for(int i=0;i<n;i++) { arr1[i]=Long.parseLong(tk1.nextToken()); } Long[] diff = new Long[(int)n]; for(int i=0;i<n;i++) { diff[i]=arr1[i]-arr[i]; } Arrays.sort(diff); int ind=-1; int r=-1; int l=-1; for(int i=0;i<n;i++) { if(diff[i]==0) { if(i-1>=0) l=i-1; ind=i; while(i<n && diff[i]==0) i++; if(i<n) r=i; break; } else { if(i-1>=0 && diff[i-1]<0 && diff[i]>0) { l=i-1; r=i; ind=i; break; } } } int out=0; while(l>=0 && r<n && r!=-1) { if(diff[r]+diff[l]>=0) { out++; diff[r]=null; diff[l]=null; r++; l--; } else { r++; } } // System.out.println("out "+out); int cnt=0; if(ind!=-1) { for(int i=ind;i<n;i++) { if(diff[i]!=null) { cnt++; } } } else if(diff[0]>=0){ ind=0; for(int i=ind;i<n;i++) { if(diff[i]!=null) { cnt++; } } } out+=cnt/2; System.out.println(out); } } } /* bw.write(n+""); bw.newLine(); bw.flush(); System.out.println("Case #"+(ot-t)+":"+" YES"); FileWriter myWriter = new FileWriter("C:\\Users\\Lenovo\\Desktop\\output.txt",true); myWriter.write("Case #"+(ot-t)+": "+"YES"+"\n"); myWriter.close(); */ //class Pair{ // public long a=0; // public long b=0; // public Pair(long val,long id){ // this.a=val; // this.b=id; // } // //} //class Pair{ // public char val; // public long id; // public Pair(char val,long id){ // this.val=val; // this.id=id; // } // //} //class Node{ // public int val; //// public Node left=null; //// public Node right=null; // ArrayList<Node> children = new ArrayList<>(); // //} //class Comp implements Comparator<Pair>{ // public int compare(Pair p1,Pair p2) { // if(p1.val<p2.val) { // return -1; // } // if(p1.val>p2.val){ // return 1; // } // else return 0; //MUST WRITE THIS RETURN 0 FOR EQUAL CASE SINCE GIVE RUNTIME ERROR IN SOME COMPLIERS // } //} //sort [[a1,b1],[a2,b2]...] on basis of a1,a2.... since comparator compare run of each value of passed array! //class Comp implements Comparator<int[]>{ // public int compare(int[] p1,int[] p2) { // if(p1[0]<p2[0]) { // return -1; // } // if(p1[0]>p2[0]){ // return 1; // } // else return 0; // } //} //if take gcd of whole array the take default gcd=0 and keep doing gcd of 2 elements of array! //public static int gcd(int a, int b){ // if(b==0){ // return a; // } // return gcd(b,a%b); //} // //ArrayList<Long>[] adjlist = new ArrayList[(int)n+1]; //array of arraylist //for(int i=0;i<n;i++) { // String[] strNums2 = br.readLine().split(" "); // long a=Long.parseLong(strNums2[0]); // long b=Long.parseLong(strNums2[1]); // // adjlist[(int)a].add(b); // adjlist[(int)b].add(a); //} //int[][] vis = new int[(int)n+1][(int)n+1]; //OR can make list of list :- //List<List<Integer>> adjlist = new ArrayList<>(); //for(int i=0;i<n;i++){ // adjlist.add(new ArrayList<>()); //} //OR 1-D vis array //int[] vis = new int[(int)n+1]; /* Long[] arr = new Long[(int)n]; StringTokenizer tk = new StringTokenizer(br.readLine().trim()); for(int i=0;i<n;i++) { arr[i]=Long.parseLong(tk.nextToken()); } Long[][] arr = new Long[(int)n][(int)m]; for(int i=0;i<n;i++) { String[] strNums2 = br.readLine().split(" "); for(int j=0;j<m;j++) { arr[i][j]=Long.parseLong(strNums2[j]); } } 4 4 4 3 2 4 4 4 3 Main m = new Main(); //no need since pair class main class ne niche banao Pair p = m.new Pair(i,i+1); li.add(p); */ //double num = 3.9634; //double onum=num; //num = (double)((int)(num*100))/100; //double down = (num); //float up =(float) down; //if take up as double then will get large value when add (3.96+0.01)!! //if(down<onum) { // up=(float)down+(float)0.01; //// System.out.println(((float)3.96+(float)0.01)); //// System.out.println(3.96+0.01);//here both double, so output double , so here get large output other than 3.97!! //} ////in c++ 3.96+0.01 is by default 3.97 but in java need to type cast to float to get this output!! //System.out.println(down +" "+up); /* #include <iostream> #include <string> #include<vector> #include<queue> #include<utility> #include<limits.h> #include <unordered_set> #include<algorithm> using namespace std; */
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
603efef6c60255acd7890db64e321d39
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.Comparator; public class D { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter out = new PrintWriter(System.out); static int[]a = new int[(int)(1e5 + 10)]; static infos[]f = new infos[(int)(1e5 + 10)]; public static void main(String[] args)throws Exception{ int t = Integer.parseInt(br.readLine()); while((t--) > 0) { int n = Integer.parseInt(br.readLine()); String s[] = br.readLine().split(" "); for(int i = 0; i < n; i++) { a[i] = Integer.parseInt(s[i]); f[i] = new infos(); f[i].x = a[i]; } String yy[] = br.readLine().split(" "); for(int i = 0; i < n; i++) { f[i].y = Integer.parseInt(yy[i]); f[i].st = f[i].y - f[i].x; } Arrays.sort(f,0,n,new cmp()); int i = 0, j = n - 1; int ans = 0; while(i < j) { if(i >j) break; if(f[i].st + f[j].st >= 0) { i++; j--; ans++; } else { j--; } } out.println(ans); out.flush(); } } } class cmp implements Comparator<infos>{ public int compare(infos x1,infos x2) { return x2.st - x1.st; } } class infos{ int x,y; int st; }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
64ab2ce6678d08728e33b68f19123020
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.Comparator; public class D { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter out = new PrintWriter(System.out,true); static int[]a = new int[(int)(1e5 + 10)]; static infos[]f = new infos[(int)(1e5 + 10)]; public static void main(String[] args)throws Exception{ int t = Integer.parseInt(br.readLine()); while((t--) > 0) { int n = Integer.parseInt(br.readLine()); String s[] = br.readLine().split(" "); for(int i = 0; i < n; i++) { a[i] = Integer.parseInt(s[i]); f[i] = new infos(); f[i].x = a[i]; } String yy[] = br.readLine().split(" "); for(int i = 0; i < n; i++) { f[i].y = Integer.parseInt(yy[i]); f[i].st = f[i].y - f[i].x; } Arrays.sort(f,0,n,new cmp()); int i = 0, j = n - 1; int ans = 0; while(i < j) { if(i >j) break; if(f[i].st + f[j].st >= 0) { i++; j--; ans++; } else { j--; } } out.println(ans); } } } class cmp implements Comparator<infos>{ public int compare(infos x1,infos x2) { return x2.st - x1.st; } } class infos{ int x,y; int st; }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
a82a5e34c46dff6ad9efeec68527e3d2
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.Comparator; public class D { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter out = new PrintWriter(System.out); static int[]a = new int[(int)(1e5 + 10)]; static infos[]f = new infos[(int)(1e5 + 10)]; public static void main(String[] args)throws Exception{ int t = Integer.parseInt(br.readLine()); while((t--) > 0) { int n = Integer.parseInt(br.readLine()); String s[] = br.readLine().split(" "); for(int i = 0; i < n; i++) { a[i] = Integer.parseInt(s[i]); f[i] = new infos(); f[i].x = a[i]; } String yy[] = br.readLine().split(" "); for(int i = 0; i < n; i++) { f[i].y = Integer.parseInt(yy[i]); f[i].st = f[i].y - f[i].x; } Arrays.sort(f,0,n,new cmp()); int i = 0, j = n - 1; int ans = 0; while(i < j) { if(i >j) break; if(f[i].st + f[j].st >= 0) { i++; j--; ans++; } else { j--; } } System.out.println(ans); } } } class cmp implements Comparator<infos>{ public int compare(infos x1,infos x2) { return x2.st - x1.st; } } class infos{ int x,y; int st; }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
18236d334a022474a6b22d04ea17b113
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
import java.util.*; public class Main{ public static void main(String args[]) { Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t-->0) { int n=s.nextInt(); int x[]=new int[n]; int y[]=new int[n]; for(int i=0;i<n;i++) { x[i]=s.nextInt(); } for(int i=0;i<n;i++) { y[i]=s.nextInt(); } PriorityQueue<Integer> neg=new PriorityQueue<>((a,b)->(b-a)); PriorityQueue<Integer> pos=new PriorityQueue<>(); for(int i=0;i<n;i++) { int diff=y[i]-x[i]; if(diff<0) { neg.add(diff); } else { pos.add(diff); } } int count=0; while(!pos.isEmpty()&&!neg.isEmpty()) { int num1=pos.poll(); int num2=neg.poll(); if(num1+num2>=0) { count++; } else { //System.out.println("hello "+num2); neg.add(num2); if(pos.isEmpty()) { break; } pos.poll(); count++; } } //System.out.println(count+" "+pos.size()+" "+neg.size()); while(!pos.isEmpty()) { pos.poll(); if(pos.isEmpty()) { break; } pos.poll(); count++; } System.out.println(count); } } }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
5b3c00a0086b8b598ecf773d079753bc
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } int binary(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; } static int[] segment,parent,rank; static void constructSt(int n, int[] arr){ segment = new int[n*4+1]; formSt(arr, 1,0,n-1); } public static void formSt(int[] arr, int node, int s, int e){ if(s==e){ segment[node]= arr[s]; return; } formSt(arr, node*2,s,s+(e-s)/2); formSt(arr, node*2+1,s+(e-s)/2+1,e); segment[node]=Math.max(segment[node*2],segment[node*2+1]); } public static int findMax( int node, int s, int e,int l , int r){ if(l>e||s>r) return -1; if(s==e) return segment[node]; if(l<=s&&r>=e) return segment[node]; int mid = s+(e-s)/2; return Math.max(findMax(node*2,s,mid,l,r),findMax(node*2+1,mid+1,e,l,r)); } public static void dsu(int n){ parent = new int[n]; rank = new int[n]; for(int i =0;i<n;i++) parent[i]=i; } public static int find(int i){ if(i==parent[i] ) return i; return parent[i]=find(parent[i]); } public static void merge(int i, int j){ if(rank[i]>=rank[j]){ rank[i]+=rank[j]; parent[j]=i; } else { rank[j]+=rank[i]; parent[i]=j; } } public static void main (String[] args) throws java.lang.Exception { OutputStream outputStream =System.out; PrintWriter out =new PrintWriter(outputStream); FastReader sc =new FastReader(); int t =sc.nextInt(); while(t-->0){ int n = sc.nextInt(),sum=0; int[] a = new int[n]; for(int i =0;i<n;i++) a[i]=sc.nextInt(); for(int i =0;i<n;i++) a[i]= sc.nextInt()-a[i]; Arrays.sort(a); int s=0,e=a.length-1; while(s<e&&a[s]<0){ if(a[e]+a[s]>=0){ sum++;e--; } s++; } while(s<e&&a[s]<0) s++; sum+= (e-s+1)/2; out.print(sum+"\n"); } out.close(); // your code goes here" } } class pair { char c ; int x; public pair(char c , int x){ this.c=c; this.x=x; } } class solution{ }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
947a832a4c975030ab01df4aea280743
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
/** * @author Nitin Bhakar * */ import java.io.*; import java.util.*; public class Codeforces{ static long mod = 1000000007L; // map.put(a[i],map.getOrDefault(a[i],0)+1); // map.putIfAbsent; static int ninf = Integer.MIN_VALUE; static int inf = Integer.MAX_VALUE; static void swap(int[] a,int i,int j) {int temp = a[i]; a[i] = a[j]; a[j] = temp;} static void priArr(int[] a) {for(int i=0;i<a.length;i++) out.print(a[i] + " ");out.println();} static long gcd(long a,long b){if(b==0) return a; return gcd(b,a%b);} static int gcd(int a,int b){ if(b==0) return a;return gcd(b,a%b);} private static void sieve(boolean[] a, int n) {a[1] = false; for(int i=2;i*i<=n;i++) { if(a[i]) { for(int j=i*i;j<=n;j+=i) a[j] = false;}}} static MyScanner sc = new MyScanner(); //<----------------------------------------------WRITE HERE-------------------------------------------> static void solve(){ int n = sc.nextInt(); int[] a = sc.readIntArray(n); int[] b = sc.readIntArray(n); int[] c = new int[n]; for(int i=0;i<n;i++) { c[i] = b[i]-a[i]; } sort(c); // priArr(c); int i=0; int j= n-1; int ans = -1; while(i<=j) { int mid = (i+j)>>1; if(c[mid]<0) { ans = mid; i = mid+1; } else j = mid-1; } // out.print(ans+" "); int val = 0; if(ans == -1 ) { out.println(n/2); return; } else { int k = 0; int q = n-1; while(k<=ans) { if(c[k]+c[q]>=0) { val++; q--; } k++; } int rem = q-ans; val += rem/2; } out.println(val); } //<----------------------------------------------WRITE HERE-------------------------------------------> static class Pair implements Comparable<Pair> { int v1; int v2; Pair(int v,int f){ v1 = v; v2 = f; } public int compareTo(Pair p){ return this.v1-p.v1; } } public static void main(String[] args) { out = new PrintWriter(new BufferedOutputStream(System.out)); int t = sc.nextInt(); // int t= 1; while(t-- >0){ solve(); } // Stop writing your solution here. ------------------------------------- out.close(); } //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; //-----------MyScanner class for faster input---------- 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(); } public int[] readIntArray(int n){ int arr[] = new int[n]; for(int i = 0;i<n;i++){ arr[i] = Integer.parseInt(next()); } return arr; } int[] reverse(int arr[]){ int n= arr.length; int i = 0; int j = n-1; while(i<j){ int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; j--;i++; } return arr; } long[] readLongArray(int n){ long arr[] = new long[n]; for(int i = 0;i<n;i++){ arr[i] = Long.parseLong(next()); } return arr; } 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; } } private static void sort(int[] arr) {List<Integer> list = new ArrayList<>();for (int i=0; i<arr.length; i++)list.add(arr[i]);Collections.sort(list);for (int i = 0; i < arr.length; i++)arr[i] = list.get(i);} }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
86d09db0d790bb7400b8760550d3a985
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class cfct { public static void main (String[] args) throws java.lang.Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line = br.readLine(); int t = Integer.parseInt(line.split(" ")[0]); for(int tt=0;tt<t;tt++){ String line1 = br.readLine(); //Reading n and k which are written in the same line int n = Integer.parseInt(line1.split(" ")[0]); int[] x = new int[n]; //Reading arr String str1 = br.readLine(); String[] items1 = str1.split(" "); for(int j = 0; j < n; j++){ x[j] = Integer.parseInt(items1[j]); } int[] y = new int[n]; //Reading arr String str2 = br.readLine(); String[] items2 = str2.split(" "); for(int j = 0; j < n; j++){ y[j] = Integer.parseInt(items2[j]); } ArrayList<Integer> less=new ArrayList<>(); ArrayList<Integer> more=new ArrayList<>(); for(int i=0;i<n;i++){ if(x[i]<=y[i]){ more.add(y[i]-x[i]); }else{ less.add(x[i]-y[i]); } } int ptr=0,ans=0; Collections.sort(less); Collections.sort(more); for(int k=0;k<less.size()&&ptr<more.size();k++){ int num1 = less.get(k); while(ptr<more.size() && more.get(ptr)-num1<0){ ptr++; } if(ptr<more.size() && more.get(ptr)-num1>=0){ ptr++; ans++; } } System.out.println(ans+((more.size()-ans)/2)); } } }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
319a509a3d5e49cb3652589db27a4a82
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { /* BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw=new PrintWriter(new BufferedOutputStream(System.out)); int t=Integer.parseInt(br.readLine()); while(t-->0){ int n=Integer.parseInt(br.readLine()); String[] inp=br.readLine().trim().split(" "); } */ /* Scanner cs=new Scanner(System.in); PrintWriter pw=new PrintWriter(new BufferedOutputStream(System.out)); int t=cs.nextInt(); while(t-->0){ int n=cs.nextInt(); int[] a=new int[n]; for(int i=0;i<n;i++){ a[i]=cs.nextInt(); } } */ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine()); while(t-->0){ int n = Integer.parseInt(br.readLine()); String[] inp = br.readLine().trim().split(" "); int[] a = new int[n]; for(int i=0;i<n;i++){ a[i] = Integer.parseInt(inp[i]); } inp = br.readLine().trim().split(" "); List<Integer> pos = new ArrayList<>(); List<Integer> neg = new ArrayList<>(); int zero = 0; for(int i=0;i<n;i++){ int x = Integer.parseInt(inp[i]); a[i] -= x; if(a[i] < 0) neg.add(a[i]); else if(a[i] > 0) pos.add(a[i]); else zero ++; } Arrays.sort(a); int i=0; int j = n-1; int ans = 0; while(i < j){ if(a[i]+a[j] <=0){ ans++; i++; j--; }else j--; } Collections.sort(pos); Collections.sort(neg, Collections.reverseOrder()); int l1 = pos.size(); int l2 = neg.size(); /* System.out.println(pos); // System.out.println(neg); int i = 0; int j = 0; int cnt = 0; int cur = 0; int ngcur = 0; while(i < l1 && j < l2){ cur = pos.get(i); int p = j; while(j < l2 && cur > 0){ cur += neg.get(j); j++; } if(cur <= 0){ cnt++; i++; }else{ j = p; break; } } if(j < l2){ int rem = l2 - j; cnt += (rem+zero) / 2; }else{ cnt += (zero) / 2; }*/ System.out.println(ans); /* String st = br.readLine(); int n = st.length(); TreeMap<Character, List<Integer>> tm = new TreeMap<>(); for(int i=0;i<n;i++){ char ch = st.charAt(i); tm.putIfAbsent(ch, new ArrayList<>()); tm.get(ch).add(i); } List<Integer> ans = new ArrayList(); char ch = st.charAt(0); // System.out.println(tm); char last = st.charAt(n-1); while(ch != st.charAt(n-1)){ // System.out.println(ch); List<Integer> al = tm.get(ch); for(int i=0;i<al.size();i++){ ans.add(al.get(i)); } tm.remove(ch); Character low = tm.lowerKey(ch); Character high = tm.higherKey(ch); // System.out.println(low +" "+high); if(low == null){ ch = high; }else if(high == null){ ch = low; }else{ if(last > ch){ ch = high; }else ch = low; } } List<Integer> al = tm.get(ch); for(int i=0;i<al.size();i++){ if(al.get(i) != n-1) ans.add(al.get(i)); } ans.add(n-1);//System.out.println(ans); int tot = 0; for(int i=1;i<ans.size();i++){ // System.out.println(st.charAt(ans.get(i))+" "+st.charAt(ans.get(i-1))); tot += Math.abs((st.charAt(ans.get(i))) - (st.charAt(ans.get(i-1)))); } System.out.println(tot+" "+ans.size()); for(int i=0;i<ans.size();i++){ System.out.print((ans.get(i)+1)+" "); } System.out.println(); */ /* int n=Integer.parseInt(br.readLine()); String st = br.readLine(); StringBuilder sb = new StringBuilder(); int j = n-1; while(j >= 0){ if(st.charAt(j) == '0'){ int n1 = Integer.parseInt(st.substring(j-2, j)); char p = ((char)(96+n1)); sb.append(p); j-=3; }else{ int n1 = Integer.parseInt(st.substring(j, j+1)); char p = ((char)(96+n1)); sb.append(p); j-=1; } } sb.reverse(); System.out.println(sb); */ } } static long power(long x, long y) { //0^0 = 1 int mod = 1000000007; long res = 1L; x = x % mod; while (y > 0) { if ((y & 1) == 1) res = (res * x) % mod; y >>= 1; x = (x * x) % mod; } return res; } static class DSU{ public int component; public int[] parent; public int[] sz; public int size; DSU(int size){ this.size = component = size; parent=new int[size]; for(int i=0;i<size;i++){ parent[i]=i; } sz = new int[size+1]; for(int i=0;i<size;i++){ sz[i]=1; } } public int findParent(int node){ if(node == parent[node]) return node; return parent[node] = findParent(parent[node]); } public int totalComponent(){ return component; } public void union(int a, int b){ int par_a = findParent(a); int par_b = findParent(b); if(par_a==par_b) return ; if(sz[par_b] > sz[par_a]){ sz[par_b]+=sz[par_a]; parent[par_a] = par_b; }else{ sz[par_a]+=sz[par_b]; parent[par_b] = par_a; } component--; } } }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
b3056f5c6a22e41e9578e506b41cab92
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.StringTokenizer; public class test { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); int t = Integer.parseInt(br.readLine()); while (t-- > 0) { int n = Integer.parseInt(br.readLine()); int[] x = new int[n]; int[] y = new int[n]; StringTokenizer tokenizer = new StringTokenizer(br.readLine()); for (int i = 0; i < n; i++) { x[i] = Integer.parseInt(tokenizer.nextToken()); } tokenizer = new StringTokenizer(br.readLine()); for (int i = 0; i < n; i++) { y[i] = Integer.parseInt(tokenizer.nextToken()); } ArrayList<Integer> diff = new ArrayList<>(); for (int i = 0; i < n; i++) { diff.add(y[i] - x[i]); } Collections.sort(diff, Collections.reverseOrder()); int j = n - 1; int res = 0; for(int i = 0; i < n; i++){ while(j > i && diff.get(i) + diff.get(j) < 0) j--; if(i >= j) break; res++;j--; } pw.println(res); } pw.flush(); pw.close(); br.close(); } }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
96b805fe56b718debfc02662e35470fd
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
import java.util.*; import java.io.*; import java.math.BigInteger; import java.math.*; public class Div3_D { static FastReader sc= new FastReader(); //static PrintWriter out= new PrintWriter(System.out); /* ****************************************************************************************************************** ****************************************************************************************************************** ****************************************************************************************************************** ***************************************************************************************************************** ************************************SSSSSSSSSSSSSSSSSSSSSSSSSS**************************************************** ************************************SSSSSSSSSSSSSSSSSSSSSSSSSS**************************************************** ************************************SSSSSSSSSSSSSSSSSSSSSSSSSS**************************************************** ************************************SSS*************************************************************************** ************************************SSS*************************************************************************** ************************************SSS*************************************************************************** ************************************SSSSSSSSSSSSSSSSSSSSSSSSSS**************************************************** ************************************SSSSSSSSSSSSSSSSSSSSSSSSSS**************************************************** ************************************SSSSSSSSSSSSSSSSSSSSSSSSSS**************************************************** ***********************************************************SSS**************************************************** ***********************************************************SSS**************************************************** ************************************SSSSSSSSSSSSSSSSSSSSSSSSSS**************************************************** ************************************SSSSSSSSSSSSSSSSSSSSSSSSSS**************************************************** ************************************SSSSSSSSSSSSSSSSSSSSSSSSSS**************************************************** ****************************************************************************************************************** ****************************************************************************************************************** ****************************************************************************************************************** ****************************************************************************************************************** */ static Boolean prime[] = new Boolean[10000002]; static void seive(int n) { int count=0; for(int p = 2; p*p <=n; p++) { // If prime[p] is not changed, then it is a prime if(prime[p] == null) { // Update all multiples of p for(int i = p*p; i <= n; i += p) prime[i] = false; } } } static class Pair implements Comparable<Pair> { long elem; long wt; Pair(long elem,long wt) { this.elem=elem; this.wt=wt; } public int compareTo(Pair obj) { return (int)(obj.elem-this.elem); } } public static void main(String args[]) { PrintWriter out = new PrintWriter(System.out); long start=System.currentTimeMillis(); int test=sc.nextInt(); while(test>0) { int n=sc.nextInt(); long arr[]=new long[n]; long brr[]=new long[n]; long crr[]=new long[n]; for(int i=0; i<n; i++) arr[i]=sc.nextLong(); for(int j=0; j<n; j++) brr[j]=sc.nextLong(); for(int i=0; i<n; i++) crr[i]=brr[i]-arr[i]; Arrays.sort(crr); int count=0; int i=0; int j=arr.length-1; while(i<j) { if((crr[i]+crr[j])>=0) { count++; i++; j--; } else i++; } System.out.println(count); test--; } long end=System.currentTimeMillis(); //System.out.println((end-start)+" "+"m/s"); } static long gcd(long a, long b){ // GCD fun.... return b==0?a:gcd(b,a%b); } static int fact(int num){ // Factorial of int...12 int point=1; for(int i=1; i<=num; i++) { point=point*i; } return point; } static void fact(BigInteger num){ // Factorial of BigInteger(>10^4)..2second BigInteger one=BigInteger.valueOf(1); BigInteger m=BigInteger.valueOf(1); BigInteger i=one; for(i=BigInteger.valueOf(1); num.compareTo(i)>=0; i=i.add(BigInteger.valueOf(1))) m=m.multiply(i); System.out.println(m); } static long fact(long num){ // lfactorial of Long....(<=16) long point=1; for(long i=1; i<=num; i++) { point=point*i; } return point; } static void input(long arr[][],int n,int m){ //long 2d-array input... for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { arr[i][j]=sc.nextLong(); } } } static void input(int arr[][],int n,int m){ //int 2d-array input... for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { arr[i][j]=sc.nextInt(); } } } static void input(String arr[][],int n,int m){ //String 2d-array input... for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { arr[i][j]=sc.nextLine(); } } } static void input(long arr[],int n){ //long 1d array input for(int i=0; i<n; i++) { arr[i]=sc.nextLong(); } } static void input(int arr[],int n){ //int 1d array input for(int i=0; i<n; i++) { arr[i]=sc.nextInt(); } } static void input(char arr[],int n){ //char 1d array input for(int i=0; i<n; i++) { arr[i]=sc.next().charAt(0); } } private static int countDigits(int l) { //count of digit..Integer 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; } private static int countDigits(long l) { // count of Long Digit.. 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; } static class FastReader { // Fast input Reader class ...Jaaan 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 s=""; try { s=br.readLine(); } catch (IOException e) { e.printStackTrace(); } return s; } } static void print(long a[]) { //print long array int n=a.length; for(int i=0;i<n;i++) System.out.print(a[i]+" "); System.out.println(); } static void print(int a[]) { //print int array int n=a.length; for(int i=0;i<n;i++) System.out.print(a[i]+" "); System.out.println(); } static void print(String a[]) { //print String array int n=a.length; for(int i=0;i<n;i++) System.out.print(a[i]+" "); System.out.println(); } static void print(double a[]) { //print Double array int n=a.length; for(int i=0;i<n;i++) System.out.print(a[i]+" "); System.out.println(); } static void print(char a[]) { //print Char array int n=a.length; for(int i=0;i<n;i++) System.out.print(a[i]+" "); System.out.println(); } }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
cd1570384f2e4829c27bcb6e250f423e
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
import java.io.*; import java.math.*; import java.util.*; import java.util.stream.Collectors; import java.net.*; public class P03 { static class FastReader{ BufferedReader br ; StringTokenizer st; public FastReader() {br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while(st==null || !st.hasMoreElements()){try {st = new StringTokenizer(br.readLine());}catch(IOException e) {e.printStackTrace();}} return st.nextToken(); } int nextInt(){return Integer.parseInt(next());} long nextLong(){return Long.parseLong(next());} double nextDouble(){return Double.parseDouble(next());} float nextFloat(){return Float.parseFloat(next());} String nextLine(){ String str = ""; try { str = br.readLine(); }catch(IOException e) { e.printStackTrace(); } return str ; } } static class CPair { char ch ; Integer index; public CPair(char ch,Integer ind) { this.ch =ch; index=ind; } int getIndex() { return index; } char getChar() { return ch; } } static class BPair { Integer index;boolean value; public BPair(Integer index, boolean value) {this.value =value;this.index =index;} int getIndex() {return index;} boolean getValue() {return value;} } static class Pair implements Comparable<Pair> { Integer index,value; public Pair(Integer index, Integer value) {this.value = value;this.index = index;} @Override public int compareTo(Pair o){return value - o.value;} int getValue(){ return value;} int getindex(){return index;} } private static long gcd(long l, long m){ if(m==0) {return l;} return gcd(m,l%m); } static void swap(int[] arr, int i, int j){ int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } static int partition(int[] arr, int low, int high){ long pivot = arr[high]; int i = (low - 1); for(int j = low; j <= high - 1; j++){ if (arr[j] < pivot){ i++; swap(arr, i, j); } } swap(arr, i + 1, high); return (i + 1); } static void quickSort(int[] arr, int low, int high){ if (low < high){ int pi = partition(arr, low, high); quickSort(arr, low, pi - 1); quickSort(arr, pi + 1, high); } } static long M = 1000000007; static long powe(long a,long b) { long res =1; while(b>0){ if((b&1)!=0) { res=(res*a)&M; } a=(a*a)%M; b>>=1; } return res; } static long power(long x, long y, long p) { long res = 1; x = x % p; if (x == 0) return 0; while (y > 0){ if ((y & 1) != 0) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } static boolean [] seive(int n) { boolean a[] = new boolean[n+1]; Arrays.fill(a, true); a[0]=false; a[1]=false; for(int i =2;i<=Math.sqrt(n);i++) { for(int j =2*i;j<=n;j+=i) { a[j]=false; } } return a; } private static String swap(String s, int i, int j){ if(i>=j)return s; String ans = s.substring(0,i); ans+=s.charAt(j); ans+=s.substring(i+1,j); ans+=s.charAt(i); ans+=s.substring(j+1); return ans; } private static void pa(char[] cs){for(int i =0;i<cs.length;i++){System.out.print(cs[i]+" ");}System.out.println();} private static void pa(long[] b){for(int i =0;i<b.length;i++) {System.out.print(b[i]+" ");}System.out.println();} private static void pm(Character[][] a){for(int i =0;i<a.length;i++){for(int j=0;j<a[i].length;j++){System.out.print(a[i][j]);}System.out.println();}} private static void pm(int [][] a) {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();}} private static void pa(int[] a){for(int i =0;i<a.length;i++){System.out.print(a[i]+" ");}System.out.println();} private static boolean isprime(int n){if (n <= 1) return false;else if (n == 2) return true;else if (n % 2 == 0) return false;for (int i = 3; i <= Math.sqrt(n); i += 2){if (n % i == 0) return false;}return true;} static int lb(int[] b, long a){ int l=-1,r=b.length; while(l+1<r) { int m=(l+r)>>>1; if(b[m]>=a) r=m; else l=m; } return r; } static int ub(long a[], long x){ int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]<=x) l=m; else r=m; } return l+1; } static //MAIN FUNCTION -------> ArrayList<String> alpos = new ArrayList<>(); public static void main(String[] args) throws IOException { long start2 = System.currentTimeMillis(); FastReader fs = new FastReader(); PrintWriter write = new PrintWriter(System.out); Scanner sc = new Scanner (System.in); int t =1; t = fs.nextInt(); while(t-->0) { int n = fs.nextInt(); int a [] = new int [n]; int b [] = new int [n]; ArrayList<Integer> arr = new ArrayList<>(); for(int i =0;i<n;i++) { a[i]=fs.nextInt(); } for(int i =0;i<n;i++) { b[i]=fs.nextInt(); arr.add(b[i]-a[i]); } Collections.sort(arr); // System.out.println(arr); int i =0,j=arr.size()-1; int c=0; while(i<j) { if(arr.get(i)+arr.get(j)>=0) { c++; i++; j--; } else { i++; } } System.out.println(c); } } } /* */
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
18096a42c630305f77be78e8c4a1f265
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
//package Algorithm; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.Arrays; import java.util.Collections; import java.util.PriorityQueue; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); StringTokenizer st = new StringTokenizer(br.readLine()); int T = Integer.parseInt(st.nextToken()); for (int test = 1; test <= T; test++) { st = new StringTokenizer(br.readLine()); int N = Integer.parseInt(st.nextToken()); int[] a = new int[N]; int[] b = new int[N]; st = new StringTokenizer(br.readLine()); for (int i = 0; i < N; i++) { a[i] = Integer.parseInt(st.nextToken()); } st = new StringTokenizer(br.readLine()); for (int i = 0; i < N; i++) { b[i] = Integer.parseInt(st.nextToken()); } int[] seq = new int[N]; for(int i=0;i<N;i++) { seq[i] = b[i] - a[i]; } Arrays.sort(seq); int start = 0; int end = N-1; int cnt = 0; while(start<end) { //bw.write(test+" "+seq[start]+" "+seq[end]+"\n"); if(seq[start]+seq[end]>=0) { cnt++; start++; end--; } else { start++; } } bw.write(cnt+"\n"); } bw.flush(); } }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
53a7ce84cd6fb6fda67e2a104f641147
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
import java.util.*; import java.io.*; public class Main { static PrintWriter out = new PrintWriter(System.out); static FastReader sc = new FastReader(); public static void main (String[] args) throws java.lang.Exception { int t = 1; t = i(); int te=t; while(t-- > 0){ long ans=0; //x = x ^ y ^ (y = x); //String.format("%.10f",ans) //out.print("Case #"+(te-t)+": "); //Map<Integer,Integer> map= new TreeMap<Integer,Integer>(); //Map<Character,ArrayList<Integer>> map= new HashMap<Character,ArrayList<Integer>>(); // Map<Integer,Integer> val= new HashMap<Integer,Integer>(); //Set <Character> set=new HashSet<Character>(); //TreeSet <pair> set=new TreeSet<pair>(); //ArrayList<Integer>arr= map.get(s.charAt(i)); ArrayList<Integer> neg=new ArrayList<>(); ArrayList<Integer> pos=new ArrayList<>(); ArrayList<Integer> zero=new ArrayList<>(); //StringBuilder str = new StringBuilder(); int c=0; int n=i(); int arr[]=input(n); int arr1[]=input(n); int diffp[]=new int[n]; for(int i=0;i<n;i++){ diffp[i]=arr1[i]-arr[i]; //out.println(diffp[i]); if(diffp[i]<0){ neg.add(diffp[i]); } else if(diffp[i]>0){ pos.add(diffp[i]); } else{ zero.add(diffp[i]); } } msort(diffp); // outarr(diffp); //reverse(diffp); int l=n-1,b=0; while(b<l&&b<n){ if(diffp[b]+diffp[l]>=0){ ans++; b++; l--; } else{ b++; } } out.println(ans); } out.close(); } public static TreeMap<Integer,Integer> freq(int arr[]){ int n=arr.length; TreeMap<Integer,Integer> map = new TreeMap<Integer,Integer>(); for(int i=0;i<n;i++){ map.put(arr[i],map.getOrDefault(arr[i],0)+1); } return map; } public static void reverse(int[] arr){ ArrayList<Integer> temp = new ArrayList<>(); for(int x : arr){ temp.add(x); } Collections.reverse(temp); for(int i = 0;i < arr.length;i++){ arr[i] = temp.get(i); } } public static int[] prevSmaller(int a[]){ int ps[]=new int[a.length]; Stack<Integer> s=new Stack<>(); for(int i=0;i<a.length;i++){ while(!s.isEmpty()&&a[s.peek()]>=a[i]){ s.pop(); } if(s.isEmpty()){ ps[i]=-1; } else{ ps[i]=s.peek(); } s.push(i); } return ps; } public static int[] nextSmaller(int a[]){ int ps[]=new int[a.length]; Stack<Integer> s=new Stack<>(); for(int i=a.length-1;i>=0;i--){ while(!s.isEmpty()&&a[s.peek()]>=a[i]){ s.pop(); } if(s.isEmpty()){ ps[i]=a.length; } else{ ps[i]=s.peek(); } s.push(i); } return ps; } public static void msort(int[] arr){ ArrayList<Integer> doop = new ArrayList<>(); for(int x : arr){ doop.add(x); } Collections.sort(doop); for(int i = 0;i < arr.length;i++){ arr[i] = doop.get(i); } } public static void outarr(int[] arr){ for(int i=0;i<arr.length;i++){ out.print(arr[i]+" "); } out.println(); } public static void outarrl(long[] arr){ for(int i=0;i<arr.length;i++){ out.print(arr[i]+" "); } out.println(); } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } public static int rev(int a){ int n=a,dig=0; while(n>0){ dig++; n=n/10; } int rev=0; while(dig>0){ rev=rev*10+(a%10); a/=10; dig--; } return rev; } static int i() { return sc.nextInt(); } static long l() { return sc.nextLong(); } static int[] input(int N){ int A[]=new int[N]; for(int i=0; i<N; i++) { A[i]=sc.nextInt(); } return A; } static long[] inputLong(int N) { long A[]=new long[N]; for(int i=0; i<A.length; i++)A[i]=sc.nextLong(); return A; } public static int lastset(int num){ int ans=1; while(num>0){ if((num&1)>0){ return ans; } ans++; num=num>>1; } return -1; } } 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; } } class pair implements Comparable<pair> { int x; int y; //int z; public pair(int x, int y) { this.x = x; this.y = y; //this.z = z; } public String toString() { return x + " " + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair) o; return p.x == x && p.y == y; } return false; } // public int hashCode() { // return new Integer(x).hashCode() * 31 + new Integer(y).hashCode(); // } public int compareTo(pair other) { if(this.x == other.x){ return Integer.compare(this.y,other.y); } return Integer.compare(this.x,other.x); } }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
2453c7b1bc529aaacf9c687f08104c66
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.InputMismatchException; public class D { public static void main(String[] args) { RealFastReader rf = new RealFastReader(System.in); int t = rf.ni(); while (t-- > 0) { int n = rf.ni(); long[] x = rf.nal(n); long[] y = rf.nal(n); Long[] d = new Long[n]; int ans = 0; int sss = 0; for (int i = 0; i < n; i++) { d[i] = y[i]-x[i]; if(d[i]>=0){ sss++; } } Arrays.sort(d); int from = 0, to = n-1; for(int i = from ;i<n; i++){ if(d[i]>=0){ break; } if(d[to]<=0){ break; } if(d[i]+d[to]>=0){ to--; ans ++; } } ans = (sss-ans>>1) + ans; System.out.println(ans); } } static public class RealFastReader { InputStream is; public RealFastReader(final InputStream is) { this.is = is; } private byte[] inbuf = new byte[8192]; public int lenbuf = 0, ptrbuf = 0; public int readByte() { if (lenbuf == -1) { throw new InputMismatchException(); } if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) { return -1; } } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } public double nd() { return Double.parseDouble(ns()); } public char nc() { return (char) skip(); } public String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } public int[] na(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = ni(); } return a; } public long[] nal(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = nl(); } return a; } public char[][] nm(int n, int m) { char[][] map = new char[n][]; for (int i = 0; i < n; i++) { map[i] = ns(m); } return map; } public int[][] nmi(int n, int m) { int[][] map = new int[n][]; for (int i = 0; i < n; i++) { map[i] = na(m); } return map; } public int ni() { int num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } public long nl() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } } }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
8e9f7d2a2fa86be1066833897743cb0f
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.InputMismatchException; import java.util.Scanner; public class D { public static void main(String[] args) { Scanner sc = new Scanner(System.in); RealFastReader rf = new RealFastReader(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.nextLong(); } for (int i = 0; i < n; i++) { y[i] = sc.nextLong(); } Long[] d = new Long[n]; int ans = 0; int sss = 0; for (int i = 0; i < n; i++) { d[i] = y[i]-x[i]; if(d[i]>=0){ sss++; } } Arrays.sort(d); int from = 0, to = n-1; for(int i = from ;i<n; i++){ if(d[i]>=0){ break; } if(d[to]<=0){ break; } if(d[i]+d[to]>=0){ to--; ans ++; } } ans = (sss-ans>>1) + ans; System.out.println(ans); } } static public class RealFastReader { InputStream is; public RealFastReader(final InputStream is) { this.is = is; } private byte[] inbuf = new byte[8192]; public int lenbuf = 0, ptrbuf = 0; public int readByte() { if (lenbuf == -1) { throw new InputMismatchException(); } if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) { return -1; } } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } public double nd() { return Double.parseDouble(ns()); } public char nc() { return (char) skip(); } public String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } public int[] na(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = ni(); } return a; } public long[] nal(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = nl(); } return a; } public char[][] nm(int n, int m) { char[][] map = new char[n][]; for (int i = 0; i < n; i++) { map[i] = ns(m); } return map; } public int[][] nmi(int n, int m) { int[][] map = new int[n][]; for (int i = 0; i < n; i++) { map[i] = na(m); } return map; } public int ni() { int num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } public long nl() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } } }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
000cf7ad168046a16c486752bfa7137c
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
import java.io.*; import java.util.*; 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.IOException; import java.io.InputStreamReader; import java.util.TreeSet; import java.util.StringTokenizer; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.BufferedReader; import java.io.InputStream; public class Solution{ public 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 swap(int i, int j) { int temp = i; i = j; j = temp; } static class Pair{ int s; int end; public Pair(int a, int e) { end = e; s = a; } } 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++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void println(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } } public static void main(String[] args) throws Exception { FastReader scn = new FastReader(); OutputStream outputStream = System.out; OutputWriter output = new OutputWriter(outputStream); int t = scn.nextInt(); long mod = 1000000007L; // String[] pal = {"0000", "0110","0220","0330","0440","0550","1001","1111","1221","1331","1441","1551","2002","2112","2222","2332"}; while(t>0) { int n = scn.nextInt(); long[] a= new long[n]; for(int i=0;i<n;i++) { a[i]= scn.nextLong(); } for(int i=0;i<n;i++) { long x = scn.nextLong(); a[i]= x-a[i]; } List<Long> neg = new ArrayList<>(); List<Long> pos = new ArrayList<>(); TreeMap<Long, Integer> m1 =new TreeMap<>(); for(int i=0;i<n;i++) { if(a[i]<0) { neg.add(a[i]); }else { if(!m1.containsKey(a[i])) { m1.put(a[i], 1); }else { m1.put(a[i],m1.get(a[i])+1); } pos.add(a[i]); } } int ans = pos.size()/2; int cnt =0; for(int i= neg.size()-1;i>=0;i--) { Long c = m1.ceilingKey(-1*neg.get(i)); if(c!=null) { cnt++; if(m1.get(c)==1) { m1.remove(c); }else { m1.put(c, m1.get(c)-1); } } } int rem =0; for(long key: m1.keySet()) { rem = rem+m1.get(key); } cnt =cnt+(rem/2); output.println(Math.max(ans,cnt)); t--; } output.close(); } static int CeilIndex(int A[], int l, int r, int key) { while (r - l > 1) { int m = l + (r - l) / 2; if (A[m] >= key) r = m; else l = m; } return r; } static int lis(int A[], int size) { // Add boundary case, when array size is one int[] tailTable = new int[size]; int len; // always points empty slot tailTable[0] = A[0]; len = 1; for (int i = 1; i < size; i++) { if (A[i] < tailTable[0]) // new smallest value tailTable[0] = A[i]; else if (A[i] > tailTable[len - 1]) // A[i] wants to extend largest subsequence tailTable[len++] = A[i]; else // A[i] wants to be current end candidate of an existing // subsequence. It will replace ceil value in tailTable tailTable[CeilIndex(tailTable, -1, len - 1, A[i])] = A[i]; } return len; } public static int checkL(char[][] a, int r, int c, boolean[][] mark) { int cnt=0; for(int i=Math.max(r-1,0);i<=Math.min(r+2,a.length-1);i++) { for(int j= Math.max(c-1,0);j<=Math.min(c+2,a[0].length-1);j++) { if(a[i][j]=='*') { cnt++; } } } char ch11 = a[r][c]; char ch12 = a[r][c+1]; char ch21 = a[r+1][c]; char ch22 = a[r+1][c+1]; int n = a.length; int m = a[0].length; if(cnt==4) { if(ch22!='*' && r+2<n && c+2<m && a[r+2][c+2]=='*') { cnt--; }else if(ch21!='*' && r+2<n && c-1>=0 && a[r+2][c-1]=='*') { cnt--; }else if(ch11!='*' && r-1>=0 && c-1>=0 && a[r-1][c-1]=='*') { cnt--; }else if(ch12!='*' && r-1>=0 && c+2<m && a[r-1][c+2]=='*') { cnt--; } } if(cnt==0) { return 1; } if(cnt>3) { return 4; } if(cnt<3) { return 2; } if((ch11=='*' && ch12=='*' && ch22=='*' && ch21!='*')|| (ch11=='*' && ch21=='*' && ch22=='*' && ch12!='*') || (ch12=='*'&&ch22=='*'&&ch21=='*'&&ch11!='*')||(ch11=='*'&&ch12=='*'&&ch21=='*'&&ch22!='*')) { for(int i=r;i<r+2;i++) { for(int j=c;j<c+2;j++) { if(a[i][j]=='*') { mark[i][j] = true; } } } return 1; } return 1; } public static void addTime(int h, int m, int ah, int am) { int rm = m+am; int rh = (h+ah+(rm/60))%24; rm = rm%60; } public static long power(long x, long y, long p) { long res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p if (x == 0) return 0; // In case x is divisible by p; while (y > 0) { // If y is odd, multiply x with result if ((y & 1) != 0) res = (res * x) % p; // y must be even now y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
8638b71772dc750f4b2214eea2b38409
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
import java.math.BigInteger; import java.util.*; import javax.lang.model.util.ElementScanner6; public class Main{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int testcase=sc.nextInt(); for(int tc=1;tc<=testcase;tc++){ //System.out.print("Case #"+tc+": "); int n=sc.nextInt(); int a[] = new int[n]; int b[] = new int[n]; for(int i=0;i<n;i++){ a[i]=sc.nextInt(); } for(int i=0;i<n;i++){ b[i]=sc.nextInt(); } int c[] = new int[n]; for(int i=0;i<n;i++){ c[i]=b[i]-a[i]; } Arrays.sort(c); int ans = 0, i = 0, j = n-1; while(i<j){ if(c[i] + c[j] < 0){ i++; continue; } ans++; i++; j--; } System.out.println(ans); } sc.close(); } static int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } // method to return LCM of two numbers static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static int f(int order[], int disAmount){ int count = 0; for(int x : order){ if(x > 0 && disAmount % x == 0) count++; } return count; } static int upper_bound(int arr[], int key) { int mid, N = arr.length; // Initialise starting index and // ending index int low = 0; int high = N; // Till low is less than high while (low < high && low != N) { // Find the index of the middle element mid = low + (high - low) / 2; // If key is greater than or equal // to arr[mid], then find in // right subarray if (key >= arr[mid]) { low = mid + 1; } // If key is less than arr[mid] // then find in left subarray else { high = mid; } } // If key is greater than last element which is // array[n-1] then upper bound // does not exists in the array if (low > N ) { low--; } // Print the upper_bound index return low; } static int lower_bound(int array[], int key) { // Initialize starting index and // ending index int low = 0, high = array.length; int mid; // Till high does not crosses low while (low < high) { // Find the index of the middle element mid = low + (high - low) / 2; // If key is less than or equal // to array[mid], then find in // left subarray if (key <= array[mid]) { high = mid; } // If key is greater than array[mid], // then find in right subarray else { low = mid + 1; } } // If key is greater than last element which is // array[n-1] then lower bound // does not exists in the array if(low==-1) low++; // Returning the lower_bound index return low; } static boolean palin(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; } static long minSum(int arr[], int n, int k) { // k must be smaller than n if (n < k) { // System.out.println("Invalid"); return -1; } // Compute sum of first window of size k long res = 0; for (int i=0; i<k; i++) res += arr[i]; // Compute sums of remaining windows by // removing first element of previous // window and adding last element of // current window. long curr_sum = res; for (int i=k; i<n; i++) { curr_sum += arr[i] - arr[i-k]; res = Math.min(res, curr_sum); } return res; } static int nextIndex(int a[], int x){ int n=a.length; for(int i=x;i<n-1;i++){ if(a[i]>a[i+1]){ return i; } } return n; } static void rev(int a[], int i, int j){ while(i<j){ int t=a[i]; a[i]=a[j]; a[j]=t; i++; j--; } } static int sorted(char arr[], int n) { // Array has one or no element or the // rest are already checked and approved. if (n == 1 || n == 0) return 1; // Unsorted pair found (Equal values allowed) if (arr[n - 1] < arr[n - 2]) return 0; // Last pair was sorted // Keep on checking return sorted(arr, n - 1); } static void sieveOfEratosthenes(int n, Set<Integer> set) { // Create a boolean array "prime[0..n]" and // initialize all entries it as true. A value in // prime[i] will finally be false if i is Not a // prime, else true. 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] is not changed, then it is a // prime if (prime[p] == true) { // Update all multiples of p greater than or // equal to the square of it numbers which // are multiple of p and are less than p^2 // are already been marked. for (int i = p * p; i <= n; i += p) prime[i] = false; } } // Print all prime numbers for (int i = 2; i <= n; i++) { if (prime[i] == true) set.add(i); } } static boolean isPowerOfTwo(int n) { return (int)(Math.ceil((Math.log(n) / Math.log(2)))) == (int)(Math.floor(((Math.log(n) / Math.log(2))))); } static int countBits(int number) { // log function in base 2 // take only integer part return (int)(Math.log(number) / Math.log(2) + 1); } public static void swap(int ans[], int i, int j) { int temp=ans[i]; ans[i]=ans[j]; ans[j]=temp; } static int power(int x, int y, int p) { int res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p if (x == 0) return 0; // In case x is divisible by p; while (y > 0) { // If y is odd, multiply x with result if ((y & 1) != 0) res = (res * x) % p; // y must be even now y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
9350835f3ab847ef0b14762900b55bc0
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
import java.util.*; import java.io.*; import java.lang.*; import java.math.*; import static java.lang.Math.*; public class x { static FastInput scn; static PrintWriter out; final static int MOD = (int) (1e9 + 7); final static int MAX = Integer.MAX_VALUE; final static int MIN = Integer.MIN_VALUE; // MAIN public static void main(String[] args) throws IOException { scn = new FastInput(); out = new PrintWriter(System.out); int t = 1; t = scn.nextInt(); while (t-- > 0) { solve(); } out.flush(); } private static void solve() throws IOException { int n = scn.nextInt(); int[] a = scn.nextIntArray(n); int[] b = scn.nextIntArray(n); List<Integer> list = new ArrayList<>(); for(int i= 0;i<n;i++){ list.add(b[i]-a[i]); } Collections.sort(list); //out.println(list); // if(list.get(0) >= 0){ // out.println(1); // return; // } // if(list.get(n-1) <= 0){ // out.println(0); // return; // } // int i = n-1,j = 0,cnt=0; // while(i<j){ // if(list.get(j) >= abs(list.get(i))){ // cnt++; // i++; // j--; // } // else i++; // } int i = n-1,j=0,cnt=0; for(;;cnt++,i--,j++){ for(;j<n && list.get(j)<-list.get(i);)j++; if(j >= i)break; } out.println(cnt); } // CLASSES static class Pair implements Comparable<Pair> { int first, second; Pair(int first, int second) { this.first = first; this.second = second; } Pair(Pair o) { this.first = o.first; this.second = o.second; } public int compareTo(Pair o) { return this.first - o.first; } } // CHECK IF STRING IS NUMBER private static boolean isInteger(String s) { try { Integer.parseInt(s); } catch (NumberFormatException e) { return false; } catch (NullPointerException e) { return false; } return true; } private static boolean isLong(String s) { try { Long.parseLong(s); } catch (NumberFormatException e) { return false; } catch (NullPointerException e) { return false; } return true; } // FASTER SORT private static void fastSort(int[] arr) { int n = arr.length; List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) list.add(arr[i]); Collections.sort(list); for (int i = 0; i < n; i++) arr[i] = list.get(i); } private static void fastSort(char[] arr) { int n = arr.length; List<Character> list = new ArrayList<>(); for (int i = 0; i < n; i++) list.add(arr[i]); Collections.sort(list); for (int i = 0; i < n; i++) arr[i] = list.get(i); } private static void fastSortReverse(int[] arr) { int n = arr.length; List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) list.add(arr[i]); Collections.sort(list, Collections.reverseOrder()); for (int i = 0; i < n; i++) arr[i] = list.get(i); } private static void fastSort(long[] arr) { int n = arr.length; List<Long> list = new ArrayList<>(); for (int i = 0; i < n; i++) list.add(arr[i]); Collections.sort(list); for (int i = 0; i < n; i++) arr[i] = list.get(i); } private static void fastSortReverse(long[] arr) { int n = arr.length; List<Long> list = new ArrayList<>(); for (int i = 0; i < n; i++) list.add(arr[i]); Collections.sort(list, Collections.reverseOrder()); for (int i = 0; i < n; i++) arr[i] = list.get(i); } // QUICK MATHS private static void swap(int[] a,int i,int j){ int t = a[i]; a[i] = a[j]; a[j] = t; } private static void swap(long[] a,int i,int j){ long t = a[i]; a[i] = a[j]; a[j] = t; } private static void swap(char[] a,int i,int j){ char t = a[i]; a[i] = a[j]; a[j] = t; } private static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } private static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } private static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } private static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } private static long power(long a, long b) { if (b == 0) return 1L; long ans = power(a, b / 2); ans *= ans; if ((b & 1) == 1) ans *= a; return ans; } private static int mod_power(int a, int b) { if (b == 0) return 1; int temp = mod_power(a, b / 2); temp %= MOD; temp = (int) ((1L * temp * temp) % MOD); if ((b & 1) == 1) temp = (int) ((1L * temp * a) % MOD); return temp; } private static int multiply(int a, int b) { return (int) ((((1L * a) % MOD) * ((1L * b) % MOD)) % MOD); } private static boolean isPrime(int n) { for (int i = 2; i * i <= n; i++) if (n % i == 0) return false; return true; } private static boolean isPrime(long n) { for (long i = 2; i * i <= n; i++) if (n % i == 0) return false; return true; } // STRING FUNCTIONS private static boolean isPalindrome(String str) { int i = 0, j = str.length() - 1; while (i < j) if (str.charAt(i++) != str.charAt(j--)) return false; return true; } private static String reverseString(String str) { StringBuilder sb = new StringBuilder(str); return sb.reverse().toString(); } private static String sortString(String str) { int[] arr = new int[256]; for (char ch : str.toCharArray()) arr[ch]++; StringBuilder sb = new StringBuilder(); for (int i = 0; i < 256; i++) while (arr[i]-- > 0) sb.append((char) i); return sb.toString(); } // LONGEST INCREASING AND NON-DECREASING SUBSEQUENCE private static int LIS(int arr[]) { int n = arr.length; List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) { int idx = find1(list, arr[i]); if (idx < list.size()) { list.set(idx, arr[i]); } else { list.add(arr[i]); } } return list.size(); } private static int find1(List<Integer> list, int val) { int ret = list.size(), i = 0, j = list.size() - 1; while (i <= j) { int mid = (i + j) / 2; if (list.get(mid) >= val) { ret = mid; j = mid - 1; } else { i = mid + 1; } } return ret; } private static int LNDS(int[] arr) { int n = arr.length; List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) { int idx = find2(list, arr[i]); if (idx < list.size()) { list.set(idx, arr[i]); } else { list.add(arr[i]); } } return list.size(); } private static int find2(List<Integer> list, int val) { int ret = list.size(), i = 0, j = list.size() - 1; while (i <= j) { int mid = (i + j) / 2; if (list.get(mid) <= val) { i = mid + 1; } else { ret = mid; j = mid - 1; } } return ret; } // DISJOINT SET UNION private static int find(int x, int[] parent) { if (parent[x] == x) { return x; } parent[x] = find(parent[x], parent); return parent[x]; } private static boolean union(int x, int y, int[] parent, int[] rank) { int lx = find(x, parent), ly = find(y, parent); if (lx == ly) { return true; } else if (rank[lx] > rank[ly]) { parent[ly] = lx; } else if (rank[lx] < rank[ly]) { parent[lx] = ly; } else { parent[lx] = ly; rank[ly]++; } return false; } // TRIE static class Trie { class Node { Node[] children; boolean isEnd; Node() { children = new Node[26]; } } Node root; Trie() { root = new Node(); } public void insert(String word) { Node curr = root; for (char ch : word.toCharArray()) { if (curr.children[ch - 'a'] == null) { curr.children[ch - 'a'] = new Node(); } curr = curr.children[ch - 'a']; } curr.isEnd = true; } public boolean find(String word) { Node curr = root; for (char ch : word.toCharArray()) { if (curr.children[ch - 'a'] == null) { return false; } curr = curr.children[ch - 'a']; } return curr.isEnd; } } // INPUT static class FastInput { BufferedReader br; StringTokenizer st; FastInput() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(nextLine()); return st.nextToken(); } long nextLong() throws IOException { return Long.parseLong(next()); } int nextInt() throws IOException { return Integer.parseInt(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } char nextCharacter() throws IOException { return next().charAt(0); } String nextLine() throws IOException { return br.readLine().trim(); } int[] nextIntArray(int n) throws IOException { int[] arr = new int[n]; for (int i = 0; i < n; i++) arr[i] = nextInt(); return arr; } int[][] next2DIntArray(int n, int m) throws IOException { int[][] arr = new int[n][m]; for (int i = 0; i < n; i++) arr[i] = nextIntArray(m); return arr; } long[] nextLongArray(int n) throws IOException { long[] arr = new long[n]; for (int i = 0; i < n; i++) arr[i] = nextLong(); return arr; } long[][] next2DLongArray(int n, int m) throws IOException { long[][] arr = new long[n][m]; for (int i = 0; i < n; i++) arr[i] = nextLongArray(m); return arr; } List<Integer> nextIntList(int n) throws IOException { List<Integer> list = new ArrayList<>(); for (int i = 0; i < n; i++) list.add(nextInt()); return list; } List<Long> nextLongList(int n) throws IOException { List<Long> list = new ArrayList<>(); for (int i = 0; i < n; i++) list.add(nextLong()); return list; } char[] nextCharArray(int n) throws IOException { return next().toCharArray(); } char[][] next2DCharArray(int n, int m) throws IOException { char[][] mat = new char[n][m]; for (int i = 0; i < n; i++) mat[i] = nextCharArray(m); return mat; } } // OUTPUT private static void printIntList(List<Integer> list) { for (int i = 0; i < list.size(); i++) out.print(list.get(i) + " "); out.println(" "); } private static void printLongList(List<Long> list) { for (int i = 0; i < list.size(); i++) out.print(list.get(i) + " "); out.println(" "); } private static void printIntArray(int[] arr) { for (int i = 0; i < arr.length; i++) out.print(arr[i] + " "); out.println(" "); } private static void print2DIntArray(int[][] arr) { for (int i = 0; i < arr.length; i++) printIntArray(arr[i]); } private static void printLongArray(long[] arr) { for (int i = 0; i < arr.length; i++) out.print(arr[i] + " "); out.println(" "); } private static void print2DLongArray(long[][] arr) { for (int i = 0; i < arr.length; i++) printLongArray(arr[i]); } }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
2ff4d2269930392e6eae7006bd6c222a
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
// LARGEST SQUARE // package com.company /* * @author :: Yuvraj Singh * CS UNDERGRAD AT IT GGV BILASPUR */ import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.*; import static java.lang.Math.*; import static java.lang.System.out; public class Main { // Solution here void solve() { int n = in.nextInt(); long[] x = longArr(n); long[] y = longArr(n); for(int i=0; i<n;i++) { x[i] = y[i] - x[i]; } sort(x); long ans = 0; int i=n-1,j=0; for(;;i--,j++) { ans++; for(;j<n && -x[i] > x[j];) j++; if(j>=i) break; } sb.append(ans-1).append("\n"); } void start(){ sb= new StringBuffer(); int t= in.nextInt(); for(int i=1;i<=t;i++) { solve(); } out.print(sb); } // Starter Code FastReader in; StringBuffer sb; public static void main(String[] args) { new Main().run(); } void run(){ in= new FastReader(); start(); } long nCr(int n, int r) { if (r > n) return 0; long m = 1000000007; long[] inv = new long[r + 1]; inv[0] = 1; if(r+1>=2) inv[1] = 1; for (int i = 2; i <= r; i++) { inv[i] = m - (m / i) * inv[(int) (m % i)] % m; } long ans = 1; for (int i = 2; i <= r; i++) { ans = (int) (((ans % m) * (inv[i] % m)) % m); } for (int i = n; i >= (n - r + 1); i--) { ans = (int) (((ans % m) * (i % m)) % m); } return ans; } int lower_bound(ArrayList<Integer> a, int x) { // x is the target value or key int l=-1,r=a.size(); while(l+1<r) { int m=(l+r)>>>1; if(a.get(m)>=x) r=m; else l=m; } return r; } void bubbleSort(int[] arr){ int n= arr.length; for(int i=n-1; i>0; i--){ for(int j=0; j<i; j++){ if(arr[i] < arr[j]){ swap(arr, i, j); } } } } void swap(int[] arr, int i, int j){ int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } long numberOfWays(long n, long k) { // Base Cases if (n == 0) return 1; if (k == 0) return 1; if (n >= (int)Math.pow(2, k)) { int curr_val = (int)Math.pow(2, k); return numberOfWays(n - curr_val, k) + numberOfWays(n, k - 1); } else return numberOfWays(n, k - 1); } boolean palindrome(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; } int call(int[] A, int N, int K) { int i = 0, j = 0, sum = 0; int maxLen = Integer.MIN_VALUE; while (j < N) { sum += A[j]; if (sum < K) { j++; } else if (sum == K) { maxLen = Math.max(maxLen, j-i+1); j++; } else if (sum > K) { while (sum > K) { sum -= A[i]; i++; } if(sum == K){ maxLen = Math.max(maxLen, j-i+1); } j++; } } return maxLen; } int largestNum(int n) { int num = 0; // Iterate through all possible values for (int i = 0; i <= 32; i++) { // Multiply the number by 2 i times int x = (1 << i); if ((x - 1) >= n) num = (1 << i) - 1; else break; } // Return the final result return num; } static boolean isPrime(int n) { // Corner case if (n <= 1) return false; // Check from 2 to n-1 for (int i = 2; i <= sqrt(n); i++) if (n % i == 0) return false; return true; } // Useful Functions // void swap(int[] arr, int i , int j) { // int tmp = arr[i]; // i = j; // j = tmp; // } int call(int i,int j, int[][] mat, int[][] dp){ int m= mat.length; int n= mat[0].length; if(i>=m || j>=n){ return Integer.MIN_VALUE; } if(i==m-1 && j==n-1){ return mat[i][j]; } if(dp[i][j] != -1){ return dp[i][j]; } return dp[i][j] = max(call(i+1, j, mat, dp), call(i, j+1, mat, dp)) + mat[i][j]; } int util(int i,int j, int[][] mat, int[][] dp){ int m= mat.length; int n= mat[0].length; if(i>=m || j>=n){ return Integer.MAX_VALUE; } if(i==m-1 && j==n-1){ return mat[i][j]; } if(dp[i][j] != -1){ return dp[i][j]; } return dp[i][j] = min(util(i+1, j, mat, dp), util(i, j+1, mat, dp)) + mat[i][j]; } long power(long x, long y, long p) { long res = 1; x = x % p; while (y > 0) { if (y % 2 == 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int lower_bound(long[] a, long x) { // x is the target value or key int l=-1,r=a.length; while(l+1<r) { int m=(l+r)>>>1; if(a[m]>=x) r=m; else l=m; } return r; } int upper_bound(ArrayList<Integer> arr, int key) { int i=0, j=arr.size()-1; if(j==-1){ return 0; } if (arr.get(j)<=key) return j+1; if(arr.get(i)>key) return i; while (i<j){ int mid= (i+j)/2; if(arr.get(mid)<=key){ i= mid+1; }else{ j=mid; } } return i; } void sort(long[] A){ int n = A.length; Random rnd = new Random(); for(int i=0; i<n; ++i){ long tmp = A[i]; int randomPos = i + rnd.nextInt(n-i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } int[] intArr(int n){ int[] res= new int[n]; for(int i=0;i<n;i++){ res[i]= in.nextInt(); } return res; } long[] longArr(int n){ long[] res= new long[n]; for(int i=0;i<n;i++){ res[i]= in.nextLong(); } return res; } // // sieve of eratosthenes code for precomputing whether numbers are prime or not up to MAX_VALUE long MAX= 100000000; int[] precomp; void sieve(){ long n= MAX; precomp = new int[(int) (n+1)]; boolean[] prime = new boolean[(int) (n+1)]; for(int i=0;i<=n;i++) prime[i] = true; for(long p = 2; p*p <=n; p++) { // If prime[p] is not changed, then it is a prime if(prime[(int) p]) { // Update all multiples of p for(long i = p*p; i <= n; i += p) prime[(int) i] = false; } } // Print all prime numbers for(long i = 2; i <= n; i++) { if(prime[(int) i]) precomp[(int) i]= 1; } } long REVERSE(long N) { // code here long rev=0; long org= N; while (N!=0){ long d= N%10; rev = rev*10 +d; N /= 10; } return rev; } long sumOfDigits(String n){ long sum= 0; for (char c: n.toCharArray()){ sum += Integer.parseInt(String.valueOf(c)); } return sum; } long[] revArray(long[] arr) { int n= arr.length; int i=0, j=n-1; while (i<j){ long temp= arr[i]; arr[i]= arr[j]; arr[j]= temp; i++; j--; } return arr; } long gcd(long a, long b){ if (b==0) return a; return gcd(b, a%b); } long lcm(long a,long b){ return (a*b)/gcd(a,b); } static class Pair implements Comparable<Pair>{ long first; long second; Pair(long x, long y){ this.first=x; this.second=y; } @Override public int compareTo(Pair o) { return 0; } } // static class Compare { // static void compare(ArrayList<Pair> arr, int n) { // arr.sort(new Comparator<Pair>() { // @Override // public int compare(Pair p1, Pair p2) { // return (int) (p2.first - p1.first); // } // }); // } // } public 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 (Exception e){ e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } float nextFloat(){ return Float.parseFloat(next()); } String nextLine(){ String str=""; try{ str=br.readLine(); }catch (Exception e){ e.printStackTrace(); } return str; } } }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
ea451d236f1d4ff94e1436ef85eb2810
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
import java.io.*; import java.util.*; public class Codeforces{ static int mod = (int) (1e9 + 7); static PrintWriter out = new PrintWriter(System.out); static void solve() { int n=i(); long[]x=new long[n]; long[]y=new long[n]; for(int i=0;i<n;i++){ x[i]=l(); } for(int i=0;i<n;i++){ y[i]=l(); } List<Long>li=new ArrayList<>(); for(int i=0;i<n;i++){ li.add(x[i]-y[i]); } Collections.sort(li); // out.println(li); int i=0; int j=li.size()-1; int ans=0; while(i<j){ if(li.get(i)+li.get(j)<=0){ ans++; i++; j--; }else{ j--; } } out.println(ans); } public static void main(String[] args) { int test = i(); while (test-- > 0) { solve(); } out.flush(); out.close(); } // ------> swap(long[]arr,int idx1,int idx2)<---- swap int // ----->segmentTree--> segTree as class // ----->lazy_Seg_tree --> lazy_Seg_tree as class // -----> Trie --->Trie as class // ----->fenwick_Tree ---> fenwick_Tree // -----> POWER ---> long power(long x, long y) <---- // -----> LCM ---> long lcm(long x, long y) <---- // -----> GCD ---> long gcd(long x, long y) <---- // -----> SIEVE --> ArrayList<Integer> sieve(int N) <----- // -----> NCR ---> long ncr(int n, int r) <---- // -----> BINARY_SEARCH ---> int binary_Search(long[]arr,long x) <---- // -----> (SORTING OF LONG, CHAR,INT) -->long[] sortLong(long[] a2)<-- // ----> DFS ---> void dfs(ArrayList<ArrayList<Integer>>edges,int child,int parent)<--- // ---> NODETOROOT --> ArrayList<Integer> node2Root(ArrayList<ArrayList<Integer>>edges,int child,int parent,int tofind) <-- // ---> LEVELS_TREE -->levels_Trees(ArrayList<HashSet<Integer>> edges, int child, int parent,int[]level,int currLevel) <-- // ---> K_THPARENT --> int k_thparent(int node,int[][]parent,int k) <--- // ---> TWOPOWERITHPARENTFILL --> void twoPowerIthParentFill(int[][]parent) <--- // -----> (INPUT OF INT,LONG ,STRING) -> int i() long l() String s()<- // tempstart 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 Int() { 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 String() { 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 boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return String(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static InputReader in = new InputReader(System.in); public static int i() { return in.Int(); } public static long l() { String s = in.String(); return Long.parseLong(s); } public static String s() { return in.String(); } public static int compareChar(char a, char b) { return Character.compare(a, b); } public static int compareInt(int a, int b) { return Integer.compare(a, b); } public static int compareLong(long a, long b) { return Long.compare(a, b); } public static boolean compareString(String a, String b){ return a.equals(b); } public static boolean compareStringBuilder(StringBuilder a, StringBuilder b) { return a.equals(b); } }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
ed1e6739dcb7ceccd6bb527804b37f9a
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
import java.util.*; public class b implements Runnable{ static ContestScanner in = new ContestScanner(); static ContestPrinter out = new ContestPrinter(); public static void main(String[] args) { new Thread(null, new b(), "main", 1<<28).start(); } static class pair implements Comparable<pair>{ public char val; public int index; public pair(char value , int idx){ this.val = value; this.index = idx; } public pair getVal() { return this; } @Override public int compareTo(b.pair o) { // TODO Auto-generated method stub if (o.val == this.val) { return (o.index > this.index ? 1 : -1); } return (this.val < o.val ? 1 : -1); } } public void run() { int tests = in.nextInt(); for (int t = 0; t < tests; t++) { int n = in.nextInt(); int[] arr1 = in.nextIntArray(n) , arr2 = in.nextIntArray(n); ArrayList<Integer> diff1 = new ArrayList<>() , diff2 = new ArrayList<>(); for (int i = 0 ; i < n ; i++) { // out.print(arr2[i] - arr1[i] + " "); if (arr2[i] - arr1[i] >= 0) { diff1.add(arr2[i] - arr1[i]); // out.print("hehe"); // out.println(); } else diff2.add(arr2[i] - arr1[i]); } Collections.sort(diff1); Collections.sort(diff2); int idx2 = 0 , idx1 = diff1.size()-1 , ans = 0; // out.print(diff1.size() + " " + diff2.size()); for (int i = 0 ; idx1 >= 0 ; i++) { if (idx2 == diff2.size())break; while(idx2 < diff2.size() && diff1.get(idx1) + diff2.get(idx2) < 0)idx2++; if (idx2 == diff2.size())break; // out.print(idx1 + " " + idx2 + " "); idx1-- ;idx2++; ans++; } // out.println(idx1); ans += (idx1+1)/2; // int ans = 0; out.println(ans); } out.close(); } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static class ContestScanner { private final java.io.InputStream in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private static final long LONG_MAX_TENTHS = 922337203685477580L; private static final int LONG_MAX_LAST_DIGIT = 7; private static final int LONG_MIN_LAST_DIGIT = 8; public ContestScanner(java.io.InputStream in){ this.in = in; } public ContestScanner(java.io.File file) throws java.io.FileNotFoundException { this(new java.io.BufferedInputStream(new java.io.FileInputStream(file))); } public ContestScanner(){ this(System.in); } private boolean hasNextByte() { if (ptr < buflen) { return true; }else{ ptr = 0; try { buflen = in.read(buffer); } catch (java.io.IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1; } private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126; } public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte(); } public String next() { if (!hasNext()) throw new java.util.NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while(isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new java.util.NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while (true) { if ('0' <= b && b <= '9') { int digit = b - '0'; if (n >= LONG_MAX_TENTHS) { if (n == LONG_MAX_TENTHS) { if (minus) { if (digit <= LONG_MIN_LAST_DIGIT) { n = -n * 10 - digit; b = readByte(); if (!isPrintableChar(b)) { return n; } else if (b < '0' || '9' < b) { throw new NumberFormatException( String.format("%d%s... is not number", n, Character.toString(b)) ); } } } else { if (digit <= LONG_MAX_LAST_DIGIT) { n = n * 10 + digit; b = readByte(); if (!isPrintableChar(b)) { return n; } else if (b < '0' || '9' < b) { throw new NumberFormatException( String.format("%d%s... is not number", n, Character.toString(b)) ); } } } } throw new ArithmeticException( String.format("%s%d%d... overflows long.", minus ? "-" : "", n, digit) ); } n = n * 10 + digit; }else if(b == -1 || !isPrintableChar(b)){ return minus ? -n : n; }else{ throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next()); } public long[] nextLongArray(int length){ long[] array = new long[length]; for(int i=0; i<length; i++) array[i] = this.nextLong(); return array; } public long[] nextLongArray(int length, java.util.function.LongUnaryOperator map){ long[] array = new long[length]; for(int i=0; i<length; i++) array[i] = map.applyAsLong(this.nextLong()); return array; } public int[] nextIntArray(int length){ int[] array = new int[length]; for(int i=0; i<length; i++) array[i] = this.nextInt(); return array; } public int[] nextIntArray(int length, java.util.function.IntUnaryOperator map){ int[] array = new int[length]; for(int i=0; i<length; i++) array[i] = map.applyAsInt(this.nextInt()); return array; } public double[] nextDoubleArray(int length){ double[] array = new double[length]; for(int i=0; i<length; i++) array[i] = this.nextDouble(); return array; } public double[] nextDoubleArray(int length, java.util.function.DoubleUnaryOperator map){ double[] array = new double[length]; for(int i=0; i<length; i++) array[i] = map.applyAsDouble(this.nextDouble()); return array; } public long[][] nextLongMatrix(int height, int width){ long[][] mat = new long[height][width]; for(int h=0; h<height; h++) for(int w=0; w<width; w++){ mat[h][w] = this.nextLong(); } return mat; } public int[][] nextIntMatrix(int height, int width){ int[][] mat = new int[height][width]; for(int h=0; h<height; h++) for(int w=0; w<width; w++){ mat[h][w] = this.nextInt(); } return mat; } public double[][] nextDoubleMatrix(int height, int width){ double[][] mat = new double[height][width]; for(int h=0; h<height; h++) for(int w=0; w<width; w++){ mat[h][w] = this.nextDouble(); } return mat; } public char[][] nextCharMatrix(int height, int width){ char[][] mat = new char[height][width]; for(int h=0; h<height; h++){ String s = this.next(); for(int w=0; w<width; w++){ mat[h][w] = s.charAt(w); } } return mat; } } static class ContestPrinter extends java.io.PrintWriter{ public ContestPrinter(java.io.PrintStream stream){ super(stream); } public ContestPrinter(java.io.File file) throws java.io.FileNotFoundException{ super(new java.io.PrintStream(file)); } public ContestPrinter(){ super(System.out); } private static String dtos(double x, int n) { StringBuilder sb = new StringBuilder(); if(x < 0){ sb.append('-'); x = -x; } x += Math.pow(10, -n)/2; sb.append((long)x); sb.append("."); x -= (long)x; for(int i = 0;i < n;i++){ x *= 10; sb.append((int)x); x -= (int)x; } return sb.toString(); } @Override public void print(float f){ super.print(dtos(f, 20)); } @Override public void println(float f){ super.println(dtos(f, 20)); } @Override public void print(double d){ super.print(dtos(d, 20)); } @Override public void println(double d){ super.println(dtos(d, 20)); } public void printArray(int[] array, String separator){ int n = array.length; if(n==0){ super.println(); return; } for(int i=0; i<n-1; i++){ super.print(array[i]); super.print(separator); } super.println(array[n-1]); } public void printArray(int[] array){ this.printArray(array, " "); } public void printArray(int[] array, String separator, java.util.function.IntUnaryOperator map){ int n = array.length; if(n==0){ super.println(); return; } for(int i=0; i<n-1; i++){ super.print(map.applyAsInt(array[i])); super.print(separator); } super.println(map.applyAsInt(array[n-1])); } public void printArray(int[] array, java.util.function.IntUnaryOperator map){ this.printArray(array, " ", map); } public void printArray(long[] array, String separator){ int n = array.length; if(n==0){ super.println(); return; } for(int i=0; i<n-1; i++){ super.print(array[i]); super.print(separator); } super.println(array[n-1]); } public void printArray(long[] array){ this.printArray(array, " "); } public void printArray(long[] array, String separator, java.util.function.LongUnaryOperator map){ int n = array.length; if(n==0){ super.println(); return; } for(int i=0; i<n-1; i++){ super.print(map.applyAsLong(array[i])); super.print(separator); } super.println(map.applyAsLong(array[n-1])); } public void printArray(long[] array, java.util.function.LongUnaryOperator map){ this.printArray(array, " ", map); } public <T> void printArray(T[] array, String separator){ int n = array.length; if(n==0){ super.println(); return; } for(int i=0; i<n-1; i++){ super.print(array[i]); super.print(separator); } super.println(array[n-1]); } public <T> void printArray(T[] array){ this.printArray(array, " "); } public <T> void printArray(T[] array, String separator, java.util.function.UnaryOperator<T> map){ int n = array.length; if(n==0){ super.println(); return; } for(int i=0; i<n-1; i++){ super.print(map.apply(array[i])); super.print(separator); } super.println(map.apply(array[n-1])); } public <T> void printArray(T[] array, java.util.function.UnaryOperator<T> map){ this.printArray(array, " ", map); } } }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
994f26a740dd37a89a7515a558254281
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
import java.util.*; public class MyClass { public static void main(String args[]) { Scanner sc = new Scanner(System.in); // System.out.println((int)('s'-'c')); int t = sc.nextInt(); // sc.nextLine(); while(t>0){ t--; sc.nextLine(); int n = sc.nextInt(); sc.nextLine(); int [] x = new int [n]; for(int i=0;i<n;i++){ x[i] = sc.nextInt(); } sc.nextLine(); for(int i=0;i<n;i++){ int y = sc.nextInt(); x[i] = y-x[i]; } Arrays.sort(x); int j =0, ans = 0; for(int i = n-1; i >=0; i--){ while(j < i && x[i] + x[j] < 0) j++; if(j >= i) break; ans++; j++; } System.out.println(ans); } } }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
84b7724e2e96c5d2caa1772c4f7f4424
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
import java.util.Collections; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Scanner; public class CF820D { public static void main(String[] args) { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); 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(); for (int i = 0; i < n; i++) y[i] = sc.nextLong(); ArrayList<Long> diff = new ArrayList<>(); for (int i = 0; i < n; i++) diff.add(y[i] - x[i]); Collections.sort(diff); int l = 0, ans = 0; for (int r = n - 1; r >= 0; r--) { while (l < r && diff.get(l) + diff.get(r) < 0) l++; if (l >= r) break; ans++; l++; } out.println(ans); } sc.close(); out.close(); } }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
beb611cfbe207fa87c94261502e5abaa
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class D1729 { public static int recursiveSolution(int[]diff,int i,int j){ if(i==j||j>i) return 0; if(diff[i]+diff[j]>=0){ return 1+recursiveSolution(diff,i-1,j+1); }else return recursiveSolution(diff,i,j+1); } public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); while(t-->0){ int n = s.nextInt(); int [] e = new int[n]; int [] b = new int[n]; int [] diff = new int[n]; for(int i=0;i<e.length;i++){ e[i] = s.nextInt(); } for(int i=0;i<e.length;i++){ b[i] = s.nextInt(); } for(int i=0;i<n;i++){ diff[i] = b[i]-e[i]; } Arrays.sort(diff); int days = 0; for(int i=0,j=diff.length-1;i<j&&j>i;){ if(diff[i]+diff[j]>=0){ days++;i++;j--; }else{ i++; } } //System.out.println(days); System.out.println(recursiveSolution(diff,n-1,0)); } } }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
a3340bd7207b7f6a746debd56c3ab943
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class D1729 { public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); while(t-->0){ int n = s.nextInt(); int [] e = new int[n]; int [] b = new int[n]; int [] diff = new int[n]; for(int i=0;i<e.length;i++){ e[i] = s.nextInt(); } for(int i=0;i<e.length;i++){ b[i] = s.nextInt(); } for(int i=0;i<n;i++){ diff[i] = b[i]-e[i]; } Arrays.sort(diff); int days = 0; for(int i=0,j=diff.length-1;i<j&&j>i;){ if(diff[i]+diff[j]>=0){ days++;i++;j--; }else{ i++; } } System.out.println(days); } } }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
7aa668dbb65abc2c4d8ca180a7eab722
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); int[] x = new int[n]; int[] y = new int[n]; for(int i=0; i<n; i++) { x[i] = sc.nextInt(); } for(int i=0; i<n; i++) { y[i] = sc.nextInt(); } ArrayList<Integer> diff = new ArrayList<>(); for(int i=0; i<n; i++) { diff.add(y[i]-x[i]); } Collections.sort(diff); Collections.reverse(diff); int i = 0; int j = diff.size()-1; int ans = 0; while(i<j) { if(diff.get(i)+diff.get(j) < 0) { while(i<j && diff.get(i)+diff.get(j) < 0) j--; } if(i<j && diff.get(i)+diff.get(j) >= 0) { ans++; i++; j--; } } System.out.println(ans); } } }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
22654353dafe47add59cbc1bb429a5ea
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
import java.util.*; import java.util.function.Function; public class Main { public static void main(String[] args) { Scanner scr = new Scanner(System.in); int t = scr.nextInt(); while(t > 0) { int n = scr.nextInt(); int[] x = new int[n]; int[] y = new int[n]; for(int i = 0;i < n;i++) x[i] = scr.nextInt(); for(int i = 0;i < n;i++) y[i] = scr.nextInt(); int[] s = new int[n]; for(int i = 0 ;i < n;i++) s[i] = y[i] - x[i]; Arrays.sort(s); int ans = 0; int l = 0,r = n-1; while(l < r) { if(s[r] + s[l] >= 0) { ans++; r--; l++; }else { l++; } } // for(int i = 0;i < n;i++) // System.out.print(xy[i][0] + " "); // System.out.println(); // for(int i = 0;i < n;i++) // System.out.print(xy[i][1] + " "); System.out.println(ans); t--; } if(scr != null)scr.close(); } }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
d2a6c17d79c82fa0d9c4d8337b03e990
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
import java.io.*; import java.util.*; public class new1{ static int mod = 998244353; public static void main(String[] args) throws IOException{ BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out)); FastReader s = new FastReader(); int t = s.nextInt(); for(int z = 1; z <= t; z++) { int n = s.nextInt(); int[] arr = new int[n]; for(int i = 0; i < n; i++) arr[i] = s.nextInt(); ArrayList<Integer> pos = new ArrayList<Integer>(); ArrayList<Integer> neg = new ArrayList<Integer>(); for(int i = 0; i < n; i++) { int val = s.nextInt() - arr[i]; if(val >= 0) pos.add(val); else neg.add(val); } pos.sort(null); neg.sort(null); // System.out.println(neg.toString()); // System.out.println(pos.toString()); int j = pos.size() - 1; int x = 0; for(int i = 0; i < neg.size(); i++) { if(j < 0) break; if(-neg.get(i) <= pos.get(j)) { x++; j--; } } int ans = x + (pos.size() - x) / 2; System.out.println(ans); } output.flush(); } } 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(); } public 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\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
5046be282fd72d039d9b2910927db285
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
/****************************************************************************** Welcome to GDB Online. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. Code, Compile, Run and Debug online from anywhere in world. *******************************************************************************/ import java.util.*; public class Codeforces { public static int minDays(int n, int[] x, int[] y){ Friend[] arr = new Friend[n]; for(int i=0;i<n;i++) arr[i]=new Friend(x[i],y[i]); Arrays.sort(arr,(a,b)->{ if(a.y-a.x==b.y-b.x) return a.y-b.y; return (a.y-a.x)-(b.y-b.x); }); int i=0,j=n-1,count=0; while(i<j){ while(i<n && arr[i].x+arr[j].x>arr[i].y+arr[j].y) i++; if(i<j) count++; i++; j--; } return count; } public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); for(int k=0;k<t;k++){ int n = scan.nextInt(); int[] x = new int[n]; int[] y = new int[n]; for(int i=0;i<n;i++) x[i]=scan.nextInt(); for(int i=0;i<n;i++) y[i]=scan.nextInt(); System.out.println(minDays(n,x,y)); } } } class Friend{ int x,y; Friend(int a, int b){ x=a; y=b; } }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
6d7d270727a0297c625b221b311d12ca
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
import javax.crypto.spec.PSource; import java.math.MathContext; import java.util.*; public class Solution { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int[] array2 = new int[n]; int[] array1 = new int[n]; for (int i = 0; i < n; i++) { array1[i] = sc.nextInt(); } for (int i = 0; i < n; i++) { array2[i] = sc.nextInt(); } int[] result = new int[n]; for(int i = 0; i < n; i++){ result[i] = array2[i] - array1[i]; } Arrays.sort(result); int i = 0; int j = n-1; int count = 0; while(j > i){ if(result[j] + result[i] >= 0){ count++; i++; j--; }else{ i++; } } System.out.println(count); } } }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
c5e2e3b28fce91ea37a328682be6618d
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
//package MyPackage; import java.util.*; import java.io.*; public class D{ static class FastReader{ BufferedReader br; StringTokenizer st; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || !st.hasMoreTokens()){ try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str=""; try { str=br.readLine().trim(); } catch (Exception e) { e.printStackTrace(); } return str; } } static class FastWriter { private final BufferedWriter bw; public FastWriter() { this.bw = new BufferedWriter(new OutputStreamWriter(System.out)); } public void print(Object object) throws IOException { bw.append("" + object); } public void println(Object object) throws IOException { print(object); bw.append("\n"); } public void close() throws IOException { bw.close(); } } static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } static long lcm(long a, long b) { return (a / gcd(a, b)) * b; } public static void main(String[] args) { try { FastReader in=new FastReader(); FastWriter out = new FastWriter(); StringBuilder sb = new StringBuilder(); int t = in.nextInt(); while(t-- > 0) { int n = in.nextInt(); int x[] = new int[n]; int y[] = new int[n]; List<Integer> al = new ArrayList<>(); for(int i = 0; i < n; i++) x[i] = in.nextInt(); for(int i = 0; i < n; i++) { y[i] = in.nextInt(); al.add(y[i] - x[i]); } Collections.sort(al); int i = 0, j = n - 1, ans = 0; while(i < j) { if(al.get(i) + al.get(j) < 0) i++; else { ans++; i++; j--; } } sb.append(ans + "\n"); } out.println(sb); out.close(); } catch (Exception e) { System.out.println(e); return; } } }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output
PASSED
e1237a7edb1d6bbd3741413940823c6d
train_110.jsonl
1662993300
A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then: first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group. friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class Q1div3 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int i=0;i<t;i++){ int n = sc.nextInt(); int []x = new int[n]; int []y = new int[n]; int []val = new int[n]; for(int j=0;j<n;j++){ x[j] = sc.nextInt(); } for(int j=0;j<n;j++){ y[j] = sc.nextInt(); } for(int j=0;j<n;j++){ val[j] = y[j] - x[j]; } Arrays.sort(val); int p = 0; int m = val.length-1; int c=0; while(p<m){ if(val[p]+val[m]<0){ p++; }else{ c+=1; p++; m--; } } System.out.println(c); } } }
Java
["6\n\n6\n\n8 3 9 2 4 5\n\n5 3 1 4 5 10\n\n4\n\n1 2 3 4\n\n1 1 2 2\n\n3\n\n2 3 7\n\n1 3 10\n\n6\n\n2 3 6 9 5 7\n\n3 2 7 10 6 10\n\n6\n\n5 4 2 1 8 100\n\n1 1 1 1 1 200\n\n6\n\n1 4 1 2 4 2\n\n1 3 3 2 3 4"]
2 seconds
["2\n0\n1\n3\n1\n3"]
NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.
Java 11
standard input
[ "greedy", "sortings", "two pointers" ]
7c8884b72dcc3c51e0696eec8d6aa8ef
The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.
1,200
For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.
standard output