exec_outcome
stringclasses
1 value
code_uid
stringlengths
32
32
file_name
stringclasses
111 values
prob_desc_created_at
stringlengths
10
10
prob_desc_description
stringlengths
63
3.8k
prob_desc_memory_limit
stringclasses
18 values
source_code
stringlengths
117
65.5k
lang_cluster
stringclasses
1 value
prob_desc_sample_inputs
stringlengths
2
802
prob_desc_time_limit
stringclasses
27 values
prob_desc_sample_outputs
stringlengths
2
796
prob_desc_notes
stringlengths
4
3k
lang
stringclasses
5 values
prob_desc_input_from
stringclasses
3 values
tags
listlengths
0
11
src_uid
stringlengths
32
32
prob_desc_input_spec
stringlengths
28
2.37k
difficulty
int64
-1
3.5k
prob_desc_output_spec
stringlengths
17
1.47k
prob_desc_output_to
stringclasses
3 values
hidden_unit_tests
stringclasses
1 value
PASSED
7baf91380ab85a645c05ec9f6e7265cb
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.io.*; import java.lang.*; import java.util.*; public class solution { public static void main (String[] args){ int t=sc.nextInt(); while(t--!=0) { int n=sc.nextInt();long b=sc.nextLong();long x=sc.nextLong();long y=sc.nextLong(); long a[]=new long[n+1];long sum=0; if(x>=y) { ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
42b26ca08d815890162fa46298db9caf
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; import java.io.*; public class B1657 { public static void main(String[] args) throws IOException { BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); int T = Integer.parseInt(r.readLine()); for(int i = 0; i < T; i++) { StringToke...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
9217a71fa10029b790e117756f9443a5
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args)throws IOException { Scanner in = new Scanner(System.in); int t = in.nextInt(); while(t-- > 0) { int n = in.nextInt(),B = in.nextInt(),x = in.nextInt(),y = in.nextInt(); ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
19926e3b67a1817f2befd17a3ef67702
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; public class Solution{ public static void main(String[] args){ Scanner scn = new Scanner(System.in); int t = scn.nextInt(); while(t-->0){ int n = scn.nextInt(); int b = scn.nextInt(); int x = scn.nextInt(); int y...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
03e5e0eb02008ca1e30d4d29f479ef31
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
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; /* cF B */ public class Main { pu...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
bf28f498515eef784f469a4bb712b4e2
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; public class GFG { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { //int n, B, x, y; int n=sc.nextInt(); int B=sc.nextInt(); int x=sc.nextInt(); int y=sc.nextIn...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
99cf66964779aa643a032981c86b08a5
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.Scanner; public class template { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for (int i = 1; i <= n; i++) { int l = sc.nextInt(); long max = sc.nextLong(); ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
8fa0a74ad559ce42a4509a1583772bb9
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; public class Cf { static Scanner sc = new Scanner(System.in); public static void main(String[] args ) { int t = sc.nextInt(); while(t-- > 0) solve(); } public static void solve() { int n = sc.nextInt(); long b = sc.nextInt(); ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
f395fd4c52aa4594a5a4fb9fccbdbcf0
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class XYsequence { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for (int i = 0; i < t; i++) { int n = in.nextInt(); int b = in.nextInt(); int x = in.nextInt...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
2135d9ad073cf6571580721243f77b7f
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; import java.io.*; import java.lang.*; import java.math.BigInteger; public class quetion2template { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
21a08cf57bcba6b16c09a0e59d5042d6
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.io.*; import java.util.InputMismatchException; import java.io.IOException; public class B { public static void main(String[] args) throws IOException { InputReader in = new InputReader(System.in); OutputWriter out = new OutputWriter(System.out); int t = in.readInt(); ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
8c02c65bc2e8662c7964cc3dc02ea8be
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; public class Main { s...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
b7392eda5494954e37ad883b16856c89
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class XYSequence { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine()); ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
9040f6fdda4f0c074e20bff34f3da813
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; public class XY_Sequence { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); int[] n = new int[t]; int[] B = new int[t]; int[] x = new int[t]; int[] y = new int[t]; int[] a = new int[t]; long[] num = new long[t...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
802e250aae5477dcdba86357ab594b5c
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; public class Solution { static Scanner sc = new Scanner(System.in); public static void solver() { int n = sc.nextInt(), B = sc.nextInt(), x = sc.nextInt(), y = sc.nextInt(); long sum = 0; int[] a = new int[n+1]; a[0] = 0; for(int i = 1; i...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
596579b652666fa780af11a1bdc43efa
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; public class Main { // static List<List<Integer>> list; // static int findKMaxElement(int[] arr, int k) { // PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder()); // int count = 1; // int n = arr.length; // int i = 0; /...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
51d898abd145c68d606f63a68f14b93c
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; import java.lang.Math; import java.util.Arrays; import java.util.Scanner; public class JavaApplication26 { public static void main(String[] args) throws java.lang.Exception { Scann...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
e17944b12ccd59816a4096cc2c5885cd
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
/* Author:Farhan Shaikh */ 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 Pupil { static FastReader sc = new FastReader(); public static void main (String[] args) throws java.lang.Exception { ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
d47cc535c3b858842d8066ca86255d91
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; import java.io.*; import static java.lang.Math.*; public class Main { public static void swap (int [] arr , int i , int j) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } public static void main(String[] args) throws IOException { OutputStreamWrite...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
69d30fa9bf3b327ca16e0c2cae269938
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; import java.io.*; public class Codeforces{ public static void main(String[] args) throws IOException{ Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t = sc.nextInt(); while (t-- > 0) { i...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
5f8378635ce3a1bd34955af68618ae14
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) { new Thread(null, () -> new Main().run(), "1", 1 << 23).start(); } private void run() { FastReader scan = new FastReader(); PrintWriter out = new PrintWriter(System.out); ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
de2ce329801990bc0b30109a4e6c0ee1
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
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 B = sc.nextInt(); int x = sc.nextInt(); int y = sc.nextInt(); int[]nu...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
38514f37816dbae898a6c047849fc30e
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.io.*; import java.util.*; public final class Main { //int 2e9 - long 9e18 static PrintWriter out = new PrintWriter(System.out); static FastReader in = new FastReader(); static Pair[] moves = new Pair[]{new Pair(-1, 0), new Pair(0, 1), new Pair(1, 0), new Pair(0, -1)}; static...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
15c122fd19fb3e2cfb39a774339d36dc
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; import java.io.*; public class MyCpClass{ public static void main(String []args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); int T = Integer.parseInt(br.readLine()....
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
f309daa14073fee21d7c10be41394b18
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; import java.io.*; public class B { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
4c97794aaabb1798487e69e4cc4ab042
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); while (t-- > 0) { int n = in.nextInt(); int b = in.nextInt(); int x = in.nextInt(); int y = in.nextInt(); long sum = 0; for (int i = 0, s...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
776ae54840a0a0bb96c8fc27f11bfd81
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; import java.io.*; public class codeforces1657B { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int numCases = Integer.parseInt(br.readLine()); for (int rep = 0; rep<numCases;rep+...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
8134a5c22924df4936d57cf22b870d0b
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main{ public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[]data; int t, n, B, x, y; ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
db14551dad53291279239133f1bf3b58
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.io.*; import java.util.*; public class Main { static Reader rd = new Reader(); public static void main(String[] args) { int tt = rd.nextInt(); while (tt-- > 0) { new Solution().solve(); } } static class Solution { void solve() { ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
e516076ffad1b3e4b89c2a088a297be3
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { public static void main(String args[]) throws java.lang.Exception { FastScanner input = new FastScanner(); int tc = input.nextInt(); ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
070be80514ec4b469b4bcdecabc5ee46
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; import java.io.*;import java.math.*; public class Main { public static void main(String ... args) { //import com.sun.java_cup.internal.runtime.Scanner; Scanner sc=new Scanner(System.in); int tt=sc.nextInt(); int n,B,x,y; while((tt--)>0) { BigInteger ans=new BigInteg...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
9fb6227f28b29c370c95f40528352bb8
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.Scanner; public class B1657 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int T = in.nextInt(); for (int t=0; t<T; t++) { int N = in.nextInt(); int B = in.nextInt(); int X = in.nextInt(); ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
94f3a90dba5fd2ec2059608392004fa2
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; import java.lang.Math; import java.util.*; import java.util.Arrays; public class B{ public static void main(String[] args){ int t, n, b, x, y; ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
8ba6bbd5762e755f5ccccd0eea191e81
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.io.*; import java.util.*; public class _1657bb { FastScanner scn; PrintWriter w; PrintStream fs; int MOD = 1000000007; int MAX = 200005; long mul(long x, long y) {long res = x * y; return (res >= MOD ? res % MOD : res);} long power(long x, long y) {if (y < 0) return...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
b5e69e8406c2eb7b99fb7f30a773e4c1
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
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. */ /* Template created by Jabra Ram - @hack41 */ public class Solution { public static void main (String[] args) throws java.lang...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
3f9390db3ef6a9f3c04c1641b3bcce8e
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import javax.swing.*; import java.lang.reflect.Array; import java.text.DecimalFormat; import java.util.*; import java.lang.*; import java.io.*; import java.math.*; import java.util.stream.Stream; // Please name your class Main public class Main { static FastScanner fs=new FastScanner(); ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
58f518f40c31c6d647cf0f8133ad0dbe
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.*; import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
523e8f0cfe0c62c7112f16f3f62eac62
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.Scanner; public class App { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t>0) { int n = sc.nextInt(); int B = sc.nextInt(); int x = sc.nextInt(); ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
b627ab1061907ba04e8d8fae1472f7d5
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
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 Codeforces_1657B { public static void main (String[] args) throws java.lang.Exception { Scanner sc=new Scanner(System...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
92d8add6db93e7d0e1a6a888e3007194
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
// package faltu; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import java.util.Map.Entry; public class Main { public static int upperBound(long[] arr, long m, int l, int r) { while(l<=r) { int mid=(l+r)/2; if(arr[mid...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
c8a3ae6d91aa2f167b1fea1542aa6e07
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; import java.io.*; public class Main { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader(){ try {br = new BufferedReader( ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
cea7610482d3dcfb346209bbb83ff050
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class XYSequence { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t= sc.nextInt(); while (t-->0) { int n = sc.nextInt(); long b = sc.nextLong(); lon...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
179c05cb4d1110120f14006e50d2958b
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.io.PrintWriter; import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; public class B { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int t = in.nextInt(); in.nextLine...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
5382103c46ed943a796d5355463624f9
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.Scanner; public class XY_Sequence { public static long sum(int n,int B,int x,int y){ long s = 0; long arr[] = new long[n]; for (int i = 0; i < n; i++) { if(s + x <= B){ s += x; } else { s -= y;...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
2bdc149b965b9334303e1352e906f836
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.Arrays; import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.TreeSet; import java.util.TreeMa...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
3ddf20d8bcf69bbc536e85885edb79d8
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.Scanner; public class codevita { public static long solve(int n,int B,int x,int y) { long sum=0; int arr[]= new int[n+1]; for(int i=1; i<=n; i++) { if(arr[i-1]+x<=B) { arr[i]=arr[i-1]+x; }else { ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
da3d159e855cd8bcd7f1c550a72992ff
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; public class Main { private static int T; public static void main(String[] args) { Scanner in = new Scanner(System.in); T = in.nextInt(); while(T-- > 0) { int n = in.nextInt(); int b = in.nextInt(); int x = in.nextInt(); ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
d222253d1cdbdba11b62eb1aaaf75267
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner=new Scanner(System.in); int t = scanner.nextInt(); for (int j = 0; j <t ; j++) { Integer n=scanner.nextInt(); Integer b=scanner.nextInt(); ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
da8447b00b654104b62adf35f6958fbc
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; import java.lang.Math; public class test { public static void main(String[] args) { Scanner inputul = new Scanner(System.in); int numbers = inputul.nextInt(); for (int i = 0; i < numbers; i++) { int n,B,x,y; n = inputul.nextInt();...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
521df4d1b203bd343d7e6f21cb1f483a
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
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 { // your code goes here try...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
7e97e1426892dedecb82086902998114
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; public class Main { public static void main(String args[]) { //System.out.println("Hello World!"); Scanner in = new Scanner(System.in); int t = in.nextInt();; while(t-- > 0){ int n = in.nextInt(); int b = in.nextInt(); int x = in.nextI...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
44e4491248aea2eae44a02d0b4db4726
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; public class ahmed { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); long r = 0; while (t-->0) { r = 0; Long[] l = new Long[4]; for (int i = 0;i<4;i++) { l[i] = sc.nextLong(); } Long[] v = new Long[(int) (l[...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
36cecee1e81736a39b25f7068ccf7e5e
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.io.IOException; import java.util.Scanner; public class Main { public static void main(String[] args) throws IOException { Scanner in=new Scanner(System.in); int t=in.nextInt(); for (int i=0;i<t;i++) { int n=in.nextInt(); int b=in.nextI...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
7463ab415264a99c189f9705560d40d5
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; public class Main{ static void solve(int n, int b, int x, int y) { int cur = 0; long res = 0; for (int i = 0; i < n; i++) { if (cur + x <= b) { cur += x; } else { cur -= y; } res +=...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
f05519ee0c0a059d478781b61f10a74f
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; import java.util.stream.Collectors; import java.io.*; import java.math.*; public class ER125_B{ public static FastScanner sc; public static PrintWriter pw; public static StringBuilder sb; public static int MOD= 1000000007; public static class FastScanner { BufferedRead...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
ab769f8cd1779da24f04ca83606cd9e6
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.Scanner; public class XYSequence { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); for (int i = 0; i < t; i++) { long n = scanner.nextLong(), b = scanner.nextLong(), x = scanner.nextL...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
b339b4a2705806d7a334f8956c6e1ee3
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.io.*; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.StringTokenizer; import java.util.logging.Logger; /** * Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools * * To modify the template, go to Prefer...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
490c7d2d61186662d8646b2988873752
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Scanner; /** * Built using CHelper plug-in * Actual solution is at the top * * @author cpp */ public class Main { public static void main(String[] args) { Inp...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
1d70210d179b9deb26be6b864e0ba044
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; import java.lang.Math; public class IntegerMoves { static long maxSum ( long n, long B, long x, long y ) { int i; long last = 0; long totalSum = 0; for ( i = 0; i < n; i++ ) { if (B<last+x) last=last-y; else last=last+x; totalS...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
1f8658ba6cb50692b20b7dfba202eba1
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.math.BigInteger; import java.util.*; import java.util.concurrent.ThreadLocalRandom; public class c731{ p...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
7d00a0d60802862ddb4e97136a425b4f
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.io.*; public class Main{ 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){ String[] str = br.readLine().split(" "); ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
0ae4c789174012c24ee5cf999c5d503d
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.io.*; import java.math.*; import java.util.*; import java.util.regex.Matcher; public class Main { static final int INF = 0x3f3f3f3f; static final long LNF = 0x3f3f3f3f3f3f3f3fL; static int[]arr;static int n;static int b;static int x,y; public static void main(String[] args) thr...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
64daad6017a217b14769c0c3df42f459
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.io.*; import java.util.*; public class XYSequence { public static PrintWriter out; public static void main(String[] args)throws IOException{ Scanner sc=new Scanner(); out=new PrintWriter(System.out); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
53eb8391014c66fbb975dc58e61c8267
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.Scanner; public class XYSequence { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); int t = in.nextInt(); int i=0; StringBuilder sc=new StringBuilder(); while(i<t) { int n=in.nextInt(); long b=in.nextLong...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
b7917a644be281b283abb2d1ab2eb93c
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
/* * akshaygupta26 */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Random; import java.util.StringTokenizer; public class B { static long mod = (long) (1e9 + 7); public static void main(String[] args) { Fas...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
bca88751e5d78f02865910dc41875632
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
// package JAVA; // import java.util.ArrayList; // import java.util.Arrays; // import java.util.List; import java.util.Scanner; // import org.omg.CORBA.INV_OBJREF; // import javax.swing.text.Highlighter.Highlight; public class Main { // static int[] f = new int[10]; public static void main(St...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
199f4d510e6e41e03e0f5835bcd3fec8
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { static AReader scan = new AReader(); static void slove() { int n = scan.nextInt(); int b = scan.nextInt(); int x = scan.nextInt(); int y = scan.n...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
b9ee4c23891947c24ec4495cf9df9a70
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; import javax.management.Query; import java.io.*; public class Main { // static int n,k; //// static String t,s; // static long[]memo; // static int n; static String s; static HashMap<Long,Integer>hm; public static void main(String[] args) throws Exception { ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
be27daa86231a6dfd987bf53b396dfa2
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; import java.util.concurrent.LinkedBlockingDeque; import javax.sql.rowset.spi.SyncResolver; import java.io.*; import java.nio.channels.NonReadableChannelException; import java.text.DateFormatSymbols; public class CpTemp { static int a[]; static long count=0; static long row ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
f89e8e78ba6613e6bb1b553cd9e7e8df
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class XYSequence { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
1b723eeed4655805eae601bd84066378
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; import java.lang.*; public class sumdigit{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); long B=sc.nextLong(); long x=sc.nextLong(); ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
e78992e06a6b39227e97e04e3d167bae
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.Map; import java.util.Scanner; import java.util.Set; im...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
65edbed2734226ff3c53e03ca717ea62
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.StringTokenizer; import java.uti...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
2d662a4b893ca55e65009d71f24bf11b
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.io.*; import java.util.*; import java.lang.Math; import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; public class Main { static PrintWriter pw; static Scanner sc; static StringBuilder ans; static long mod = 1000000000+...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
d095efa166d149286a04a9e426449e6d
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
/*Radhe-Krishna*/ import javax.print.CancelablePrintJob; import javax.xml.stream.events.Characters; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.sql.SQLType; import java.util.*; public class Main { static int mod=1000000007; static clas...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
357e0b9c7fa110dca06b26ed0e0a4c71
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; public class Main { static Scanner sc = new Scanner(System.in) ; public static void main(String[] args) { int N = sc.nextInt(); while (N-- != 0) { int n = sc.nextInt() ; int b = sc.nextInt() ; int x = sc.nextInt() ; ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
88fc45e0be05a11b7fa572337343574e
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); int b = sc.nextInt(); int x = sc.nextInt(); int y = sc.nextInt(); long sum = 0; long c = 0; fo...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
998fc938f3758b66fc70da705fa01666
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
//CP- MASS_2701 import java.util.*; import java.io.*; public class B_XY_Sequence { static FastReader in=new FastReader(); static final Random random=new Random(); static long mod=1000000007L; static HashMap<String,Integer>map=new HashMap<>(); public static void main(String args[]) throws I...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
c30b38587daed692d4723cd40916aa8f
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.awt.*; import java.util.*; import java.io.*; public class Codeforces { static FScanner sc = new FScanner(); static PrintWriter out = new PrintWriter(System.out); static final Random random = new Random(); static long mod = 1000000007L; static HashMap<String, Integer> map = new ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
a92d9fbe773b3bdf708169fcd5bea823
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) throws Exception { FastIO io = new FastIO(); int test=io.nextInt(); while(test>0) { int n=io.nextInt(); long b=io.nextLong(); long x=io.nextLong(); long ...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
e79ca35c8efbcbef789cd74691d68b57
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
//import java.io.IOException; import java.io.*; import java.util.*; public class XYSequence { static InputReader inputReader=new InputReader(System.in); static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); static List<LinkedHashSet<Integer>>a...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
ed28758cb4cbefb825684c9282e4e706
train_110.jsonl
1647960300
You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose: either $$$a_i = a_{i - 1} + x$$$ or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$...
256 megabytes
import java.util.*; public class code { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long t = sc.nextLong(); while (t-- > 0) { int n=sc.nextInt(); int B=sc.nextInt(); int x=sc.nextInt(); int y= sc.nex...
Java
["3\n5 100 1 30\n7 1000000000 1000000000 1000000000\n4 1 7 3"]
2 seconds
["15\n4000000000\n-10"]
NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.
Java 8
standard input
[ "greedy" ]
2c921093abf2c5963f5f0e96cd430456
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the...
800
For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.
standard output
PASSED
42b8338409c4a5808afe7aa250d6f0d7
train_110.jsonl
1647960300
Monocarp is playing a strategy game. In the game, he recruits a squad to fight monsters. Before each battle, Monocarp has $$$C$$$ coins to spend on his squad.Before each battle starts, his squad is empty. Monocarp chooses one type of units and recruits no more units of that type than he can recruit with $$$C$$$ coins.T...
256 megabytes
// package edu_125; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class DD{ public static void main(String[] args){ FastReader sc = new FastReader(); int t=1; while(t-->0){ int n=sc.nextInt(); int C=sc.nextInt(); Pai...
Java
["3 10\n3 4 6\n5 5 5\n10 3 4\n3\n8 3\n5 4\n10 15", "5 15\n14 10 3\n9 2 2\n10 4 3\n7 3 5\n4 3 1\n6\n11 2\n1 1\n4 7\n2 1\n1 14\n3 3", "5 13\n13 1 9\n6 4 5\n12 18 4\n9 13 2\n5 4 5\n2\n16 3\n6 2"]
4 seconds
["5 3 -1", "14 4 14 4 7 7", "12 5"]
NoteConsider the first monster of the first example.Monocarp can't recruit one unit of the first type, because it will take both him and the monster $$$0.75$$$ seconds to kill each other. He can recruit two units for the cost of $$$6$$$ coins and kill the monster in $$$0.375$$$ second.Monocarp can recruit one unit of t...
Java 11
standard input
[ "binary search", "brute force", "greedy", "math", "sortings" ]
476c05915a1536cd989c4681c61c9deb
The first line contains two integers $$$n$$$ and $$$C$$$ ($$$1 \le n \le 3 \cdot 10^5$$$; $$$1 \le C \le 10^6$$$) — the number of types of units and the amount of coins Monocarp has before each battle. The $$$i$$$-th of the next $$$n$$$ lines contains three integers $$$c_i, d_i$$$ and $$$h_i$$$ ($$$1 \le c_i \le C$$$; ...
2,000
Print $$$m$$$ integers. For each monster, print the minimum amount of coins Monocarp has to spend to kill that monster. If this amount is greater than $$$C$$$, then print $$$-1$$$.
standard output
PASSED
b4ca523397e96f55fc103d163168ff88
train_110.jsonl
1647960300
Monocarp is playing a strategy game. In the game, he recruits a squad to fight monsters. Before each battle, Monocarp has $$$C$$$ coins to spend on his squad.Before each battle starts, his squad is empty. Monocarp chooses one type of units and recruits no more units of that type than he can recruit with $$$C$$$ coins.T...
256 megabytes
import java.util.*; import java.io.*; public class Solution { public static void main(String[] args) throws IOException { StringBuilder sb = new StringBuilder(); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String[] tokens = in.readLine().split("\\s+"...
Java
["3 10\n3 4 6\n5 5 5\n10 3 4\n3\n8 3\n5 4\n10 15", "5 15\n14 10 3\n9 2 2\n10 4 3\n7 3 5\n4 3 1\n6\n11 2\n1 1\n4 7\n2 1\n1 14\n3 3", "5 13\n13 1 9\n6 4 5\n12 18 4\n9 13 2\n5 4 5\n2\n16 3\n6 2"]
4 seconds
["5 3 -1", "14 4 14 4 7 7", "12 5"]
NoteConsider the first monster of the first example.Monocarp can't recruit one unit of the first type, because it will take both him and the monster $$$0.75$$$ seconds to kill each other. He can recruit two units for the cost of $$$6$$$ coins and kill the monster in $$$0.375$$$ second.Monocarp can recruit one unit of t...
Java 11
standard input
[ "binary search", "brute force", "greedy", "math", "sortings" ]
476c05915a1536cd989c4681c61c9deb
The first line contains two integers $$$n$$$ and $$$C$$$ ($$$1 \le n \le 3 \cdot 10^5$$$; $$$1 \le C \le 10^6$$$) — the number of types of units and the amount of coins Monocarp has before each battle. The $$$i$$$-th of the next $$$n$$$ lines contains three integers $$$c_i, d_i$$$ and $$$h_i$$$ ($$$1 \le c_i \le C$$$; ...
2,000
Print $$$m$$$ integers. For each monster, print the minimum amount of coins Monocarp has to spend to kill that monster. If this amount is greater than $$$C$$$, then print $$$-1$$$.
standard output
PASSED
d3e54d52f888738988e99402765c2882
train_110.jsonl
1647960300
Monocarp is playing a strategy game. In the game, he recruits a squad to fight monsters. Before each battle, Monocarp has $$$C$$$ coins to spend on his squad.Before each battle starts, his squad is empty. Monocarp chooses one type of units and recruits no more units of that type than he can recruit with $$$C$$$ coins.T...
256 megabytes
import java.io.IOException; import java.io.BufferedReader; import java.io.FileReader; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.Arrays; import java.util.Random; import java.io.FileWriter; import java.io.PrintWriter; /* Solution Created: 20:55:54 22/03/2022 C...
Java
["3 10\n3 4 6\n5 5 5\n10 3 4\n3\n8 3\n5 4\n10 15", "5 15\n14 10 3\n9 2 2\n10 4 3\n7 3 5\n4 3 1\n6\n11 2\n1 1\n4 7\n2 1\n1 14\n3 3", "5 13\n13 1 9\n6 4 5\n12 18 4\n9 13 2\n5 4 5\n2\n16 3\n6 2"]
4 seconds
["5 3 -1", "14 4 14 4 7 7", "12 5"]
NoteConsider the first monster of the first example.Monocarp can't recruit one unit of the first type, because it will take both him and the monster $$$0.75$$$ seconds to kill each other. He can recruit two units for the cost of $$$6$$$ coins and kill the monster in $$$0.375$$$ second.Monocarp can recruit one unit of t...
Java 11
standard input
[ "binary search", "brute force", "greedy", "math", "sortings" ]
476c05915a1536cd989c4681c61c9deb
The first line contains two integers $$$n$$$ and $$$C$$$ ($$$1 \le n \le 3 \cdot 10^5$$$; $$$1 \le C \le 10^6$$$) — the number of types of units and the amount of coins Monocarp has before each battle. The $$$i$$$-th of the next $$$n$$$ lines contains three integers $$$c_i, d_i$$$ and $$$h_i$$$ ($$$1 \le c_i \le C$$$; ...
2,000
Print $$$m$$$ integers. For each monster, print the minimum amount of coins Monocarp has to spend to kill that monster. If this amount is greater than $$$C$$$, then print $$$-1$$$.
standard output
PASSED
68b5bf02f3c87e058fc8dcb9cdaa7bc4
train_110.jsonl
1647960300
Monocarp is playing a strategy game. In the game, he recruits a squad to fight monsters. Before each battle, Monocarp has $$$C$$$ coins to spend on his squad.Before each battle starts, his squad is empty. Monocarp chooses one type of units and recruits no more units of that type than he can recruit with $$$C$$$ coins.T...
256 megabytes
import java.io.*; import java.util.*; public class Solution extends PrintWriter { Solution() { super(System.out, true); } Scanner sc = new Scanner(System.in); public static void main(String[] $) { Solution o = new Solution(); o.main(); o.flush(); } static final long INF = 0x3f3f3f3f3f3f3f3fL; void ...
Java
["3 10\n3 4 6\n5 5 5\n10 3 4\n3\n8 3\n5 4\n10 15", "5 15\n14 10 3\n9 2 2\n10 4 3\n7 3 5\n4 3 1\n6\n11 2\n1 1\n4 7\n2 1\n1 14\n3 3", "5 13\n13 1 9\n6 4 5\n12 18 4\n9 13 2\n5 4 5\n2\n16 3\n6 2"]
4 seconds
["5 3 -1", "14 4 14 4 7 7", "12 5"]
NoteConsider the first monster of the first example.Monocarp can't recruit one unit of the first type, because it will take both him and the monster $$$0.75$$$ seconds to kill each other. He can recruit two units for the cost of $$$6$$$ coins and kill the monster in $$$0.375$$$ second.Monocarp can recruit one unit of t...
Java 11
standard input
[ "binary search", "brute force", "greedy", "math", "sortings" ]
476c05915a1536cd989c4681c61c9deb
The first line contains two integers $$$n$$$ and $$$C$$$ ($$$1 \le n \le 3 \cdot 10^5$$$; $$$1 \le C \le 10^6$$$) — the number of types of units and the amount of coins Monocarp has before each battle. The $$$i$$$-th of the next $$$n$$$ lines contains three integers $$$c_i, d_i$$$ and $$$h_i$$$ ($$$1 \le c_i \le C$$$; ...
2,000
Print $$$m$$$ integers. For each monster, print the minimum amount of coins Monocarp has to spend to kill that monster. If this amount is greater than $$$C$$$, then print $$$-1$$$.
standard output
PASSED
c7ac1430d13ae963784d0637e5a93c4d
train_110.jsonl
1647960300
Monocarp is playing a strategy game. In the game, he recruits a squad to fight monsters. Before each battle, Monocarp has $$$C$$$ coins to spend on his squad.Before each battle starts, his squad is empty. Monocarp chooses one type of units and recruits no more units of that type than he can recruit with $$$C$$$ coins.T...
256 megabytes
import java.util.*; import java.io.*; public class D { static FastScanner fs = new FastScanner(); static PrintWriter pw = new PrintWriter(System.out); static StringBuilder sb = new StringBuilder(""); public static void main(String[] args) { int n = fs.nextInt(); int C =...
Java
["3 10\n3 4 6\n5 5 5\n10 3 4\n3\n8 3\n5 4\n10 15", "5 15\n14 10 3\n9 2 2\n10 4 3\n7 3 5\n4 3 1\n6\n11 2\n1 1\n4 7\n2 1\n1 14\n3 3", "5 13\n13 1 9\n6 4 5\n12 18 4\n9 13 2\n5 4 5\n2\n16 3\n6 2"]
4 seconds
["5 3 -1", "14 4 14 4 7 7", "12 5"]
NoteConsider the first monster of the first example.Monocarp can't recruit one unit of the first type, because it will take both him and the monster $$$0.75$$$ seconds to kill each other. He can recruit two units for the cost of $$$6$$$ coins and kill the monster in $$$0.375$$$ second.Monocarp can recruit one unit of t...
Java 11
standard input
[ "binary search", "brute force", "greedy", "math", "sortings" ]
476c05915a1536cd989c4681c61c9deb
The first line contains two integers $$$n$$$ and $$$C$$$ ($$$1 \le n \le 3 \cdot 10^5$$$; $$$1 \le C \le 10^6$$$) — the number of types of units and the amount of coins Monocarp has before each battle. The $$$i$$$-th of the next $$$n$$$ lines contains three integers $$$c_i, d_i$$$ and $$$h_i$$$ ($$$1 \le c_i \le C$$$; ...
2,000
Print $$$m$$$ integers. For each monster, print the minimum amount of coins Monocarp has to spend to kill that monster. If this amount is greater than $$$C$$$, then print $$$-1$$$.
standard output
PASSED
c8d86dd3d816baf6097ca8a0f52d7490
train_110.jsonl
1647960300
Monocarp is playing a strategy game. In the game, he recruits a squad to fight monsters. Before each battle, Monocarp has $$$C$$$ coins to spend on his squad.Before each battle starts, his squad is empty. Monocarp chooses one type of units and recruits no more units of that type than he can recruit with $$$C$$$ coins.T...
256 megabytes
import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.security.cert.X509CRL; import java.util.*; import java.lang.*; import java.util.stream.Collector; import java.util.stream.Co...
Java
["3 10\n3 4 6\n5 5 5\n10 3 4\n3\n8 3\n5 4\n10 15", "5 15\n14 10 3\n9 2 2\n10 4 3\n7 3 5\n4 3 1\n6\n11 2\n1 1\n4 7\n2 1\n1 14\n3 3", "5 13\n13 1 9\n6 4 5\n12 18 4\n9 13 2\n5 4 5\n2\n16 3\n6 2"]
4 seconds
["5 3 -1", "14 4 14 4 7 7", "12 5"]
NoteConsider the first monster of the first example.Monocarp can't recruit one unit of the first type, because it will take both him and the monster $$$0.75$$$ seconds to kill each other. He can recruit two units for the cost of $$$6$$$ coins and kill the monster in $$$0.375$$$ second.Monocarp can recruit one unit of t...
Java 11
standard input
[ "binary search", "brute force", "greedy", "math", "sortings" ]
476c05915a1536cd989c4681c61c9deb
The first line contains two integers $$$n$$$ and $$$C$$$ ($$$1 \le n \le 3 \cdot 10^5$$$; $$$1 \le C \le 10^6$$$) — the number of types of units and the amount of coins Monocarp has before each battle. The $$$i$$$-th of the next $$$n$$$ lines contains three integers $$$c_i, d_i$$$ and $$$h_i$$$ ($$$1 \le c_i \le C$$$; ...
2,000
Print $$$m$$$ integers. For each monster, print the minimum amount of coins Monocarp has to spend to kill that monster. If this amount is greater than $$$C$$$, then print $$$-1$$$.
standard output
PASSED
9b0855de1010b119f5148a990c18100b
train_110.jsonl
1647960300
Monocarp is playing a strategy game. In the game, he recruits a squad to fight monsters. Before each battle, Monocarp has $$$C$$$ coins to spend on his squad.Before each battle starts, his squad is empty. Monocarp chooses one type of units and recruits no more units of that type than he can recruit with $$$C$$$ coins.T...
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class TaskD { public static void main(String[] args) { final Scanner in = new Scanner(System.in); new TaskD().solve(in); } private void solve(final Scanner in) { final int n = in.nextInt(); final int C = in.nextInt(); fi...
Java
["3 10\n3 4 6\n5 5 5\n10 3 4\n3\n8 3\n5 4\n10 15", "5 15\n14 10 3\n9 2 2\n10 4 3\n7 3 5\n4 3 1\n6\n11 2\n1 1\n4 7\n2 1\n1 14\n3 3", "5 13\n13 1 9\n6 4 5\n12 18 4\n9 13 2\n5 4 5\n2\n16 3\n6 2"]
4 seconds
["5 3 -1", "14 4 14 4 7 7", "12 5"]
NoteConsider the first monster of the first example.Monocarp can't recruit one unit of the first type, because it will take both him and the monster $$$0.75$$$ seconds to kill each other. He can recruit two units for the cost of $$$6$$$ coins and kill the monster in $$$0.375$$$ second.Monocarp can recruit one unit of t...
Java 11
standard input
[ "binary search", "brute force", "greedy", "math", "sortings" ]
476c05915a1536cd989c4681c61c9deb
The first line contains two integers $$$n$$$ and $$$C$$$ ($$$1 \le n \le 3 \cdot 10^5$$$; $$$1 \le C \le 10^6$$$) — the number of types of units and the amount of coins Monocarp has before each battle. The $$$i$$$-th of the next $$$n$$$ lines contains three integers $$$c_i, d_i$$$ and $$$h_i$$$ ($$$1 \le c_i \le C$$$; ...
2,000
Print $$$m$$$ integers. For each monster, print the minimum amount of coins Monocarp has to spend to kill that monster. If this amount is greater than $$$C$$$, then print $$$-1$$$.
standard output
PASSED
715ccc2e4cb18208e66eaa22f413c0b0
train_110.jsonl
1647960300
Monocarp is playing a strategy game. In the game, he recruits a squad to fight monsters. Before each battle, Monocarp has $$$C$$$ coins to spend on his squad.Before each battle starts, his squad is empty. Monocarp chooses one type of units and recruits no more units of that type than he can recruit with $$$C$$$ coins.T...
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class TaskD { public static void main(String[] args) { Scanner in = new Scanner(System.in); new TaskD().solve(in); } private void solve(Scanner in) { int n = in.nextInt(); final int C = in.nextInt(); long[] bestPowerAtCo...
Java
["3 10\n3 4 6\n5 5 5\n10 3 4\n3\n8 3\n5 4\n10 15", "5 15\n14 10 3\n9 2 2\n10 4 3\n7 3 5\n4 3 1\n6\n11 2\n1 1\n4 7\n2 1\n1 14\n3 3", "5 13\n13 1 9\n6 4 5\n12 18 4\n9 13 2\n5 4 5\n2\n16 3\n6 2"]
4 seconds
["5 3 -1", "14 4 14 4 7 7", "12 5"]
NoteConsider the first monster of the first example.Monocarp can't recruit one unit of the first type, because it will take both him and the monster $$$0.75$$$ seconds to kill each other. He can recruit two units for the cost of $$$6$$$ coins and kill the monster in $$$0.375$$$ second.Monocarp can recruit one unit of t...
Java 11
standard input
[ "binary search", "brute force", "greedy", "math", "sortings" ]
476c05915a1536cd989c4681c61c9deb
The first line contains two integers $$$n$$$ and $$$C$$$ ($$$1 \le n \le 3 \cdot 10^5$$$; $$$1 \le C \le 10^6$$$) — the number of types of units and the amount of coins Monocarp has before each battle. The $$$i$$$-th of the next $$$n$$$ lines contains three integers $$$c_i, d_i$$$ and $$$h_i$$$ ($$$1 \le c_i \le C$$$; ...
2,000
Print $$$m$$$ integers. For each monster, print the minimum amount of coins Monocarp has to spend to kill that monster. If this amount is greater than $$$C$$$, then print $$$-1$$$.
standard output
PASSED
14fe6af96374b43be2e0e7333b47b84a
train_110.jsonl
1647960300
Monocarp is playing a strategy game. In the game, he recruits a squad to fight monsters. Before each battle, Monocarp has $$$C$$$ coins to spend on his squad.Before each battle starts, his squad is empty. Monocarp chooses one type of units and recruits no more units of that type than he can recruit with $$$C$$$ coins.T...
256 megabytes
import java.io.*; import java.lang.Math; import java.math.BigInteger; import java.nio.*; import java.util.*; public final class code { static int tot; static class sortCond implements Comparator<Pair<Integer, Pair<Long, Long>>> { @Override public int compare( Pair<Integer, Pair<Long,...
Java
["3 10\n3 4 6\n5 5 5\n10 3 4\n3\n8 3\n5 4\n10 15", "5 15\n14 10 3\n9 2 2\n10 4 3\n7 3 5\n4 3 1\n6\n11 2\n1 1\n4 7\n2 1\n1 14\n3 3", "5 13\n13 1 9\n6 4 5\n12 18 4\n9 13 2\n5 4 5\n2\n16 3\n6 2"]
4 seconds
["5 3 -1", "14 4 14 4 7 7", "12 5"]
NoteConsider the first monster of the first example.Monocarp can't recruit one unit of the first type, because it will take both him and the monster $$$0.75$$$ seconds to kill each other. He can recruit two units for the cost of $$$6$$$ coins and kill the monster in $$$0.375$$$ second.Monocarp can recruit one unit of t...
Java 11
standard input
[ "binary search", "brute force", "greedy", "math", "sortings" ]
476c05915a1536cd989c4681c61c9deb
The first line contains two integers $$$n$$$ and $$$C$$$ ($$$1 \le n \le 3 \cdot 10^5$$$; $$$1 \le C \le 10^6$$$) — the number of types of units and the amount of coins Monocarp has before each battle. The $$$i$$$-th of the next $$$n$$$ lines contains three integers $$$c_i, d_i$$$ and $$$h_i$$$ ($$$1 \le c_i \le C$$$; ...
2,000
Print $$$m$$$ integers. For each monster, print the minimum amount of coins Monocarp has to spend to kill that monster. If this amount is greater than $$$C$$$, then print $$$-1$$$.
standard output
PASSED
011c7f3affeeee5bcc92e2fbe142d006
train_110.jsonl
1647960300
Monocarp is playing a strategy game. In the game, he recruits a squad to fight monsters. Before each battle, Monocarp has $$$C$$$ coins to spend on his squad.Before each battle starts, his squad is empty. Monocarp chooses one type of units and recruits no more units of that type than he can recruit with $$$C$$$ coins.T...
256 megabytes
import java.io.*; import java.lang.Math; import java.math.BigInteger; import java.nio.*; import java.util.*; public final class code { static int tot; static class sortCond implements Comparator<Pair<Integer, Pair<Long, Long>>> { @Override public int compare( Pair<Integer, Pair<Long,...
Java
["3 10\n3 4 6\n5 5 5\n10 3 4\n3\n8 3\n5 4\n10 15", "5 15\n14 10 3\n9 2 2\n10 4 3\n7 3 5\n4 3 1\n6\n11 2\n1 1\n4 7\n2 1\n1 14\n3 3", "5 13\n13 1 9\n6 4 5\n12 18 4\n9 13 2\n5 4 5\n2\n16 3\n6 2"]
4 seconds
["5 3 -1", "14 4 14 4 7 7", "12 5"]
NoteConsider the first monster of the first example.Monocarp can't recruit one unit of the first type, because it will take both him and the monster $$$0.75$$$ seconds to kill each other. He can recruit two units for the cost of $$$6$$$ coins and kill the monster in $$$0.375$$$ second.Monocarp can recruit one unit of t...
Java 11
standard input
[ "binary search", "brute force", "greedy", "math", "sortings" ]
476c05915a1536cd989c4681c61c9deb
The first line contains two integers $$$n$$$ and $$$C$$$ ($$$1 \le n \le 3 \cdot 10^5$$$; $$$1 \le C \le 10^6$$$) — the number of types of units and the amount of coins Monocarp has before each battle. The $$$i$$$-th of the next $$$n$$$ lines contains three integers $$$c_i, d_i$$$ and $$$h_i$$$ ($$$1 \le c_i \le C$$$; ...
2,000
Print $$$m$$$ integers. For each monster, print the minimum amount of coins Monocarp has to spend to kill that monster. If this amount is greater than $$$C$$$, then print $$$-1$$$.
standard output
PASSED
3790cf3816ae17f690023f94b5da31c2
train_110.jsonl
1647960300
Monocarp is playing a strategy game. In the game, he recruits a squad to fight monsters. Before each battle, Monocarp has $$$C$$$ coins to spend on his squad.Before each battle starts, his squad is empty. Monocarp chooses one type of units and recruits no more units of that type than he can recruit with $$$C$$$ coins.T...
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class C1657D { static class Point { long a; int b; public Point(long a, int b) { this.a = a; this.b = b; } } public static void ...
Java
["3 10\n3 4 6\n5 5 5\n10 3 4\n3\n8 3\n5 4\n10 15", "5 15\n14 10 3\n9 2 2\n10 4 3\n7 3 5\n4 3 1\n6\n11 2\n1 1\n4 7\n2 1\n1 14\n3 3", "5 13\n13 1 9\n6 4 5\n12 18 4\n9 13 2\n5 4 5\n2\n16 3\n6 2"]
4 seconds
["5 3 -1", "14 4 14 4 7 7", "12 5"]
NoteConsider the first monster of the first example.Monocarp can't recruit one unit of the first type, because it will take both him and the monster $$$0.75$$$ seconds to kill each other. He can recruit two units for the cost of $$$6$$$ coins and kill the monster in $$$0.375$$$ second.Monocarp can recruit one unit of t...
Java 11
standard input
[ "binary search", "brute force", "greedy", "math", "sortings" ]
476c05915a1536cd989c4681c61c9deb
The first line contains two integers $$$n$$$ and $$$C$$$ ($$$1 \le n \le 3 \cdot 10^5$$$; $$$1 \le C \le 10^6$$$) — the number of types of units and the amount of coins Monocarp has before each battle. The $$$i$$$-th of the next $$$n$$$ lines contains three integers $$$c_i, d_i$$$ and $$$h_i$$$ ($$$1 \le c_i \le C$$$; ...
2,000
Print $$$m$$$ integers. For each monster, print the minimum amount of coins Monocarp has to spend to kill that monster. If this amount is greater than $$$C$$$, then print $$$-1$$$.
standard output
PASSED
244819039f0825c220c758ea4167c062
train_110.jsonl
1647960300
Monocarp is playing a strategy game. In the game, he recruits a squad to fight monsters. Before each battle, Monocarp has $$$C$$$ coins to spend on his squad.Before each battle starts, his squad is empty. Monocarp chooses one type of units and recruits no more units of that type than he can recruit with $$$C$$$ coins.T...
256 megabytes
import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import java.io.*; import java.util.*; public class Solution { static int mod=(int)1e9+7; static double epsilon = 0.000001d; static long h[],add[]; public static void main(String[] args) { ...
Java
["3 10\n3 4 6\n5 5 5\n10 3 4\n3\n8 3\n5 4\n10 15", "5 15\n14 10 3\n9 2 2\n10 4 3\n7 3 5\n4 3 1\n6\n11 2\n1 1\n4 7\n2 1\n1 14\n3 3", "5 13\n13 1 9\n6 4 5\n12 18 4\n9 13 2\n5 4 5\n2\n16 3\n6 2"]
4 seconds
["5 3 -1", "14 4 14 4 7 7", "12 5"]
NoteConsider the first monster of the first example.Monocarp can't recruit one unit of the first type, because it will take both him and the monster $$$0.75$$$ seconds to kill each other. He can recruit two units for the cost of $$$6$$$ coins and kill the monster in $$$0.375$$$ second.Monocarp can recruit one unit of t...
Java 11
standard input
[ "binary search", "brute force", "greedy", "math", "sortings" ]
476c05915a1536cd989c4681c61c9deb
The first line contains two integers $$$n$$$ and $$$C$$$ ($$$1 \le n \le 3 \cdot 10^5$$$; $$$1 \le C \le 10^6$$$) — the number of types of units and the amount of coins Monocarp has before each battle. The $$$i$$$-th of the next $$$n$$$ lines contains three integers $$$c_i, d_i$$$ and $$$h_i$$$ ($$$1 \le c_i \le C$$$; ...
2,000
Print $$$m$$$ integers. For each monster, print the minimum amount of coins Monocarp has to spend to kill that monster. If this amount is greater than $$$C$$$, then print $$$-1$$$.
standard output
PASSED
29c2b33538218d3b60955d5603f86264
train_110.jsonl
1647960300
Monocarp is playing a strategy game. In the game, he recruits a squad to fight monsters. Before each battle, Monocarp has $$$C$$$ coins to spend on his squad.Before each battle starts, his squad is empty. Monocarp chooses one type of units and recruits no more units of that type than he can recruit with $$$C$$$ coins.T...
256 megabytes
import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import java.io.*; import java.util.*; public class Solution { static int mod=(int)1e9+7; static double epsilon = 0.000001d; static long h[],add[]; public static void main(String[] args) { ...
Java
["3 10\n3 4 6\n5 5 5\n10 3 4\n3\n8 3\n5 4\n10 15", "5 15\n14 10 3\n9 2 2\n10 4 3\n7 3 5\n4 3 1\n6\n11 2\n1 1\n4 7\n2 1\n1 14\n3 3", "5 13\n13 1 9\n6 4 5\n12 18 4\n9 13 2\n5 4 5\n2\n16 3\n6 2"]
4 seconds
["5 3 -1", "14 4 14 4 7 7", "12 5"]
NoteConsider the first monster of the first example.Monocarp can't recruit one unit of the first type, because it will take both him and the monster $$$0.75$$$ seconds to kill each other. He can recruit two units for the cost of $$$6$$$ coins and kill the monster in $$$0.375$$$ second.Monocarp can recruit one unit of t...
Java 11
standard input
[ "binary search", "brute force", "greedy", "math", "sortings" ]
476c05915a1536cd989c4681c61c9deb
The first line contains two integers $$$n$$$ and $$$C$$$ ($$$1 \le n \le 3 \cdot 10^5$$$; $$$1 \le C \le 10^6$$$) — the number of types of units and the amount of coins Monocarp has before each battle. The $$$i$$$-th of the next $$$n$$$ lines contains three integers $$$c_i, d_i$$$ and $$$h_i$$$ ($$$1 \le c_i \le C$$$; ...
2,000
Print $$$m$$$ integers. For each monster, print the minimum amount of coins Monocarp has to spend to kill that monster. If this amount is greater than $$$C$$$, then print $$$-1$$$.
standard output
PASSED
5539e0b5e997af71b4e8895b0bb7e56f
train_110.jsonl
1647960300
Monocarp is playing a strategy game. In the game, he recruits a squad to fight monsters. Before each battle, Monocarp has $$$C$$$ coins to spend on his squad.Before each battle starts, his squad is empty. Monocarp chooses one type of units and recruits no more units of that type than he can recruit with $$$C$$$ coins.T...
256 megabytes
import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import java.io.*; import java.util.*; public class Solution { static int mod=(int)1e9+7; static double epsilon = 0.000001d; static long h[],add[]; public static void main(String[] args) { ...
Java
["3 10\n3 4 6\n5 5 5\n10 3 4\n3\n8 3\n5 4\n10 15", "5 15\n14 10 3\n9 2 2\n10 4 3\n7 3 5\n4 3 1\n6\n11 2\n1 1\n4 7\n2 1\n1 14\n3 3", "5 13\n13 1 9\n6 4 5\n12 18 4\n9 13 2\n5 4 5\n2\n16 3\n6 2"]
4 seconds
["5 3 -1", "14 4 14 4 7 7", "12 5"]
NoteConsider the first monster of the first example.Monocarp can't recruit one unit of the first type, because it will take both him and the monster $$$0.75$$$ seconds to kill each other. He can recruit two units for the cost of $$$6$$$ coins and kill the monster in $$$0.375$$$ second.Monocarp can recruit one unit of t...
Java 11
standard input
[ "binary search", "brute force", "greedy", "math", "sortings" ]
476c05915a1536cd989c4681c61c9deb
The first line contains two integers $$$n$$$ and $$$C$$$ ($$$1 \le n \le 3 \cdot 10^5$$$; $$$1 \le C \le 10^6$$$) — the number of types of units and the amount of coins Monocarp has before each battle. The $$$i$$$-th of the next $$$n$$$ lines contains three integers $$$c_i, d_i$$$ and $$$h_i$$$ ($$$1 \le c_i \le C$$$; ...
2,000
Print $$$m$$$ integers. For each monster, print the minimum amount of coins Monocarp has to spend to kill that monster. If this amount is greater than $$$C$$$, then print $$$-1$$$.
standard output
PASSED
ef3607c15bf21d955d4e4b3226f4d0b2
train_110.jsonl
1647960300
Monocarp is playing a strategy game. In the game, he recruits a squad to fight monsters. Before each battle, Monocarp has $$$C$$$ coins to spend on his squad.Before each battle starts, his squad is empty. Monocarp chooses one type of units and recruits no more units of that type than he can recruit with $$$C$$$ coins.T...
256 megabytes
import java.io.*; import java.util.*; import java.math.BigDecimal; import java.math.*; // public class Main{ private static int[] input() { int n=in.nextInt(); int[]arr=new int[n]; for(int i=0;i<n;i++) { arr[i]=in.nextInt(); } return arr; } private static int[]input(int n){ int []arr...
Java
["3 10\n3 4 6\n5 5 5\n10 3 4\n3\n8 3\n5 4\n10 15", "5 15\n14 10 3\n9 2 2\n10 4 3\n7 3 5\n4 3 1\n6\n11 2\n1 1\n4 7\n2 1\n1 14\n3 3", "5 13\n13 1 9\n6 4 5\n12 18 4\n9 13 2\n5 4 5\n2\n16 3\n6 2"]
4 seconds
["5 3 -1", "14 4 14 4 7 7", "12 5"]
NoteConsider the first monster of the first example.Monocarp can't recruit one unit of the first type, because it will take both him and the monster $$$0.75$$$ seconds to kill each other. He can recruit two units for the cost of $$$6$$$ coins and kill the monster in $$$0.375$$$ second.Monocarp can recruit one unit of t...
Java 11
standard input
[ "binary search", "brute force", "greedy", "math", "sortings" ]
476c05915a1536cd989c4681c61c9deb
The first line contains two integers $$$n$$$ and $$$C$$$ ($$$1 \le n \le 3 \cdot 10^5$$$; $$$1 \le C \le 10^6$$$) — the number of types of units and the amount of coins Monocarp has before each battle. The $$$i$$$-th of the next $$$n$$$ lines contains three integers $$$c_i, d_i$$$ and $$$h_i$$$ ($$$1 \le c_i \le C$$$; ...
2,000
Print $$$m$$$ integers. For each monster, print the minimum amount of coins Monocarp has to spend to kill that monster. If this amount is greater than $$$C$$$, then print $$$-1$$$.
standard output
PASSED
fc4b17d42b3cf33de5399081080be758
train_110.jsonl
1647960300
Monocarp is playing a strategy game. In the game, he recruits a squad to fight monsters. Before each battle, Monocarp has $$$C$$$ coins to spend on his squad.Before each battle starts, his squad is empty. Monocarp chooses one type of units and recruits no more units of that type than he can recruit with $$$C$$$ coins.T...
256 megabytes
import java.io.*; import java.util.*; /** * A simple template for competitive programming problems. */ public class Solution { //InputReader in = new InputReader("input.txt"); final InputReader in = new InputReader(System.in); final PrintWriter out = new PrintWriter(System.out); static fi...
Java
["3 10\n3 4 6\n5 5 5\n10 3 4\n3\n8 3\n5 4\n10 15", "5 15\n14 10 3\n9 2 2\n10 4 3\n7 3 5\n4 3 1\n6\n11 2\n1 1\n4 7\n2 1\n1 14\n3 3", "5 13\n13 1 9\n6 4 5\n12 18 4\n9 13 2\n5 4 5\n2\n16 3\n6 2"]
4 seconds
["5 3 -1", "14 4 14 4 7 7", "12 5"]
NoteConsider the first monster of the first example.Monocarp can't recruit one unit of the first type, because it will take both him and the monster $$$0.75$$$ seconds to kill each other. He can recruit two units for the cost of $$$6$$$ coins and kill the monster in $$$0.375$$$ second.Monocarp can recruit one unit of t...
Java 11
standard input
[ "binary search", "brute force", "greedy", "math", "sortings" ]
476c05915a1536cd989c4681c61c9deb
The first line contains two integers $$$n$$$ and $$$C$$$ ($$$1 \le n \le 3 \cdot 10^5$$$; $$$1 \le C \le 10^6$$$) — the number of types of units and the amount of coins Monocarp has before each battle. The $$$i$$$-th of the next $$$n$$$ lines contains three integers $$$c_i, d_i$$$ and $$$h_i$$$ ($$$1 \le c_i \le C$$$; ...
2,000
Print $$$m$$$ integers. For each monster, print the minimum amount of coins Monocarp has to spend to kill that monster. If this amount is greater than $$$C$$$, then print $$$-1$$$.
standard output
PASSED
f6a5e87846bf83b60facab9c9ba58f9d
train_110.jsonl
1647960300
Monocarp is playing a strategy game. In the game, he recruits a squad to fight monsters. Before each battle, Monocarp has $$$C$$$ coins to spend on his squad.Before each battle starts, his squad is empty. Monocarp chooses one type of units and recruits no more units of that type than he can recruit with $$$C$$$ coins.T...
256 megabytes
import java.io.*; import java.util.*; public class CF1657D extends PrintWriter { CF1657D() { super(System.out, true); } Scanner sc = new Scanner(System.in); public static void main(String[] $) { CF1657D o = new CF1657D(); o.main(); o.flush(); } static final long INF = 0x3f3f3f3f3f3f3f3fL; void main() { int ...
Java
["3 10\n3 4 6\n5 5 5\n10 3 4\n3\n8 3\n5 4\n10 15", "5 15\n14 10 3\n9 2 2\n10 4 3\n7 3 5\n4 3 1\n6\n11 2\n1 1\n4 7\n2 1\n1 14\n3 3", "5 13\n13 1 9\n6 4 5\n12 18 4\n9 13 2\n5 4 5\n2\n16 3\n6 2"]
4 seconds
["5 3 -1", "14 4 14 4 7 7", "12 5"]
NoteConsider the first monster of the first example.Monocarp can't recruit one unit of the first type, because it will take both him and the monster $$$0.75$$$ seconds to kill each other. He can recruit two units for the cost of $$$6$$$ coins and kill the monster in $$$0.375$$$ second.Monocarp can recruit one unit of t...
Java 11
standard input
[ "binary search", "brute force", "greedy", "math", "sortings" ]
476c05915a1536cd989c4681c61c9deb
The first line contains two integers $$$n$$$ and $$$C$$$ ($$$1 \le n \le 3 \cdot 10^5$$$; $$$1 \le C \le 10^6$$$) — the number of types of units and the amount of coins Monocarp has before each battle. The $$$i$$$-th of the next $$$n$$$ lines contains three integers $$$c_i, d_i$$$ and $$$h_i$$$ ($$$1 \le c_i \le C$$$; ...
2,000
Print $$$m$$$ integers. For each monster, print the minimum amount of coins Monocarp has to spend to kill that monster. If this amount is greater than $$$C$$$, then print $$$-1$$$.
standard output
PASSED
82d4000af7b24c70c6b73d66704fbd97
train_110.jsonl
1647960300
Monocarp is playing a strategy game. In the game, he recruits a squad to fight monsters. Before each battle, Monocarp has $$$C$$$ coins to spend on his squad.Before each battle starts, his squad is empty. Monocarp chooses one type of units and recruits no more units of that type than he can recruit with $$$C$$$ coins.T...
256 megabytes
/* "Everything in the universe is balanced. Every disappointment you face in life will be balanced by something good for you! Keep going, never give up." Just have Patience + 1... */ import java.util.*; import java.lang.*; ...
Java
["3 10\n3 4 6\n5 5 5\n10 3 4\n3\n8 3\n5 4\n10 15", "5 15\n14 10 3\n9 2 2\n10 4 3\n7 3 5\n4 3 1\n6\n11 2\n1 1\n4 7\n2 1\n1 14\n3 3", "5 13\n13 1 9\n6 4 5\n12 18 4\n9 13 2\n5 4 5\n2\n16 3\n6 2"]
4 seconds
["5 3 -1", "14 4 14 4 7 7", "12 5"]
NoteConsider the first monster of the first example.Monocarp can't recruit one unit of the first type, because it will take both him and the monster $$$0.75$$$ seconds to kill each other. He can recruit two units for the cost of $$$6$$$ coins and kill the monster in $$$0.375$$$ second.Monocarp can recruit one unit of t...
Java 11
standard input
[ "binary search", "brute force", "greedy", "math", "sortings" ]
476c05915a1536cd989c4681c61c9deb
The first line contains two integers $$$n$$$ and $$$C$$$ ($$$1 \le n \le 3 \cdot 10^5$$$; $$$1 \le C \le 10^6$$$) — the number of types of units and the amount of coins Monocarp has before each battle. The $$$i$$$-th of the next $$$n$$$ lines contains three integers $$$c_i, d_i$$$ and $$$h_i$$$ ($$$1 \le c_i \le C$$$; ...
2,000
Print $$$m$$$ integers. For each monster, print the minimum amount of coins Monocarp has to spend to kill that monster. If this amount is greater than $$$C$$$, then print $$$-1$$$.
standard output