exec_outcome
stringclasses 1
value | code_uid
stringlengths 32
32
| file_name
stringclasses 111
values | prob_desc_created_at
stringlengths 10
10
| prob_desc_description
stringlengths 63
3.8k
| prob_desc_memory_limit
stringclasses 18
values | source_code
stringlengths 117
65.5k
| lang_cluster
stringclasses 1
value | prob_desc_sample_inputs
stringlengths 2
802
| prob_desc_time_limit
stringclasses 27
values | prob_desc_sample_outputs
stringlengths 2
796
| prob_desc_notes
stringlengths 4
3k
⌀ | lang
stringclasses 5
values | prob_desc_input_from
stringclasses 3
values | tags
sequencelengths 0
11
| src_uid
stringlengths 32
32
| prob_desc_input_spec
stringlengths 28
2.37k
⌀ | difficulty
int64 -1
3.5k
⌀ | prob_desc_output_spec
stringlengths 17
1.47k
⌀ | prob_desc_output_to
stringclasses 3
values | hidden_unit_tests
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PASSED | d5daa818f71ed93ca18038d56f906f21 | train_000.jsonl | 1593873900 | This is an interactive problem.Anton and Harris are playing a game to decide which of them is the king of problemsetting.There are three piles of stones, initially containing $$$a$$$, $$$b$$$, and $$$c$$$ stones, where $$$a$$$, $$$b$$$, and $$$c$$$ are distinct positive integers. On each turn of the game, the following sequence of events takes place: The first player chooses a positive integer $$$y$$$ and provides it to the second player. The second player adds $$$y$$$ stones to one of the piles, with the condition that he cannot choose the same pile in two consecutive turns. The second player loses if, at any point, two of the piles contain the same number of stones. The first player loses if $$$1000$$$ turns have passed without the second player losing.Feeling confident in his skills, Anton decided to let Harris choose whether he wants to go first or second. Help Harris defeat Anton and become the king of problemsetting! | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Input in = new Input(inputStream);
PrintWriter out = new PrintWriter(outputStream);
FIntegerGame solver = new FIntegerGame();
solver.solve(1, in, out);
out.close();
}
static class FIntegerGame {
public void solve(int testNumber, Input in, PrintWriter out) {
long[] arr = new long[] {in.nextInt(), in.nextInt(), in.nextInt()};
out.println("First");
out.flush();
int large = 0, ot1 = -1, ot2 = -1;
if(arr[1]>arr[0]&&arr[1]>arr[2]) {
large = 1;
}else if(arr[2]>arr[0]&&arr[2]>arr[1]) {
large = 2;
}
for(int i = 0; i<3; i++) {
if(i!=large) {
if(ot1==-1) {
ot1 = i;
}else {
ot2 = i;
}
}
}
long y = 2*arr[large]-arr[ot1]-arr[ot2];
out.println(y);
out.flush();
int response = in.nextInt()-1;
if(response!=large) {
out.println(arr[large]-arr[response==ot1 ? ot2 : ot1]);
out.flush();
response = in.nextInt();
if(response==0) {
System.exit(0);
}else {
System.out.println("The judge is trolling");
}
}else {
arr[large] += y;
out.println(2*arr[large]-arr[ot1]-arr[ot2]);
out.flush();
response = in.nextInt()-1;
out.println(arr[large]-arr[response==ot1 ? ot2 : ot1]);
out.flush();
response = in.nextInt();
if(response==0) {
System.exit(0);
}else {
System.out.println("The judge is trolling");
}
}
}
}
static class Input {
BufferedReader br;
StringTokenizer st;
public Input(InputStream is) {
br = new BufferedReader(new InputStreamReader(is));
try {
st = new StringTokenizer(br.readLine());
}catch(IOException e) {
e.printStackTrace();
}
}
public boolean hasNext() {
try {
while(!st.hasMoreTokens()) {
String s = br.readLine();
if(s==null) {
return false;
}
st = new StringTokenizer(s);
}
return true;
}catch(Exception e) {
return false;
}
}
public String next() {
if(!hasNext()) {
throw new InputMismatchException();
}
return st.nextToken("\r\n\t\f ");
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| Java | ["5 2 6\n\n\n3\n\n0"] | 1 second | ["First\n2\n\n3"] | NoteIn the sample input, the piles initially have $$$5$$$, $$$2$$$, and $$$6$$$ stones. Harris decides to go first and provides the number $$$2$$$ to Anton. Anton adds $$$2$$$ stones to the third pile, which results in $$$5$$$, $$$2$$$, and $$$8$$$.In the next turn, Harris chooses $$$3$$$. Note that Anton cannot add the stones to the third pile since he chose the third pile in the previous turn. Anton realizes that he has no valid moves left and reluctantly recognizes Harris as the king. | Java 11 | standard input | [
"math",
"constructive algorithms",
"games",
"interactive"
] | 351c6fb0a9d1bbb29387c5b7ce8c7f28 | The first line of input contains three distinct positive integers $$$a$$$, $$$b$$$, and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) — the initial number of stones in piles $$$1$$$, $$$2$$$, and $$$3$$$ respectively. | 2,600 | null | standard output | |
PASSED | 0ac9a251b47d2a96dddcf24ad71660eb | train_000.jsonl | 1593873900 | This is an interactive problem.Anton and Harris are playing a game to decide which of them is the king of problemsetting.There are three piles of stones, initially containing $$$a$$$, $$$b$$$, and $$$c$$$ stones, where $$$a$$$, $$$b$$$, and $$$c$$$ are distinct positive integers. On each turn of the game, the following sequence of events takes place: The first player chooses a positive integer $$$y$$$ and provides it to the second player. The second player adds $$$y$$$ stones to one of the piles, with the condition that he cannot choose the same pile in two consecutive turns. The second player loses if, at any point, two of the piles contain the same number of stones. The first player loses if $$$1000$$$ turns have passed without the second player losing.Feeling confident in his skills, Anton decided to let Harris choose whether he wants to go first or second. Help Harris defeat Anton and become the king of problemsetting! | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
public class F {
public static void main(String[] args)throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
long a = sc.nextInt();
long b = sc.nextInt();
long c = sc.nextInt();
long query = 10000000000L;
System.out.println("First");
System.out.println(query);
int idx = sc.nextInt();
if(idx==1) {
a+=query;
System.out.println((a-b-(c-a)));
int ok = sc.nextInt();
if(ok==2) {
System.out.println(Math.abs(c-a));
}else {
System.out.println(Math.abs(a-b));
}
}else if(idx==2) {
b+=query;
System.out.println(b-a-(c-b));
int ok = sc.nextInt();
if(ok==1) {
System.out.println(Math.abs(c-b));
}else {
System.out.println(Math.abs(b-a));
}
}else if(idx==3) {
c+=query;
System.out.println(c-a-(b-c));
int ok = sc.nextInt();
if(ok==1) {
System.out.println(Math.abs(b-c));
}else {
System.out.println(Math.abs(c-a));
}
}
idx = sc.nextInt();
out.close();
}
static class FastIO {
InputStream dis;
byte[] buffer = new byte[1 << 17];
int pointer = 0;
public FastIO(String fileName) throws IOException {
dis = new FileInputStream(fileName);
}
public FastIO(InputStream is) throws IOException {
dis = is;
}
int nextInt() throws IOException {
int ret = 0;
byte b;
do {
b = nextByte();
} while (b <= ' ');
boolean negative = false;
if (b == '-') {
negative = true;
b = nextByte();
}
while (b >= '0' && b <= '9') {
ret = 10 * ret + b - '0';
b = nextByte();
}
return (negative) ? -ret : ret;
}
long nextLong() throws IOException {
long ret = 0;
byte b;
do {
b = nextByte();
} while (b <= ' ');
boolean negative = false;
if (b == '-') {
negative = true;
b = nextByte();
}
while (b >= '0' && b <= '9') {
ret = 10 * ret + b - '0';
b = nextByte();
}
return (negative) ? -ret : ret;
}
byte nextByte() throws IOException {
if (pointer == buffer.length) {
dis.read(buffer, 0, buffer.length);
pointer = 0;
}
return buffer[pointer++];
}
String next() throws IOException {
StringBuffer ret = new StringBuffer();
byte b;
do {
b = nextByte();
} while (b <= ' ');
while (b > ' ') {
ret.appendCodePoint(b);
b = nextByte();
}
return ret.toString();
}
}
}
| Java | ["5 2 6\n\n\n3\n\n0"] | 1 second | ["First\n2\n\n3"] | NoteIn the sample input, the piles initially have $$$5$$$, $$$2$$$, and $$$6$$$ stones. Harris decides to go first and provides the number $$$2$$$ to Anton. Anton adds $$$2$$$ stones to the third pile, which results in $$$5$$$, $$$2$$$, and $$$8$$$.In the next turn, Harris chooses $$$3$$$. Note that Anton cannot add the stones to the third pile since he chose the third pile in the previous turn. Anton realizes that he has no valid moves left and reluctantly recognizes Harris as the king. | Java 11 | standard input | [
"math",
"constructive algorithms",
"games",
"interactive"
] | 351c6fb0a9d1bbb29387c5b7ce8c7f28 | The first line of input contains three distinct positive integers $$$a$$$, $$$b$$$, and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) — the initial number of stones in piles $$$1$$$, $$$2$$$, and $$$3$$$ respectively. | 2,600 | null | standard output | |
PASSED | 7134a43ea3e4045541741b0707e6e9f7 | train_000.jsonl | 1593873900 | This is an interactive problem.Anton and Harris are playing a game to decide which of them is the king of problemsetting.There are three piles of stones, initially containing $$$a$$$, $$$b$$$, and $$$c$$$ stones, where $$$a$$$, $$$b$$$, and $$$c$$$ are distinct positive integers. On each turn of the game, the following sequence of events takes place: The first player chooses a positive integer $$$y$$$ and provides it to the second player. The second player adds $$$y$$$ stones to one of the piles, with the condition that he cannot choose the same pile in two consecutive turns. The second player loses if, at any point, two of the piles contain the same number of stones. The first player loses if $$$1000$$$ turns have passed without the second player losing.Feeling confident in his skills, Anton decided to let Harris choose whether he wants to go first or second. Help Harris defeat Anton and become the king of problemsetting! | 256 megabytes | //package global9;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
public class F2 {
Scanner in;
PrintWriter out;
String INPUT = "";
void solve()
{
int n = 3;
long[] a = new long[n];
for(int i = 0;i < n;i++) {
a[i] = ni();
}
out.println("First");
out.flush();
long m = 0;
for(long v : a) {
m = Math.max(m, v);
}
out.println(m);
out.flush();
int w = ni()-1;
if(w == -1)return;
a[w] += m;
long max = a[w];
// a b c
// 2c-a-b
out.println(2*max-(a[0]+a[1]+a[2]-a[w]));
out.flush();
int t = ni()-1;
if(t == -1)return;
a[t] += 2*max-(a[0]+a[1]+a[2]-a[w]);
Arrays.sort(a);
out.println(a[1] - a[0]);
out.flush();
}
void run() throws Exception
{
in = oj ? new Scanner(System.in) : new Scanner(INPUT);
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
tr(System.currentTimeMillis()-s+"ms");
}
public static void main(String[] args) throws Exception
{
new F2().run();
}
int ni() { return Integer.parseInt(in.next()); }
long nl() { return Long.parseLong(in.next()); }
double nd() { return Double.parseDouble(in.next()); }
boolean oj = System.getProperty("ONLINE_JUDGE") != null;
void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}
| Java | ["5 2 6\n\n\n3\n\n0"] | 1 second | ["First\n2\n\n3"] | NoteIn the sample input, the piles initially have $$$5$$$, $$$2$$$, and $$$6$$$ stones. Harris decides to go first and provides the number $$$2$$$ to Anton. Anton adds $$$2$$$ stones to the third pile, which results in $$$5$$$, $$$2$$$, and $$$8$$$.In the next turn, Harris chooses $$$3$$$. Note that Anton cannot add the stones to the third pile since he chose the third pile in the previous turn. Anton realizes that he has no valid moves left and reluctantly recognizes Harris as the king. | Java 11 | standard input | [
"math",
"constructive algorithms",
"games",
"interactive"
] | 351c6fb0a9d1bbb29387c5b7ce8c7f28 | The first line of input contains three distinct positive integers $$$a$$$, $$$b$$$, and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) — the initial number of stones in piles $$$1$$$, $$$2$$$, and $$$3$$$ respectively. | 2,600 | null | standard output | |
PASSED | df84a1e067bcfca08c917db4531d4878 | train_000.jsonl | 1593873900 | This is an interactive problem.Anton and Harris are playing a game to decide which of them is the king of problemsetting.There are three piles of stones, initially containing $$$a$$$, $$$b$$$, and $$$c$$$ stones, where $$$a$$$, $$$b$$$, and $$$c$$$ are distinct positive integers. On each turn of the game, the following sequence of events takes place: The first player chooses a positive integer $$$y$$$ and provides it to the second player. The second player adds $$$y$$$ stones to one of the piles, with the condition that he cannot choose the same pile in two consecutive turns. The second player loses if, at any point, two of the piles contain the same number of stones. The first player loses if $$$1000$$$ turns have passed without the second player losing.Feeling confident in his skills, Anton decided to let Harris choose whether he wants to go first or second. Help Harris defeat Anton and become the king of problemsetting! | 256 megabytes |
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
try{
PrintWriter out = new PrintWriter(System.out);
long[] a=new long[3];
for(int i=0;i<3;i++){
a[i]=in.nextInt();
}
out.println("First");
out.flush();
out.println("100000000000");
out.flush();
int id=in.nextInt();
a[id-1]+=100_000_000_000L;
Integer[] pos=new Integer[]{0,1,2};
Arrays.sort(pos,(p,q)->{
return Long.compare(a[p],a[q]);
});
long y=a[pos[2]]*2-a[pos[0]]-a[pos[1]];
out.println(y);
out.flush();
id=in.nextInt();
if(id==pos[0]+1){
out.println(a[pos[2]]-a[pos[1]]);
out.flush();
}else{
out.println(a[pos[2]]-a[pos[0]]);
out.flush();
}
out.flush();
id=in.nextInt();
// System.ot.println();
}catch(Exception e){
System.out.println(e);
}
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static FastReader in = new FastReader();
} | Java | ["5 2 6\n\n\n3\n\n0"] | 1 second | ["First\n2\n\n3"] | NoteIn the sample input, the piles initially have $$$5$$$, $$$2$$$, and $$$6$$$ stones. Harris decides to go first and provides the number $$$2$$$ to Anton. Anton adds $$$2$$$ stones to the third pile, which results in $$$5$$$, $$$2$$$, and $$$8$$$.In the next turn, Harris chooses $$$3$$$. Note that Anton cannot add the stones to the third pile since he chose the third pile in the previous turn. Anton realizes that he has no valid moves left and reluctantly recognizes Harris as the king. | Java 11 | standard input | [
"math",
"constructive algorithms",
"games",
"interactive"
] | 351c6fb0a9d1bbb29387c5b7ce8c7f28 | The first line of input contains three distinct positive integers $$$a$$$, $$$b$$$, and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) — the initial number of stones in piles $$$1$$$, $$$2$$$, and $$$3$$$ respectively. | 2,600 | null | standard output | |
PASSED | f4357c657f57f07d7591b21676becf65 | train_000.jsonl | 1593873900 | This is an interactive problem.Anton and Harris are playing a game to decide which of them is the king of problemsetting.There are three piles of stones, initially containing $$$a$$$, $$$b$$$, and $$$c$$$ stones, where $$$a$$$, $$$b$$$, and $$$c$$$ are distinct positive integers. On each turn of the game, the following sequence of events takes place: The first player chooses a positive integer $$$y$$$ and provides it to the second player. The second player adds $$$y$$$ stones to one of the piles, with the condition that he cannot choose the same pile in two consecutive turns. The second player loses if, at any point, two of the piles contain the same number of stones. The first player loses if $$$1000$$$ turns have passed without the second player losing.Feeling confident in his skills, Anton decided to let Harris choose whether he wants to go first or second. Help Harris defeat Anton and become the king of problemsetting! | 256 megabytes | import java.io.*;
import java.text.*;
import java.util.*;
import java.math.*;
public class template {
public static void main(String[] args) throws Exception {
new template().run();
}
public void run() throws Exception {
FastScanner f = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
///
long[] a = {f.nextLong(), f.nextLong(), f.nextLong()};
long s = a[0] + a[1] + a[2];
out.println("First\n10000000000");
out.flush();
int i = f.nextInt()-1;
a[i] += 10000000000L;
out.println(a[i]*3-10000000000L-s);
out.flush();
int j = f.nextInt()-1;
a[j] += a[i]*3-10000000000L-s;
out.println(a[j]-a[i]);
out.flush();
f.nextInt();
///
out.flush();
}
///
static class FastScanner {
public BufferedReader reader;
public StringTokenizer tokenizer;
public FastScanner() {
reader = new BufferedReader(new InputStreamReader(System.in), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() {
try {
return reader.readLine();
} catch(IOException e) {
throw new RuntimeException(e);
}
}
}
}
| Java | ["5 2 6\n\n\n3\n\n0"] | 1 second | ["First\n2\n\n3"] | NoteIn the sample input, the piles initially have $$$5$$$, $$$2$$$, and $$$6$$$ stones. Harris decides to go first and provides the number $$$2$$$ to Anton. Anton adds $$$2$$$ stones to the third pile, which results in $$$5$$$, $$$2$$$, and $$$8$$$.In the next turn, Harris chooses $$$3$$$. Note that Anton cannot add the stones to the third pile since he chose the third pile in the previous turn. Anton realizes that he has no valid moves left and reluctantly recognizes Harris as the king. | Java 11 | standard input | [
"math",
"constructive algorithms",
"games",
"interactive"
] | 351c6fb0a9d1bbb29387c5b7ce8c7f28 | The first line of input contains three distinct positive integers $$$a$$$, $$$b$$$, and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) — the initial number of stones in piles $$$1$$$, $$$2$$$, and $$$3$$$ respectively. | 2,600 | null | standard output | |
PASSED | c8f43d2ea8d0b5802a65c8b6dcdd9144 | train_000.jsonl | 1593873900 | This is an interactive problem.Anton and Harris are playing a game to decide which of them is the king of problemsetting.There are three piles of stones, initially containing $$$a$$$, $$$b$$$, and $$$c$$$ stones, where $$$a$$$, $$$b$$$, and $$$c$$$ are distinct positive integers. On each turn of the game, the following sequence of events takes place: The first player chooses a positive integer $$$y$$$ and provides it to the second player. The second player adds $$$y$$$ stones to one of the piles, with the condition that he cannot choose the same pile in two consecutive turns. The second player loses if, at any point, two of the piles contain the same number of stones. The first player loses if $$$1000$$$ turns have passed without the second player losing.Feeling confident in his skills, Anton decided to let Harris choose whether he wants to go first or second. Help Harris defeat Anton and become the king of problemsetting! | 256 megabytes | import java.util.*;
public class Question6 {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
long[] arr = new long[3];
arr[0] = sc.nextLong();
arr[1] = sc.nextLong();
arr[2] = sc.nextLong();
long max = -1;long other = -1;
long maxi = 0;long min = -1;
if(arr[0] >= arr[1] && arr[0]>= arr[2]) {
max = arr[0];
maxi = 1;
other = arr[1] + arr[2];
if(arr[1] < arr[2])min = arr[1];
else min = arr[2];
}
else if(arr[1] >= arr[0] && arr[1] >= arr[2]) {
max = arr[1];
maxi = 2;
other = arr[0] + arr[2];
if(arr[0] < arr[2])min = arr[0];
else min = arr[2];
}
else {
max = arr[2];
maxi = 3;
other = arr[0] + arr[1];
if(arr[0] < arr[1])min = arr[0];
else min = arr[1];
}
long val = (2 * max) - other;
System.out.println("First");
System.out.println(val);
long zx = sc.nextInt();
if(zx == maxi) {
max = max + val;
arr[(int)maxi - 1] = max;
val = (2 * max) - other;
System.out.println(val);
long x = sc.nextInt();
if(x == 1)System.out.println(Math.abs(arr[1] - arr[2]));
else if(x == 2)System.out.println(Math.abs(arr[0] - arr[2]));
else System.out.println(Math.abs(arr[0] - arr[1]));
}
else {
if(zx == 1)System.out.println(Math.abs(arr[1] - arr[2]));
else if(zx == 2)System.out.println(Math.abs(arr[0] - arr[2]));
else System.out.println(Math.abs(arr[0] - arr[1]));
}
}
}
| Java | ["5 2 6\n\n\n3\n\n0"] | 1 second | ["First\n2\n\n3"] | NoteIn the sample input, the piles initially have $$$5$$$, $$$2$$$, and $$$6$$$ stones. Harris decides to go first and provides the number $$$2$$$ to Anton. Anton adds $$$2$$$ stones to the third pile, which results in $$$5$$$, $$$2$$$, and $$$8$$$.In the next turn, Harris chooses $$$3$$$. Note that Anton cannot add the stones to the third pile since he chose the third pile in the previous turn. Anton realizes that he has no valid moves left and reluctantly recognizes Harris as the king. | Java 11 | standard input | [
"math",
"constructive algorithms",
"games",
"interactive"
] | 351c6fb0a9d1bbb29387c5b7ce8c7f28 | The first line of input contains three distinct positive integers $$$a$$$, $$$b$$$, and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) — the initial number of stones in piles $$$1$$$, $$$2$$$, and $$$3$$$ respectively. | 2,600 | null | standard output | |
PASSED | 2dabf5a4f2248b84360eeed60a28568d | train_000.jsonl | 1593873900 | This is an interactive problem.Anton and Harris are playing a game to decide which of them is the king of problemsetting.There are three piles of stones, initially containing $$$a$$$, $$$b$$$, and $$$c$$$ stones, where $$$a$$$, $$$b$$$, and $$$c$$$ are distinct positive integers. On each turn of the game, the following sequence of events takes place: The first player chooses a positive integer $$$y$$$ and provides it to the second player. The second player adds $$$y$$$ stones to one of the piles, with the condition that he cannot choose the same pile in two consecutive turns. The second player loses if, at any point, two of the piles contain the same number of stones. The first player loses if $$$1000$$$ turns have passed without the second player losing.Feeling confident in his skills, Anton decided to let Harris choose whether he wants to go first or second. Help Harris defeat Anton and become the king of problemsetting! | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastReader in = new FastReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
FIntegerGame solver = new FIntegerGame();
solver.solve(1, in, out);
out.close();
}
static class FIntegerGame {
public void solve(int testNumber, FastReader s, PrintWriter out) {
long a = s.nextLong(), b = s.nextLong(), c = s.nextLong();
out.println("First");
out.flush();
func(a, b, c, s, out);
}
private void func(long a, long b, long c, FastReader s, PrintWriter out) {
FIntegerGame.pair[] arr = new FIntegerGame.pair[3];
arr[0] = new FIntegerGame.pair(a, 1);
arr[1] = new FIntegerGame.pair(b, 2);
arr[2] = new FIntegerGame.pair(c, 3);
Arrays.sort(arr);
out.println(2L * arr[2].val - arr[1].val - arr[0].val);
out.flush();
int curr = s.nextInt();
if (curr == arr[0].ind) {
out.println(arr[2].val - arr[1].val);
out.flush();
int curr1 = s.nextInt();
} else if (curr == arr[1].ind) {
out.println(arr[2].val - arr[0].val);
out.flush();
int curr1 = s.nextInt();
} else {
arr[2].val = 3L * arr[2].val - arr[1].val - arr[0].val;
out.println(2L * arr[2].val - arr[1].val - arr[0].val);
out.flush();
int currN = s.nextInt();
if (currN == arr[0].ind) {
out.println(arr[2].val - arr[1].val);
out.flush();
int curr1 = s.nextInt();
} else {
out.println(arr[2].val - arr[0].val);
out.flush();
int curr1 = s.nextInt();
}
}
}
private static class pair implements Comparable<FIntegerGame.pair> {
long val;
long ind;
public pair(long val, int ind) {
this.val = val;
this.ind = ind;
}
public int compareTo(FIntegerGame.pair o) {
return Long.compare(this.val, o.val);
}
}
}
static class FastReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private FastReader.SpaceCharFilter filter;
public FastReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
| Java | ["5 2 6\n\n\n3\n\n0"] | 1 second | ["First\n2\n\n3"] | NoteIn the sample input, the piles initially have $$$5$$$, $$$2$$$, and $$$6$$$ stones. Harris decides to go first and provides the number $$$2$$$ to Anton. Anton adds $$$2$$$ stones to the third pile, which results in $$$5$$$, $$$2$$$, and $$$8$$$.In the next turn, Harris chooses $$$3$$$. Note that Anton cannot add the stones to the third pile since he chose the third pile in the previous turn. Anton realizes that he has no valid moves left and reluctantly recognizes Harris as the king. | Java 11 | standard input | [
"math",
"constructive algorithms",
"games",
"interactive"
] | 351c6fb0a9d1bbb29387c5b7ce8c7f28 | The first line of input contains three distinct positive integers $$$a$$$, $$$b$$$, and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) — the initial number of stones in piles $$$1$$$, $$$2$$$, and $$$3$$$ respectively. | 2,600 | null | standard output | |
PASSED | 29a54382d71eb71fdb252ca56928c7ef | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.util.Scanner;
public class DoorsBreaking {
public static void main(String [] args)
{ Scanner s = new Scanner(System.in);
int n = s.nextInt();
int x = s.nextInt();
int y = s.nextInt();
int arr[] = new int[n];
for (int i = 0; i < n; i++) {// for reading array
arr[i] = s.nextInt();
}
if(x>y)
System.out.println(n);
else {
int c=0;
for(int i=0;i<n;i++){
if(arr[i] <= x)
c++;
}
System.out.println((c+1)/2);
}
}
}
| Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 8008936106188faa8455fb230b3b41d8 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.util.*;
import java.io.*;
public class Main{
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader inp = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Solver solver = new Solver();
solver.solve(inp, out);
out.close();
}
static class Solver {
class Node implements Comparable<Node>{
int i;
long c;
Node(int i,long c)
{
this.i=i;
this.c=c;
}
public int compareTo(Node n)
{
return Long.compare(this.c, n.c);
}
}
public boolean done(int[] sp,int[] par)
{
int root;
root=findSet(sp[0],par);
for(int i=1;i<sp.length;i++)
{
if(root!=findSet(sp[i], par))
return false;
}
return true;
}
public int findSet(int i,int[] par)
{
int x =i;
boolean flag =false;
while(par[i]>=0)
{
flag = true;
i=par[i];
}
if(flag)
par[x]=i;
return i;
}
public void unionSet(int i,int j,int[] par)
{
int x = findSet(i, par);
int y = findSet(j, par);
if(x<y)
{
par[y]=x;
}
else
{
par[x]=y;
}
}
public long pow(long a, long b, long MOD) {
if (b == 0) {
return 1;
}
if (b == 1) {
return a;
}
long val = pow(a, b / 2, MOD);
if (b % 2 == 0) {
return val * val % MOD;
} else {
return val * (val * a % MOD) % MOD;
}
}
public void minPrimeFactor(int n,int[] s)
{
boolean prime[] = new boolean[n+1];
Arrays.fill(prime, true);
s[1]=1;
s[2]=2;
for(int i=4;i<=n;i+=2)
{
prime[i]=false;
s[i]=2;
}
for(int i=3;i<=n;i+=2)
{
if(prime[i])
{
s[i]=i;
for(int j=2*i;j<=n;j+=i)
{
prime[j]=false;
s[j]=i;
}
}
}
}
// public void findAllPrime(int n,ArrayList<Node> al,int s[])
// {
// int curr = s[n];
// int cnt = 1;
// while(n>1)
// {
// n/=s[n];
// if(curr==s[n])
// {
// cnt++;
// continue;
// }
// Node n1 = new Node(curr,cnt);
// al.add(n1);
// curr=s[n];
// cnt=1;
// }
// }
public int binarySearch(int n,int k)
{
int left=1;
int right=100000000+5;
int ans=0;
while(left<=right)
{
int mid = (left+right)/2;
if(n/mid>=k)
{
left = mid+1;
ans=mid;
}
else
{
right=mid-1;
}
}
return ans;
}
public boolean checkPallindrom(String s)
{
char ch[] = s.toCharArray();
for(int i=0;i<s.length()/2;i++)
{
if(ch[i]!=ch[s.length()-1-i])
return false;
}
return true;
}
public void dfs_util(ArrayList<Integer>[] al,boolean vis[],int x,int cnt[],int sts[],int fts[],long sv[])
{
vis[x] = true;
long min=Long.MAX_VALUE;
sts[cnt[0]]=x+1;
for(int i=0;i<al[x].size();i++)
{
if(!vis[al[x].get(i)])
{
cnt[0]++;
dfs_util(al, vis, al[x].get(i),cnt,sts,fts,sv);
if(sv[al[x].get(i)]<min&&sv[al[x].get(i)]!=-1)
{
min=sv[al[x].get(i)];
}
}
}
if(sv[x]==-1)
{
if(min==Long.MAX_VALUE)
{
min=-1;
}
sv[x]=min;
}
return ;
}
public void dfs(ArrayList[] al,int sts[],int fts[],long sv[])
{
boolean vis[] = new boolean[al.length];
int cnt[]= new int[2*al.length+2];
for(int i=0;i<al.length;i++)
{
if(!vis[i])
{
dfs_util(al,vis,i,cnt,sts,fts,sv);
}
}
}
public void remove(ArrayList<Integer>[] al,int x)
{
for(int i=0;i<al.length;i++)
{
for(int j=0;j<al[i].size();j++)
{
if(al[i].get(j)==x)
al[i].remove(j);
}
}
}
public int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
public void printDivisors(long n,ArrayList<Long> al)
{
// Note that this loop runs till square root
for (long i=1; i<=Math.sqrt(n); i++)
{
if (n%i==0)
{
// If divisors are equal, print only one
if (n/i == i)
al.add(i);
else // Otherwise print both
al.add(i);
al.add(n/i);
}
}
}
private void solve(InputReader inp, PrintWriter out1) {
int n = inp.nextInt();
int x =inp.nextInt();
int y = inp.nextInt();
int arr[] = new int[n];
for(int i=0;i<n;i++)
{
arr[i] = inp.nextInt();
}
if(x>y)
{
out1.println(n);
}
else
{
int count=0;
for(int i=0;i<n;i++)
{
if(arr[i]<=x)
{
count++;
}
}
if(count%2==0)
{
out1.println(count/2);
}
else
{
out1.println((count/2)+1);
}
}
}
}
static class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
}
class ele{
long value;
long i;
boolean flag;
public ele(long value,long i)
{
this.value = value;
this.i=i;
this.flag = false;
}
}
| Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | ec1d1e1369de4f20dd689adc138f65e5 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.util.*;
public class Main {
static class Data implements Comparable<Data> {
int data, index, color;
public Data(int d, int i) {
data = d;
index = i;
}
@Override
public int compareTo(Data o) {
if (this.data > o.data)
return 1;
else if (this.data < o.data)
return -1;
else
return 0;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int x = sc.nextInt();
int y = sc.nextInt();
int arr[] = new int[n];
PriorityQueue<Integer> pr = new PriorityQueue<>();
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
pr.add(arr[i]);
}
if (x > y || (n == 1 && x >= arr[0])) {
System.out.println(n);
} else if (n == 1 && x < arr[0]) {
System.out.println(0);
} else {
int count = 0;
while (!pr.isEmpty()) {
int z = pr.poll();
z -= x;
if (z > 0) {
break;
}
count++;
int save = pr.poll();
save += y;
pr.add(save);
}
System.out.println(count);
}
}
} | Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 95a6aae1d555864645ec8dd06f9fc332 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class DoorBreakAndRep {
public static void main(String args[]) throws IOException {
FastReader in = new FastReader();
OutputStream outputStream = System.out;
PrintWriter out = new PrintWriter(outputStream);
Task.solve(in, out);
out.close();
}
static class Task {
public static void solve(FastReader in, PrintWriter out) {
int n = in.nextInt(),x = in.nextInt(),y=in.nextInt();
int[] a = new int[n];
int m=0;
for(int i=0;i<n;i++){
a[i] = in.nextInt();
if(a[i]<=x){
m++;
}
}
if(x>y){
System.out.println(n);
}else{
System.out.println((m+1)/2);
}
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 7f04fc600d7cd2be5e57f1e03cbc2c24 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.util.Scanner;
public class walls {
public static void main(String [] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int x = sc.nextInt();
int y = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
int ans = 0;
if (x > y) {
ans = n;
}
else {
int q = 0;
for (int i = 0; i < n; i++) {
if (arr[i] <= x) {
q++;
}
}
if (q % 2 == 0) {
ans = q / 2;
}else {
ans = (q + 1)/2;
}
}
System.out.println(ans);
}
}
| Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 2bf626d1fced53dc46a065dbeacdd67a | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class DoorsBreakingAndRepairing {
public static void main(String [] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String [] params = br.readLine().trim().split("\\s+");
int n = Integer.parseInt(params[0]);
int x = Integer.parseInt(params[1]);
int y = Integer.parseInt(params[2]);
int [] doors = new int[n];
String [] curDoors = br.readLine().trim().split("\\s+");
for(int i = 0; i<n; i++) {
doors[i] = Integer.parseInt(curDoors[i]);
}
getResult(doors, x, y);
br.close();
}
static void getResult(int [] doors, int x, int y) {
if(x>y) {
System.out.println(doors.length);
return;
}
else {
int res = cleanup(doors, x);
System.out.println((res+1)/2);
}
}
static int cleanup(int [] doors, int x) {
int ret = 0;
for(int cur:doors) {
if(cur<=x) {
ret++;
}
}
return ret;
}
}
| Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | a828749f613939694147fb7683902ddf | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.util.*;
import java.io.*;
import java.lang.*;
public class Solution
{
public static int findMinRec(int arr[], int i,
int sumCalculated,
int sumTotal)
{
if (i == 0)
return Math.abs((sumTotal-sumCalculated) -
sumCalculated);
return Math.min(findMinRec(arr, i - 1, sumCalculated
+ arr[i-1], sumTotal),
findMinRec(arr, i-1,
sumCalculated, sumTotal));
}
public static int findMin(int arr[], int n)
{
int sumTotal = 0;
for (int i = 0; i < n; i++)
sumTotal += arr[i];
return findMinRec(arr, n, 0, sumTotal);
}
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int n=s.nextInt();
int x=s.nextInt();
int y=s.nextInt();
int arr[]=new int[n];
for(int i=0;i<n;i++)
arr[i]=s.nextInt();
Arrays.sort(arr);
int d=y-x;
if(d<0)
{
pw.println(n);
pw.flush();
pw.close();
}
else
{
int count=0;
ArrayList<Integer>al=new ArrayList<>();
for(int i=0;i<n;i++)
{
if(arr[i]<=x)
count++;
}
if(count%2==1)
count=(count/2)+1;
else
count/=2;
pw.println(count);
pw.flush();
pw.close();}
}
static class InputReader
{
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream)
{
this.stream = stream;
}
public int snext()
{
if (snumChars == -1)
throw new InputMismatchException();
if (curChar >= snumChars)
{
curChar = 0;
try
{
snumChars = stream.read(buf);
}
catch (IOException e)
{
throw new InputMismatchException();
}
if (snumChars <= 0)
return -1;
}
return buf[curChar++];
}
public int nextInt()
{
int c = snext();
while (isSpaceChar(c))
{
c = snext();
}
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = snext();
}
int res = 0;
do
{
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = snext();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong()
{
int c = snext();
while (isSpaceChar(c))
{
c = snext();
}
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = snext();
}
long res = 0;
do
{
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = snext();
} while (!isSpaceChar(c));
return res * sgn;
}
public int[] nextIntArray(int n)
{
int a[] = new int[n];
for (int i = 0; i < n; i++)
{
a[i] = nextInt();
}
return a;
}
public String readString()
{
int c = snext();
while (isSpaceChar(c))
{
c = snext();
}
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = snext();
} while (!isSpaceChar(c));
return res.toString();
}
public String nextLine()
{
int c = snext();
while (isSpaceChar(c))
c = snext();
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = snext();
} while (!isEndOfLine(c));
return res.toString();
}
public boolean isSpaceChar(int c)
{
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
private boolean isEndOfLine(int c)
{
return c == '\n' || c == '\r' || c == -1;
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
}
public static long mod = 1000000007;
public static int d;
public static int p;
public static int q;
public static int[] suffle(int[] a,Random gen)
{
int n = a.length;
for(int i=0;i<n;i++)
{
int ind = gen.nextInt(n-i)+i;
int temp = a[ind];
a[ind] = a[i];
a[i] = temp;
}
return a;
}
public static void swap(int a, int b){
int temp = a;
a = b;
b = temp;
}
public static HashSet<Integer> primeFactorization(int n)
{
HashSet<Integer> a =new HashSet<Integer>();
for(int i=2;i*i<=n;i++)
{
while(n%i==0)
{
a.add(i);
n/=i;
}
}
if(n!=1)
a.add(n);
return a;
}
public static void sieve(boolean[] isPrime,int n)
{
for(int i=1;i<n;i++)
isPrime[i] = true;
isPrime[0] = false;
isPrime[1] = false;
for(int i=2;i*i<n;i++)
{
if(isPrime[i] == true)
{
for(int j=(2*i);j<n;j+=i)
isPrime[j] = false;
}
}
}
public static int GCD(int a,int b)
{
if(b==0)
return a;
else
return GCD(b,a%b);
}
public static long GCD(long a,long b)
{
if(b==0)
return a;
else
return GCD(b,a%b);
}
public static void extendedEuclid(int A,int B)
{
if(B==0)
{
d = A;
p = 1 ;
q = 0;
}
else
{
extendedEuclid(B, A%B);
int temp = p;
p = q;
q = temp - (A/B)*q;
}
}
public static long LCM(long a,long b)
{
return (a*b)/GCD(a,b);
}
public static int LCM(int a,int b)
{
return (a*b)/GCD(a,b);
}
public static int binaryExponentiation(int x,int n)
{
int result=1;
while(n>0)
{
if(n % 2 ==1)
result=result * x;
x=x*x;
n=n/2;
}
return result;
}
public static long binaryExponentiation(long x,long n)
{
long result=1;
while(n>0)
{
if(n % 2 ==1)
result=result * x;
x=x*x;
n=n/2;
}
return result;
}
public static int modularExponentiation(int x,int n,int M)
{
int result=1;
while(n>0)
{
if(n % 2 ==1)
result=(result * x)%M;
x=(x*x)%M;
n=n/2;
}
return result;
}
public static long modularExponentiation(long x,long n,long M)
{
long result=1;
while(n>0)
{
if(n % 2 ==1)
result=(result * x)%M;
x=(x*x)%M;
n=n/2;
}
return result;
}
public static int modInverse(int A,int M)
{
return modularExponentiation(A,M-2,M);
}
public static long modInverse(long A,long M)
{
return modularExponentiation(A,M-2,M);
}
public static boolean isPrime(int n)
{
if (n <= 1) return false;
if (n <= 3) return true;
if (n%2 == 0 || n%3 == 0)
return false;
for (int i=5; i*i<=n; i=i+6)
{
if (n%i == 0 || n%(i+2) == 0)
return false;
}
return true;
}
static class pair implements Comparable<pair>
{
Integer x, y;
pair(int x,int y)
{
this.x=x;
this.y=y;
}
public int compareTo(pair o) {
int result = x.compareTo(o.x);
if(result==0)
result = y.compareTo(o.y);
return result;
}
public String toString()
{
return x+" "+y;
}
public boolean equals(Object o)
{
if (o instanceof pair)
{
pair p = (pair)o;
return (Math.abs(p.x-x)==0 && Math.abs(p.y-y)==0);
}
return false;
}
public int hashCode()
{
return new Long(x).hashCode()*31 + new Long(y).hashCode();
}
}
} | Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 936fad4c35d4c67b89b20278a2ec55b0 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class solving {
public static void main(String args[])
{
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
int destroy=scan.nextInt();
int make=scan.nextInt();
int ar[]=new int[n];
int once=0;
for(int i=0;i<n;i++)
{
ar[i]=scan.nextInt();
if(ar[i]<=destroy)
{
once++;
}
}
if(destroy>make)
{
System.out.println(n);
return;
}else{
Arrays.sort(ar);
int x=0;
int ans=0;
while(x<n &&ar[x]<=destroy )
{
x+=2;
ans++;
}
System.out.println(ans);
}
}
}
| Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | f1e68c5526c3e9c45ca4846f54063637 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import java.net.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class cf
{
public static void merge(int arr[], int l, int m, int r)
{
int n1 = m - l + 1;
int n2 = r - m;
int L[] = new int [n1];
int R[] = new int [n2];
for (int i=0; i<n1; ++i)
L[i] = arr[l + i];
for (int j=0; j<n2; ++j)
R[j] = arr[m + 1+ j];
int i = 0, j = 0;
int k = l;
while (i < n1 && j < n2)
{
if (L[i] <= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
public static void sort(int arr[], int l, int r)
{
if (l < r)
{
int m = (l+r)/2;
sort(arr, l, m);
sort(arr , m+1, r);
merge(arr, l, m, r);
}
}
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int d=in.nextInt();
int r=in.nextInt();
int[] a=new int[n];
for(int i=0;i<n;i++)
a[i]=in.nextInt();
sort(a,0,n-1);
if(r>=d)
{
int c=0;
for(int i=0;i<n;i++)
if(a[i]<=d)
c++;
else
break;
System.out.println((int)Math.ceil((c*1.0)/2));
}
else
System.out.println(n);
}
} | Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 11007c840d0e7cfca722f82becefa4d2 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.util.*;
import java.io.*;
public class P1102C {
private static void solve() {
int n = nextInt();
int x = nextInt();
int y = nextInt();
if (x > y) {
System.out.println(n);
return;
}
int cnt = 0;
for (int i = 0; i < n; i++) {
int a = nextInt();
if (a <= x) {
cnt++;
}
}
System.out.println((cnt + 1) / 2);
}
private static void run() {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
}
private static StringTokenizer st;
private static BufferedReader br;
private static PrintWriter out;
private static String next() {
while (st == null || !st.hasMoreElements()) {
String s;
try {
s = br.readLine();
} catch (IOException e) {
return null;
}
st = new StringTokenizer(s);
}
return st.nextToken();
}
private static int nextInt() {
return Integer.parseInt(next());
}
private static long nextLong() {
return Long.parseLong(next());
}
public static void main(String[] args) {
run();
}
} | Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | d64991e61398705e1b6ab3c080d648c4 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.util.Scanner;
public class CF1102C {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int x = sc.nextInt();
int y = sc.nextInt();
if(x > y){
System.out.println(n);
} else {
int targetCnt = 0;
for(int i = 0; i < n; i++){
int a = sc.nextInt();
if(a <= x){
targetCnt++;
}
}
int r = targetCnt / 2;
int d = targetCnt % 2;
r = d == 0? r : r + 1;
System.out.println(r);
}
}
} | Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | a8f3986f2c38995d9310a45f1f8879d3 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class CF1102C {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int x = sc.nextInt();
int y = sc.nextInt();
if(x > y){
System.out.println(n);
} else {
int targetCnt = 0;
for(int i = 0; i < n; i++){
int a = sc.nextInt();
if(a <= x){
targetCnt++;
}
}
int r = targetCnt / 2;
int d = targetCnt % 2;
r = d == 0? r : r + 1;
System.out.println(r);
}
}
} | Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 58d67b128873b2e2a0b6fef1ca7fd7f0 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | //package doorbreaking;
import java.util.*;
public class DoorBreaking {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String line[] = input.nextLine().split(" ");
int n = Integer.parseInt(line[0]);
int x = Integer.parseInt(line[1]);
int y = Integer.parseInt(line[2]);
int doors[] = new int[n];
int less = 0;
if(x > y) {
System.out.println(n);
System.exit(0);
}
line = input.nextLine().split(" ");
for(int i=0; i<n; i++) {
doors[i] = Integer.parseInt(line[i]);
if(doors[i] <= x)
less++;
}
if(less % 2 == 1)
less = (less/2) + 1;
else
less = less/2;
System.out.println(less);
}
}
| Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 434da88bcb18289721cdd3934ea5eba0 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.math.BigInteger;
import java.time.chrono.MinguoChronology;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.Queue;
import java.io.BufferedWriter;
import java.io.IOException;
/*
95 999999999999999 1
*/
public class Main
{
static long a,b,c,d,e,f,t,l,r,v,n,m,k,x,y,res=0,len,pow;
static StringBuilder sb,sb1,sb2;
static String s;
static long ar[] = new long[100009];
static long cumu[] = new long[100009];
static int dis[][] = new int[9][9];
//static long cumu[] = new long[150009];
static ArrayList<Long> vi = new ArrayList<>();
boolean fl = true;
public static void main(String[] args)throws IOException
{
MainFastScan scanner = new MainFastScan();
MainFastPrint printer = new MainFastPrint();
n = scanner.nextLong();
long ami = scanner.nextLong();
long salvik = scanner.nextLong();
long cnt = 0;
for(int i=0; i<n; i++)
{
x = scanner.nextLong();
if(x<=ami) cnt++;
}
// System.out.println(cnt);
if(ami>salvik)
{
res = n;
}
else
{
if(cnt%2==0) res = cnt/2;
else res = (cnt/2)+1;
}
printer.print(Long.toString(res));
printer.print("\n");
printer.close();
}
}
class MainFastPrint
{
private final BufferedWriter bw;
public MainFastPrint(){bw=new BufferedWriter(new OutputStreamWriter(System.out));}
public void print(String str)throws IOException{bw.append(str);}
public void printLine(String str)throws IOException{print(str); bw.append("\n");}
public void close()throws IOException{bw.close();}
public void flush() throws IOException {bw.flush();}
}
class MainFastScan
{
private byte[] buf=new byte[1024];
private int index;
private InputStream in;
private int total;
public MainFastScan()
{
in=System.in;
}
public int scan()throws IOException
{
if(total<0)
throw new InputMismatchException();
if(index>=total)
{
index=0;
total=in.read(buf);
if(total<=0)
return -1;
}
return buf[index++];
}
public int nextInt()throws IOException
{
int integer=0;
int n=scan();
while(isWhiteSpace(n)) n=scan();
int neg=1;
if(n=='-')
{
neg=-1;
n=scan();
}
while(!isWhiteSpace(n))
{
if(n>='0'&&n<='9')
{
integer*=10;
integer+=n-'0';
n=scan();
}
else throw new InputMismatchException();
}
return neg*integer;
}
public long nextLong()throws IOException
{
long res=0;
int n = scan();
while(isWhiteSpace(n)) n=scan();
int neg=1;
if(n=='-')
{
neg=-1;
n=scan();
}
while(!isWhiteSpace(n))
{
if(n>='0'&&n<='9')
{
res *= 10;
res += n-'0';
n=scan();
}
else throw new InputMismatchException();
}
return neg*res;
}
public double nextDouble()throws IOException
{
double doub=0;
int n=scan();
while(isWhiteSpace(n)) n=scan();
int neg=1;
if(n=='-')
{
neg=-1;
n=scan();
}
while(!isWhiteSpace(n)&&n!='.')
{
if(n>='0'&&n<='9')
{
doub*=10;
doub+=n-'0';
n=scan();
}
else throw new InputMismatchException();
}
if(n=='.')
{
n=scan();
double temp=1;
while(!isWhiteSpace(n))
{
if(n>='0'&&n<='9')
{
temp/=10;
doub+=(n-'0')*temp;
n=scan();
}
else throw new InputMismatchException();
}
}
return doub*neg;
}
public String nextWord()throws IOException
{
StringBuilder sb=new StringBuilder();
int n=scan();
while(isWhiteSpace(n)) n=scan();
while(!isWhiteSpace(n))
{
sb.append((char)n);
n=scan();
}
return sb.toString();
}
public String nextLine()throws IOException
{
StringBuilder sb=new StringBuilder();
int n=scan();
while(isWhiteSpaceLine(n)) n=scan();
while(!isWhiteSpaceLine(n))
{
sb.append((char)n);
n=scan();
}
return sb.toString();
}
private boolean isWhiteSpace(int n)
{
if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
return true;
return false;
}
private boolean isWhiteSpaceLine(int n)
{
if(n=='\n'||n=='\r'||n=='\t'||n==-1)
return true;
return false;
}
} | Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 1bf6f2c66ebfe38dd5b30abe36fb0f37 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes |
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
import javafx.util.Pair;
public class Main {
public static void main(String[] args) throws FileNotFoundException {
// File f = new File("input.txt");
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int x = input.nextInt();
int y = input.nextInt();
int a[] = new int[n];
int count=0;
for (int i = 0; i < n; i++) {
a[i] = input.nextInt();
if(a[i]<=x)
count++;
}
if(x>y)
{
System.out.println(n);
}
else
{
if(count%2==0)
{
System.out.println(count/2);
}
else
System.out.println(count/2+1);
}
}
}
| Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 0e28861b35843defc1d609a484726128 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
/*
*
*/
Scanner scan = new Scanner(System.in);
int t= scan.nextInt();
int x=scan.nextInt();
int y=scan.nextInt();
int[] arr= new int[t];
int less=0;
for(int i=0;i<t;i++) {
arr[i]=scan.nextInt();
if(arr[i]<=x) less++;
}
int ans=0;
if(x>y) ans=t;
else {
if(less%2==0) ans=less/2;
else ans=(less/2)+1;
}
System.out.println(ans);
scan.close();
}
/*
* static final Random random=new Random();
*
* static void ruffleSort(int[] a) { int n=a.length;//shuffle, then sort for
* (int i=0; i<n; i++) { int oi=random.nextInt(n), temp=a[oi]; a[oi]=a[i];
* a[i]=temp; } Arrays.sort(a); }
*/
} | Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 25d16805efdba23d6be970bc7f2f2ef6 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.io.*;
import java.util.*;
public class vk18
{
public static void main(String[]st)
{
Scanner scan=new Scanner(System.in);
int n,i,x,y,count=0,m;
n=scan.nextInt();
x=scan.nextInt();
y=scan.nextInt();
for(i=0;i<n;i++)
{
m=scan.nextInt();
if(m <= x) count++;
}
if(x>y) System.out.println(n);
else System.out.println((count+1)/2);
}
} | Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | e91bccdc89979f016f4ca8a87a606195 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes |
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
/**
*
* @author ahmed.happa
*/
public class Test {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner reader = new Scanner(System.in);
int numberOfDoors = reader.nextInt();
int decreasingQuantity = reader.nextInt();
int increasingQunatity = reader.nextInt();
List<Integer> doorsDurability = new ArrayList<>();
for (int i = 0; i < numberOfDoors; i++) {
doorsDurability.add(reader.nextInt());
}
boolean cantMoveAgain = false;
if (decreasingQuantity > increasingQunatity) {
System.out.println(numberOfDoors);
} else {
int numberOfOutbutDoors = 0;
boolean loopAgain = true;
while (loopAgain && !doorsDurability.isEmpty()) {
int minimumDurabilityIndex = doorsDurability.indexOf(Collections.min(doorsDurability));
doorsDurability.set(minimumDurabilityIndex, doorsDurability.get(minimumDurabilityIndex) - decreasingQuantity);
if (doorsDurability.get(minimumDurabilityIndex) <= 0) {
doorsDurability.remove(minimumDurabilityIndex);
numberOfOutbutDoors++;
} else {
loopAgain = false;
}
if (!doorsDurability.isEmpty()) {
int minimumDurabilityIndexForRepair = doorsDurability.indexOf(Collections.min(doorsDurability));
doorsDurability.set(minimumDurabilityIndexForRepair, doorsDurability.get(minimumDurabilityIndexForRepair) + increasingQunatity);
}
}
System.out.println(numberOfOutbutDoors);
}
reader.close();
}
}
| Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | ad14094162778c08911e5747853a9103 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.util.*;
public class asd
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int start=s.nextInt();
int end=s.nextInt();int count=0;
Integer arr[]=new Integer[n];
for(int i=0;i<n;i++)
{ arr[i]=s.nextInt();
if(arr[i]<=start)
count++;
}
if(start>end)
System.out.println(n);
else
System.out.println((count+1)/2);
}
} | Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 17a4a3389886100d14066128c895f1bf | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes |
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class q54 {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(), me=sc.nextInt(), sal= sc.nextInt();
int x [] = new int [n];
for(int i=0;i<n;i++)
x[i]=sc.nextInt();
x=shuffle(x);
Arrays.sort(x);
if(me>sal) {
System.out.println(n);
return;
}
int f=1;
int c=0;
for(int i=0;i<n;i++) {
if(x[i]<=me)
c++;
}
if(c%2==0)
System.out.println(c/2);
else
System.out.println((int)(c/2)+1);
}
static int[] shuffle(int[] a) {
int n = a.length;
for (int i = 0; i < n; i++) {
int r = i + (int) (Math.random() * (n - i));
int tmp = a[i];
a[i] = a[r];
a[r] = tmp;
}
return a;
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public Scanner(String file) throws FileNotFoundException {
br = new BufferedReader(new FileReader(file));
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public long nextlong() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
long res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++)
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
public boolean ready() throws IOException {
return br.ready();
}
}
}
| Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 11a4cc4dcddb140990fb13496c0be01c | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.util.*;
public class b_prblm {
static int gcd(int a,int b){
if(b==0)
return a;
return gcd(b,a%b);
}
public static void main(String[] args){
Scanner scn = new Scanner(System.in);
int n=scn.nextInt();
int x=scn.nextInt();
int y=scn.nextInt();
ArrayList<Integer> al=new ArrayList<>();
for(int i=0;i<n;i++){
int v=scn.nextInt();
if(x<=y){
if(v<=x){
al.add(v);
}
}else{
al.add(v);
}
}
if(x<=y){
System.out.println((int)(Math.ceil(al.size()/2.0)));
}else{
System.out.println(al.size());
}
}
}
| Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 485211c3a5008b2d486b6ca96fc45244 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.io.*;
import java.util.*;
public class Doors_Breaking_and_Repairing
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int x=sc.nextInt();
int y=sc.nextInt();
int arr[]=new int[n];
int count=0;
for(int i=0;i<n;i++)
{
arr[i]=sc.nextInt();
if(arr[i]<=x)
++count;
}
if(x>y)
System.out.println(n);
else
System.out.println((count+1)/2);
}
} | Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 61e2bef044ec069f4d1bc4cf93abb777 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static int Answer;
static int N;
static int X;
static int Y;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
X = Integer.parseInt(st.nextToken());
Y = Integer.parseInt(st.nextToken());
st = new StringTokenizer(br.readLine());
for(int i = 0; i < N; i++) {
int var = Integer.parseInt(st.nextToken());
if(var <= X)
Answer++;
}
if(X > Y)
System.out.println(N);
else
System.out.println((Answer + 1) / 2);
br.close();
}
} | Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | d2f70b0593134147e33c1d23ce14d5f2 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.io.*;
import java.util.*;
public class MainClass
{
public static void main(String args[])throws IOException
{
try
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String t_input[];
t_input=br.readLine().split(" ");
int n=Integer.parseInt(t_input[0]);
int x=Integer.parseInt(t_input[1]);
int y=Integer.parseInt(t_input[2]);
String a_input[];
a_input=br.readLine().split(" ");
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=Integer.parseInt(a_input[i]);
}
Arrays.sort(a);
int count=0;
//System.out.println(x+" "+y);
for(int i=0;i<n;i++)
{
int l=a[i];
//System.out.print(i+" ");
a[i]=a[i]-x;
//System.out.print(a[i]+" ");
if(a[i]<=0)
{
a[i]=0;
if(i+1<n)
a[i+1]=a[i+1]+y;
}
else
a[i]=a[i]+y;
//System.out.print(a[i]+" ");
if(a[i]>=l)
continue;
count++;
//System.out.println();
}
System.out.println(count);
}
catch(NumberFormatException x){}
}
}
/*
__________TEST INPUT:
test=Integer.parseInt(br.readLine());
__________n INPUT:
n=Integer.parseInt(br.readLine());
__________ARRAY INPUT:
String a_input[];
a_input=br.readLine().split(" ");
a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=Integer.parseInt(a_input[i]);
}
__________INPUT FOR TWO SPACE SEPARATED INTEGERS:
String t_input[];
t_input=br.readLine().split(" ");
n=Integer.parseInt(t_input[0]);
k=Integer.parseInt(t_input[1]);
__________FAST MULTIPLICATION(EXPONENTIAL SQUARING):
static long fpow(int base,int power)
{
final int M=1000000007;
if(power==1)
return base;
else
{
if(power%2==0)
{
long x=(long)Math.pow(fpow(base,power/2),2);
//MODULO M if required:
if(x>= M)
return x%M;
else
return x;
}
else
{
long x=(long)(base*Math.pow(fpow(base,(power-1)/2),2));
//MODULO M if required:
if(x>= M)
return x%M;
else
return x;
}
}
}
__________FAST MULTIPLICATION 2(EXPONENTIAL SQUARING):
static long fpow(int base,int power)
{
long x=1;
//final int M=1000000007;
//MODULO M if required
while(power>0)
{
if(power%2==1)
x=(x*base);//%M;
base=(base*base);//%M;
power/=2;
}
return x;
}
*/ | Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 4d66939a71fc95e48f95a7dc3de125c5 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.io.*;
import java.util.*;
public class Main{
public static void main(String[] args) {
FastReader fs=new FastReader();
PrintWriter out=new PrintWriter(System.out);
int t=1;
//t=fs.nextInt();
for(int i=1;i<=t;i++) {
Main m=new Main();
m.solve(i,out,fs);
}
out.close();
}
public void solve(int test,PrintWriter out,FastReader fs){
int n=fs.nextInt();
int x=fs.nextInt(),y=fs.nextInt();
if(x>y){
out.println(n);
return;
}
int a[]=fs.nextIntArray(n);
int count=0;
for(int i=0;i<n;i++)
if(a[i]<=x)count++;
out.println( (count+1)/2 );
}
}
class shedule{
int a,b;
shedule(int a,int b){
this.a=a;
this.b=b;
}
}
class FastReader{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next(){
while(!st.hasMoreTokens()){
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
long nextLong(){
return Long.parseLong(next());
}
int[] nextIntArray(int n){
int a[]=new int[n];
for(int i=0;i<n;i++)a[i]=nextInt();
return a;
}
long[] nextLongArray(int n){
long a[]=new long[n];
for(int i=0;i<n;i++)a[i]=nextInt();
return a;
}
char[] nextCharArray(){
char a[]=next().toCharArray();
return a;
}
} | Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | c1d9b2d25abc495a03c81ab92b7faeb0 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | /* package whatever; // 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 Ideone
{
static int upper_bound ( int arr [ ] , int start , int end , int x )
{
if ( start > end ) return start ;
int mid = ( start + end ) / 2 ;
if ( arr [ mid ] <= x )
return upper_bound ( arr , mid + 1 , end , x ) ;
else
return upper_bound ( arr , start , mid - 1 , x ) ;
}
public static void main (String[] args) throws java.lang.Exception
{
int n , x , y ;
Scanner in = new Scanner ( System.in ) ;
n = in.nextInt() ;
x = in.nextInt() ;
y = in.nextInt() ;
int arr [ ] = new int [ n ] ;
for ( int i = 0 ; i < n ; i ++ )
arr [ i ] = in.nextInt() ;
Arrays.sort ( arr ) ;
if ( x <= y )
{
int i = upper_bound ( arr , 0 , n - 1 , x ) ;
//System.out.println ( i ) ;
System.out.println ( ( int ) Math.ceil ( ( float ) i / 2 ) ) ;
}
else
{
System.out.println ( n ) ;
}
// your code goes here
}
} | Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 4821a16d515b64378fa85ba953bfbedc | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.util.*;
public class Test1 {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int n = in.nextInt(), x = in.nextInt(), y = in.nextInt(), cnt = 0;
for(int i = 0; i<n; i++) if(in.nextInt()<=x) cnt++;
if(x>y) System.out.println(n);
else System.out.println((cnt+1)/2);
}
} | Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 8060db889eb17684799ea8bc9f0b9fd6 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
if (x > y) {
System.out.println(n);
return;
}
st = new StringTokenizer(br.readLine());
int count = 0;
for (int i = 0; i < n; i++) {
int p = Integer.parseInt(st.nextToken());
if (p <= x)
count++;
}
System.out.println((count + 1) / 2);
}
}
| Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 3b3b3ba508c882fabf6d524aef8da1a4 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in Actual solution is at the top
*
* @author @Ziklon
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
CDoorsBreakingAndRepairing solver = new CDoorsBreakingAndRepairing();
solver.solve(1, in, out);
out.close();
}
static class CDoorsBreakingAndRepairing {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int n = in.readInt(), x = in.readInt(), y = in.readInt();
if (x > y) out.printLine(n);
else {
int ans = 0;
for (int i = 0; i < n; ++i) {
int e = in.readInt();
if (e <= x) ans++;
}
out.printLine((ans + 1) >> 1);
}
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void close() {
writer.close();
}
public void printLine(int i) {
writer.println(i);
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
| Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | f04a72c4335feb90b09edf791ee1d6b4 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.util.Scanner;
public class Round530_C {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int x = sc.nextInt();
int y = sc.nextInt();
int[] arr = new int[n];
int count_less = 0;
int count_same = 0;
if(x > y) {
System.out.println(n);
return;
}
for(int i = 0;i<n;i++) {
arr[i] = sc.nextInt();
int cur = arr[i];
if(cur < x) {
count_less++;
}
if(cur == x) {
count_same++;
}
}
count_less = count_same + count_less;
if(count_less%2 == 0) {
System.out.println(count_less/2);
} else {
int out = count_less/2 + 1;
System.out.println(out);
}
}
}
| Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 9ad37d654e264c01ebe95d17bdfc87b6 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.util.*;
import java.lang.*;
public class code{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int x=sc.nextInt();
int y=sc.nextInt();
int t=0;
int arr[]=new int[n];
for(int i=0;i<n;i++){
arr[i]=sc.nextInt();
}
if(x>y)System.out.println(n);
else{
for(int i=0;i<n;i++){
if(arr[i]<=x){
t++;
}
}
if(t%2==0)System.out.println(t/2);
else System.out.println((t/2)+1);
}
}
} | Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 97f5ff621765827f41044d9be1c97646 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | /* package whatever; // 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 Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int x=sc.nextInt();
int y=sc.nextInt();
int[] a=new int[n];
for(int i=0;i<n;i++)
a[i]=sc.nextInt();
if(x>y)
{
System.out.println(n);
System.exit(0);
}
else
{
int c=0;
for(int i=0;i<n;i++)
{
if(a[i]<=x)
c++;
}
System.out.println((int)Math.ceil((double)c/2));
}
}
} | Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 78313166a3360ae60d8771aafc467834 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.io.*;
import java.util.*;
import java.lang.Math;
public class Main {
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
st = new StringTokenizer(br.readLine());
} catch (Exception e){e.printStackTrace();}
}
public String next() {
if (st.hasMoreTokens()) return st.nextToken();
try {st = new StringTokenizer(br.readLine());}
catch (Exception e) {e.printStackTrace();}
return st.nextToken();
}
public int nextInt() {return Integer.parseInt(next());}
public long nextLong() {return Long.parseLong(next());}
public double nextDouble() {return Double.parseDouble(next());}
public String nextLine() {
String line = "";
if(st.hasMoreTokens()) line = st.nextToken();
else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
while(st.hasMoreTokens()) line += " "+st.nextToken();
return line;
}
}
public static void main(String[] args) {
FastScanner sc = new FastScanner();
PrintWriter pw = new PrintWriter(System.out);
final int MOD = 1000000007;
int n = sc.nextInt(), x = sc.nextInt(), y = sc.nextInt();
if(x > y) {
pw.println(n);
}
else {
int cnt = 0;
for(int i=0;i<n;i++) {
if(sc.nextInt() <= x) cnt++;
}
pw.println((int)Math.ceil(cnt / 2.0));
}
pw.close();
}
}
//ceil(a/b) = (a+b-1)/b | Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | abeeb2e42e471ed67fd08faebaa0190a | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.io.*;
import java.util.*;
public class C {
public static void main(String[] args) throws IOException {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int x = scn.nextInt(), y = scn.nextInt();
ArrayList<Integer> al = new ArrayList<>();
for (int i = 0; i < n; i++) {
int v = scn.nextInt();
if (y < x)
al.add(v);
else {
if (v <= x)
al.add(v);
}
}
if (y < x)
System.out.println(al.size());
else
System.out.println((int) (Math.ceil(al.size() * 1.0 / 2)));
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
}
}
| Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | a91854b586d0dea7ba0b50eca4bf4016 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.io.*;
import java.util.*;
public class C {
public static void main(String[] args) throws IOException {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int x = scn.nextInt(), y = scn.nextInt();
int a[] = new int[n];
for (int i = 0; i < n; i++)
a[i] = scn.nextInt();
if (y < x) {
System.out.println(n);
return;
}
Arrays.sort(a);
if (a[0] > x) {
System.out.println(0);
return;
}
int idx = Arrays.binarySearch(a, x + 1);
if (idx < 0)
idx = -(idx + 1) - 1;
else
while (idx > 0 && a[idx] == a[--idx])
;
System.out.println(idx / 2 + 1);
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
}
}
| Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 27c9d544c66a88f22e62630afae10ce4 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import static java.lang.Double.parseDouble;
import static java.lang.Integer.MAX_VALUE;
import static java.lang.Integer.max;
import static java.lang.Long.max;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Math.abs;
import static java.lang.Math.min;
import static java.lang.Math.toRadians;
import static java.lang.System.exit;
import static java.lang.System.gc;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class A {
static BufferedReader in;
static PrintWriter out;
static StringTokenizer tok;
void solve() throws Exception {
int n = nextInt(), x = nextInt(), y = nextInt(), d = 0;
int a[] = na(n);
if(x > y) {
out.println(n);
} else {
for(int aa:a) if(aa <= x) d++;
out.println((d+1) / 2);
}
}
public int lower_bound(long[] a, long v) {
int low = -1, high = a.length;
while (high - low > 1) {
int h = high + low >>> 1;
if (a[h] >= v) {
high = h;
} else {
low = h;
}
}
return high;
}
private int gcd(int a, int b) {
while (b > 0) {
int temp = b;
b = a % b;
a = temp;
}
return a;
}
private int lcm(int a, int b) {
return a * (b / gcd(a, b));
}
private int[] na(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
private long[] nal(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++) a[i] = nextLong();
return a;
}
int nextInt() throws IOException {
return parseInt(next());
}
long nextLong() throws IOException {
return parseLong(next());
}
double nextDouble() throws IOException {
return parseDouble(next());
}
String next() throws IOException {
while (tok == null || !tok.hasMoreTokens()) {
tok = new StringTokenizer(in.readLine());
}
return tok.nextToken();
}
public static void main(String[] args) throws Exception {
try {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(new OutputStreamWriter(System.out));
//long lStartTime = System.currentTimeMillis();
new A().solve();
//long lEndTime = System.currentTimeMillis();
//out.println("Elapsed time in seconds: " + (double)(lEndTime - lStartTime) / 1000.0);
in.close();
out.close();
} catch (Throwable e) {
e.printStackTrace();
exit(1);
}
}
} | Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 07b2a4a8a69a4a11def726e25bc50c4d | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import static java.lang.Double.parseDouble;
import static java.lang.Integer.MAX_VALUE;
import static java.lang.Integer.max;
import static java.lang.Long.max;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Math.abs;
import static java.lang.Math.min;
import static java.lang.Math.toRadians;
import static java.lang.System.exit;
import static java.lang.System.gc;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class A {
static BufferedReader in;
static PrintWriter out;
static StringTokenizer tok;
void solve() throws Exception {
int n = nextInt(), x = nextInt(), y = nextInt(), d = 1;
int a[] = na(n);
for(int aa:a) if(aa <= x) d++;
out.println(x > y ? n : d / 2);
}
public int lower_bound(long[] a, long v) {
int low = -1, high = a.length;
while (high - low > 1) {
int h = high + low >>> 1;
if (a[h] >= v) {
high = h;
} else {
low = h;
}
}
return high;
}
private int gcd(int a, int b) {
while (b > 0) {
int temp = b;
b = a % b;
a = temp;
}
return a;
}
private int lcm(int a, int b) {
return a * (b / gcd(a, b));
}
private int[] na(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
private long[] nal(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++) a[i] = nextLong();
return a;
}
int nextInt() throws IOException {
return parseInt(next());
}
long nextLong() throws IOException {
return parseLong(next());
}
double nextDouble() throws IOException {
return parseDouble(next());
}
String next() throws IOException {
while (tok == null || !tok.hasMoreTokens()) {
tok = new StringTokenizer(in.readLine());
}
return tok.nextToken();
}
public static void main(String[] args) throws Exception {
try {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(new OutputStreamWriter(System.out));
//long lStartTime = System.currentTimeMillis();
new A().solve();
//long lEndTime = System.currentTimeMillis();
//out.println("Elapsed time in seconds: " + (double)(lEndTime - lStartTime) / 1000.0);
in.close();
out.close();
} catch (Throwable e) {
e.printStackTrace();
exit(1);
}
}
} | Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 0b27f9c84b95e4bca9a3ea43679ed823 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in); //文字の入力
int n =sc.nextInt();
int x = sc.nextInt();
int y = sc.nextInt();
int[] d = new int[n];
for(int i= 0;i < n;i++){
d[i] = sc.nextInt();
}
int ans = 0;
if(x > y){
ans = n;
}
if(x == y){
int count = 0;
for(int i = 0;i < n;i++){
if(d[i] <= x){
count++;
}
}
ans = (count+1)/2;
}
if(x < y){
int count = 0;
for(int i = 0;i < n;i++){
if(d[i] <= x){
count++;
}
}
ans = (count+1)/2;
}
System.out.println(ans);
}
}
class Pair implements Comparable{
int from; //p
int end; //y
int num;
int bango;
@Override
public int compareTo(Object other) {
Pair otherpair = (Pair)other;
return end - otherpair.end;
}
}
| Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 146f53a71e6e4ec577ed8e5331eee56a | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.StringTokenizer;
public class codee {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br= new BufferedReader(new InputStreamReader( System.in));
Scanner sc =new Scanner(System.in);
StringTokenizer st=new StringTokenizer(br.readLine());
int n =Integer.parseInt(st.nextToken());
int x=Integer.parseInt(st.nextToken());
int y=Integer.parseInt(st.nextToken());
Integer[] a=new Integer[n];
st=new StringTokenizer(br.readLine());
int c=0;
for(int i=0;i<n;i++) {
a[i]=Integer.parseInt(st.nextToken());
if(a[i]<=x)
c++;
}
if(x>y)
System.out.println(n);
else {
System.out.println((c+1)/2);
}
}
}
| Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 4f9c236f9abd3f675b2f0af70da55074 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.util.*;
import java.io.*;
public class C915 {
public static void main(String args[]) throws Exception{
Scanner sc = new Scanner(System.in);
//Reader sc = new Reader();
int n = sc.nextInt();
long x = sc.nextInt();
long y = sc.nextInt();
long a[] = new long[n];
for(int i=0;i<n;i++)
a[i] = sc.nextInt();
Arrays.sort(a);
int ind = bs(a , x , n) + 1;
if(ind == 1 && a[0] > x) ind = 0;
if(x > y)
System.out.println(n);
else if(x <= y){
//System.out.println(ind);
int ans = ind / 2;
if(ind % 2 == 1)
ans++;
System.out.println(ans);
}
}
static int bs(long a[] , long x , int n){
int l = 0 , h = n - 1 , mid = (l + h)/2 , ans = l;
while(l <= h){
mid = (l + h)/2;
if(a[mid] <= x){
ans = mid;
l = mid + 1;
//System.out.println(l +" " +h +" " +mid +" hii");
}
else
h = mid - 1;
//System.out.println(l +" " +h +" " +mid);
}
return ans;
}
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
} | Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 812c38cc0e0853c455b6103f71aff8de | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner entrada = new Scanner(System.in);
int A = entrada.nextInt();
int B = entrada.nextInt();
int C = entrada.nextInt();
int[] array = new int[A];
Vector<Integer> list = new Vector<>();
for(int i = 0; i<A; i++){
array[i] = entrada.nextInt();
if(array[i] <= B) list.add(array[i]);
}
if(B>C) System.out.println(A);
else{
int result = list.size()/2;
if(list.size()%2>0) result += 1;
System.out.println(result);
}
}
}
| Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | a47fe066f9b2caea66c5f395c0122fcd | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | //package acm;
import java.util.*;
import java.io.*;
public class first {
static PrintWriter out;
public static void main(String[] args) throws IOException, InterruptedException {
out = new PrintWriter(System.out);
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int x = sc.nextInt();
int y = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
Arrays.sort(arr);
int u = 0;
int g = 1;
int c = 0;
if (x > y) {
out.println(n);
} else {
for (int i = 0; i < n; i++) {
// if (i % 2 == 0) {
// if(arr[u]<x) {
// arr[u] = 0;
// c+=1;u++;}
// else {
// arr[u] = Math.max(0, arr[u] - x);
// u++;
// }
//
// } else {
// if (arr[g]<x&&arr[g]!=0)
// {arr[g] = arr[g] + y;
// g++;}
// }
// out.println(Arrays.toString(arr)+" "+x);
// }
// //c++;
if(arr[i]<=x)
u++;
}
if(u%2==0) {
out.println(u/2);}
else {
u+=1;
out.println(u/2);
}
}
out.flush();
out.close();
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public Scanner(FileReader r) {
br = new BufferedReader(r);
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
public boolean ready() throws IOException {
return br.ready();
}
}
} | Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 590b7c0d96b9f51948fc7e0e8139e500 | train_000.jsonl | 1547044500 | You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consists of two phases. During the first phase you make your move and during the second phase Slavik makes his move.There are $$$n$$$ doors, the $$$i$$$-th door initially has durability equal to $$$a_i$$$.During your move you can try to break one of the doors. If you choose door $$$i$$$ and its current durability is $$$b_i$$$ then you reduce its durability to $$$max(0, b_i - x)$$$ (the value $$$x$$$ is given).During Slavik's move he tries to repair one of the doors. If he chooses door $$$i$$$ and its current durability is $$$b_i$$$ then he increases its durability to $$$b_i + y$$$ (the value $$$y$$$ is given). Slavik cannot repair doors with current durability equal to $$$0$$$.The game lasts $$$10^{100}$$$ turns. If some player cannot make his move then he has to skip it.Your goal is to maximize the number of doors with durability equal to $$$0$$$ at the end of the game. You can assume that Slavik wants to minimize the number of such doors. What is the number of such doors in the end if you both play optimally? | 256 megabytes | import java.util.*;
public class qc{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int x=sc.nextInt();
int y=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
Arrays.sort(a);
int r=0;
if(x>y)System.out.println(n);
else{
while(r<n && a[r]<=x)r++;
System.out.println(r/2+(r%2));
}
}
} | Java | ["6 3 2\n2 3 1 3 4 2", "5 3 3\n1 2 4 2 3", "5 5 6\n1 2 6 10 3"] | 1 second | ["6", "2", "2"] | NoteClarifications about the optimal strategy will be ignored. | Java 8 | standard input | [
"games"
] | c173e2695562dfa1f603e6a925a2e1f3 | The first line of the input contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 100$$$, $$$1 \le x, y \le 10^5$$$) — the number of doors, value $$$x$$$ and value $$$y$$$, respectively. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$), where $$$a_i$$$ is the initial durability of the $$$i$$$-th door. | 1,200 | Print one integer — the number of doors with durability equal to $$$0$$$ at the end of the game, if you and Slavik both play optimally. | standard output | |
PASSED | 1c48d3e0e044732deb6ae664eefd89a0 | train_000.jsonl | 1472056500 | Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? | 256 megabytes | import java.util.Scanner;
public class jucier {
public static void main(String[] args) {
Scanner u = new Scanner (System.in);
int num = u.nextInt();
int b = u.nextInt();
int d = u.nextInt();
int c = 0;
int total = 0;
int oranges[] = new int [num];
for (int i = 0; i < oranges.length; i++) {
oranges[i] = u.nextInt();
if(oranges[i]<=b) {
total += oranges[i];
if(total>d) {
total = 0;
c++;
}
}else {
continue;
}
}
System.out.println(c);
}
} | Java | ["2 7 10\n5 6", "1 5 10\n7", "3 10 10\n5 7 7", "1 1 1\n1"] | 1 second | ["1", "0", "1", "0"] | NoteIn the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | Java 8 | standard input | [
"implementation"
] | 06e9649963715e56d97297c6104fbc00 | The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. | 900 | Print one integer — the number of times Kolya will have to empty the waste section. | standard output | |
PASSED | 35cfc9e152693fa164dd4c0319a8a59c | train_000.jsonl | 1472056500 | Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? | 256 megabytes |
import java.util.Arrays;
import java.util.Scanner;
public class JavaApplication1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int b = input.nextInt();
int d = input.nextInt();
int [] arr = new int [n];
for(int i =0 ; i< n ;i++){
arr[i] = input.nextInt();
}
int sum=0;
int count=0;
for(int i = 0 ; i<arr.length; i++){
if(arr[i] <= b){
sum+= arr[i];
if(sum > d){
count+=1;
sum=0;
}
}
}
System.out.println(count);
}
}
| Java | ["2 7 10\n5 6", "1 5 10\n7", "3 10 10\n5 7 7", "1 1 1\n1"] | 1 second | ["1", "0", "1", "0"] | NoteIn the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | Java 8 | standard input | [
"implementation"
] | 06e9649963715e56d97297c6104fbc00 | The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. | 900 | Print one integer — the number of times Kolya will have to empty the waste section. | standard output | |
PASSED | 0a8da9ecf616878e1ba0b8e3dd7da760 | train_000.jsonl | 1472056500 | Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? | 256 megabytes |
import java.util.Scanner;
public class Juicer {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n= s.nextInt();
int maxSize = s.nextInt();
int empty = s.nextInt();
int count = 0;
int result = 0;
for (int i = 0; i < n; i++) {
int orange = s.nextInt();
if (orange<=maxSize) {
result += orange;
if (result>empty){
++count;
result=0;
}
}
}
System.out.println(count);
}
}
| Java | ["2 7 10\n5 6", "1 5 10\n7", "3 10 10\n5 7 7", "1 1 1\n1"] | 1 second | ["1", "0", "1", "0"] | NoteIn the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | Java 8 | standard input | [
"implementation"
] | 06e9649963715e56d97297c6104fbc00 | The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. | 900 | Print one integer — the number of times Kolya will have to empty the waste section. | standard output | |
PASSED | c5444048f08daa09ed3fa8e29afb8193 | train_000.jsonl | 1472056500 | Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? | 256 megabytes | import java.util.Scanner;
public class Juicer {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n= s.nextInt();
int maxSize = s.nextInt();
int empty = s.nextInt();
int count = 0;
long result = 0l;
for (int i = 0; i < n; i++) {
int orange = s.nextInt();
if (orange<=maxSize) {
result += orange;
if (result>empty){
++count;
result=0;
}
}
}
System.out.println(count);
}
}
| Java | ["2 7 10\n5 6", "1 5 10\n7", "3 10 10\n5 7 7", "1 1 1\n1"] | 1 second | ["1", "0", "1", "0"] | NoteIn the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | Java 8 | standard input | [
"implementation"
] | 06e9649963715e56d97297c6104fbc00 | The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. | 900 | Print one integer — the number of times Kolya will have to empty the waste section. | standard output | |
PASSED | 95fec676732c75c8717727905976b62e | train_000.jsonl | 1472056500 | Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? | 256 megabytes | import java.util.Scanner;
public class Juicer {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
long nborange=sc.nextLong();
long maxsizeorange=sc.nextLong();
long limitwastesection=sc.nextLong();
if((nborange==maxsizeorange) && (maxsizeorange==limitwastesection) && (limitwastesection==1) )
System.out.println(0);
else
{
long sizetotal=0;
long nbwasteemptied=0;
for(long i=0;i<nborange;i++)
{
long orangesize=sc.nextLong();
if(orangesize<=maxsizeorange)
{
sizetotal+=orangesize;
if(sizetotal>limitwastesection)
{
nbwasteemptied++;
sizetotal=0;
}
}
}
System.out.println(nbwasteemptied);
}
}
}
| Java | ["2 7 10\n5 6", "1 5 10\n7", "3 10 10\n5 7 7", "1 1 1\n1"] | 1 second | ["1", "0", "1", "0"] | NoteIn the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | Java 8 | standard input | [
"implementation"
] | 06e9649963715e56d97297c6104fbc00 | The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. | 900 | Print one integer — the number of times Kolya will have to empty the waste section. | standard output | |
PASSED | 238b35ea50718cfeb7b11887df109408 | train_000.jsonl | 1472056500 | Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? | 256 megabytes |
import java.util.Scanner;
public class CF709_D2_A
{
public static void main(String[] args)
{
Scanner scanner = new Scanner( System.in );
int iN = scanner.nextInt();
int iB = scanner.nextInt();
int iD = scanner.nextInt();
long iTotal = 0;
int count = 0;
for( int i = 1; i <= iN; i++ )
{
long iOrangeSize = scanner.nextInt();
if( iOrangeSize <= iB )
{
iTotal = iTotal + iOrangeSize;
if( iTotal > iD )
{
count++;
iTotal = 0;
}
}
}
System.out.println( count );
}
}
| Java | ["2 7 10\n5 6", "1 5 10\n7", "3 10 10\n5 7 7", "1 1 1\n1"] | 1 second | ["1", "0", "1", "0"] | NoteIn the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | Java 8 | standard input | [
"implementation"
] | 06e9649963715e56d97297c6104fbc00 | The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. | 900 | Print one integer — the number of times Kolya will have to empty the waste section. | standard output | |
PASSED | 5fa7563a5709c41996c24eecf6bfeafc | train_000.jsonl | 1472056500 | Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? | 256 megabytes | import java.util.*;
public class Ex21 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner console= new Scanner (System.in);
int num = console.nextInt();
int size = console.nextInt();
int waste1 = console.nextInt();
int[] orange = new int[num];
for (int i = 0 ; i < num ; i++ ) {
orange[i] = console.nextInt();
}
int i = 0;
int sum = 0;
int count = 0;
while(i < orange.length){
if (orange[i] > size) {
}
else {
sum+= orange[i];
if (sum > waste1) {
count++;
sum = 0;
}
}
i++;
}
System.out.println(count);
}
}
| Java | ["2 7 10\n5 6", "1 5 10\n7", "3 10 10\n5 7 7", "1 1 1\n1"] | 1 second | ["1", "0", "1", "0"] | NoteIn the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | Java 8 | standard input | [
"implementation"
] | 06e9649963715e56d97297c6104fbc00 | The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. | 900 | Print one integer — the number of times Kolya will have to empty the waste section. | standard output | |
PASSED | c436be140a4ea87bf74cb9b6844f58e0 | train_000.jsonl | 1472056500 | Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? | 256 megabytes | import java.util.*;
/**
* @(#)juicer.java
*
*
* @author
* @version 1.00 2016/9/8
*/
public class juicer {
public static void main(String[] args) {
Scanner kbd = new Scanner (System.in);
int emp = 0;
int sum = 0;
int n = kbd.nextInt();
int[] list = new int[n];
int b = kbd.nextInt();
int d = kbd.nextInt();
if (n >= 1 && n <=100_000 && b >= 1 && d >= 1 && d >= b && d <= 1_000_000){
// int b = kbd.nextInt();
//
// int d = kbd.nextInt();
// if (b >= 1 && d >= 1 && b < d && d <= 1_000_000){
// int d = kbd.nextInt();
// if (d >= 1 && d >= b && d <= 1_000_000){
for (int i = 0; i < n; i++){
int a = kbd.nextInt();
if (a >= 1 && a <= 1_000_000){
list [i] = a;
if (list [i] <= b) {
sum += list [i];
if (sum > d) {
emp++;
sum = 0;
}
}
}
}
// }
// }
}
System.out.print(emp);
}
}
| Java | ["2 7 10\n5 6", "1 5 10\n7", "3 10 10\n5 7 7", "1 1 1\n1"] | 1 second | ["1", "0", "1", "0"] | NoteIn the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | Java 8 | standard input | [
"implementation"
] | 06e9649963715e56d97297c6104fbc00 | The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. | 900 | Print one integer — the number of times Kolya will have to empty the waste section. | standard output | |
PASSED | 9f3c8acd858c975e09d63ff10639cc05 | train_000.jsonl | 1472056500 | Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? | 256 megabytes | import java.util.Scanner;
public class CF709_D2_A {
public static void main(String[] args) {
// time reading 4 min
// think 5 min
// implement time 4 min
// debug 1 min
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int b = scanner.nextInt();
int d = scanner.nextInt();
int collection = 0;
int count = 0;
for (int i = 0; i < n; i++) {
int s = scanner.nextInt();
if(s <= b) {
collection += s;
}
if (collection > d) {
collection = 0;
count++;
}
}
System.out.println(count);
}
}
| Java | ["2 7 10\n5 6", "1 5 10\n7", "3 10 10\n5 7 7", "1 1 1\n1"] | 1 second | ["1", "0", "1", "0"] | NoteIn the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | Java 8 | standard input | [
"implementation"
] | 06e9649963715e56d97297c6104fbc00 | The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. | 900 | Print one integer — the number of times Kolya will have to empty the waste section. | standard output | |
PASSED | 68ec3182c72ecca64ea18d48b7b231a2 | train_000.jsonl | 1472056500 | Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? | 256 megabytes | import java.util.Scanner;
public class Juicer {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int maxSize = scanner.nextInt();
int wasteSize = scanner.nextInt();
int[] sizes = new int[n];
for (int i = 0;i<n;i++){
sizes[i] = scanner.nextInt();
}
scanner.close();
System.out.println(countWaste(maxSize,sizes,wasteSize) + "");
}
public static int countWaste(int maxSize,int[] sizes,int wasteSize){
int count = 0;
int wasteEmpty = wasteSize;
for(int i = 0 ; i < sizes.length ; i++){
if(sizes[i] <= maxSize)
wasteEmpty -= sizes[i];
if (wasteEmpty < 0){
count++;
wasteEmpty = wasteSize;
}
}
return count;
}
}
| Java | ["2 7 10\n5 6", "1 5 10\n7", "3 10 10\n5 7 7", "1 1 1\n1"] | 1 second | ["1", "0", "1", "0"] | NoteIn the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | Java 8 | standard input | [
"implementation"
] | 06e9649963715e56d97297c6104fbc00 | The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. | 900 | Print one integer — the number of times Kolya will have to empty the waste section. | standard output | |
PASSED | 490ae4e043f31b96a3df31c75dbec70e | train_000.jsonl | 1472056500 | Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class MyClass {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int b = sc.nextInt();
int d = sc.nextInt();
int sum=0;
int c =0;
for (int i = 0; i < n; i++) {
int x = sc.nextInt();
if(x<=b){
sum+=x;
if(sum > d){
sum =0;
c++ ;
}
}
}
System.out.println(c);
}
} | Java | ["2 7 10\n5 6", "1 5 10\n7", "3 10 10\n5 7 7", "1 1 1\n1"] | 1 second | ["1", "0", "1", "0"] | NoteIn the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | Java 8 | standard input | [
"implementation"
] | 06e9649963715e56d97297c6104fbc00 | The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. | 900 | Print one integer — the number of times Kolya will have to empty the waste section. | standard output | |
PASSED | b36060a2e4498cd79114c77ba5ad7406 | train_000.jsonl | 1472056500 | Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int b = sc.nextInt();
int d = sc.nextInt();
int waste = 0;
int sum = 0;
for (int i=0; i<n; i++){
int x = sc.nextInt();
if(x <= b)
sum+=x;
if(sum > d){
waste++;
sum=0;
}
}
System.out.println(waste);
}
} | Java | ["2 7 10\n5 6", "1 5 10\n7", "3 10 10\n5 7 7", "1 1 1\n1"] | 1 second | ["1", "0", "1", "0"] | NoteIn the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | Java 8 | standard input | [
"implementation"
] | 06e9649963715e56d97297c6104fbc00 | The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. | 900 | Print one integer — the number of times Kolya will have to empty the waste section. | standard output | |
PASSED | d20e720e36f3201a499904bdcde59b2b | train_000.jsonl | 1472056500 | Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int b = sc.nextInt();
int d = sc.nextInt();
int sum=0,counter=0;
for (int i = 0; i < n; i++) {
int x = sc.nextInt();
if(x<=b)
sum+=x;
if(sum>d){
counter++;
sum=0;
}
}
System.out.println(counter);
}
}
| Java | ["2 7 10\n5 6", "1 5 10\n7", "3 10 10\n5 7 7", "1 1 1\n1"] | 1 second | ["1", "0", "1", "0"] | NoteIn the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | Java 8 | standard input | [
"implementation"
] | 06e9649963715e56d97297c6104fbc00 | The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. | 900 | Print one integer — the number of times Kolya will have to empty the waste section. | standard output | |
PASSED | 6d487b4613b90e3db47c2e7df60082bf | train_000.jsonl | 1472056500 | Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class A709 {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader in = new FastReader();
int n = in.nextInt() , b = in.nextInt() , d = in.nextInt();
int sum = 0;
int count = 0;
for (int i = 0; i < n; i++) {
int temp = in.nextInt();
if (temp <= b) sum += temp;
if (sum > d) {
count++;
sum = 0;
}
}
System.out.println(count);
}
}
| Java | ["2 7 10\n5 6", "1 5 10\n7", "3 10 10\n5 7 7", "1 1 1\n1"] | 1 second | ["1", "0", "1", "0"] | NoteIn the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | Java 8 | standard input | [
"implementation"
] | 06e9649963715e56d97297c6104fbc00 | The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. | 900 | Print one integer — the number of times Kolya will have to empty the waste section. | standard output | |
PASSED | 0e65468c49fa21184e4eac0f2630ecbb | train_000.jsonl | 1472056500 | Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? | 256 megabytes | import java.util.*;
public class test {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int numberOfOrange = keyboard.nextInt();
int maxSize = keyboard.nextInt();
int dmaxcondition = keyboard.nextInt();
int orangeSize = 0;
int sum = 0;
int answer = 0;
for (int i = 0; i < numberOfOrange; i++) {
orangeSize = keyboard.nextInt();
if (orangeSize > maxSize) {
continue;
}
sum += orangeSize;
if (sum > dmaxcondition) {
answer++;
sum = 0;
}
}
System.out.println(answer);
}
}
| Java | ["2 7 10\n5 6", "1 5 10\n7", "3 10 10\n5 7 7", "1 1 1\n1"] | 1 second | ["1", "0", "1", "0"] | NoteIn the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | Java 8 | standard input | [
"implementation"
] | 06e9649963715e56d97297c6104fbc00 | The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. | 900 | Print one integer — the number of times Kolya will have to empty the waste section. | standard output | |
PASSED | 19dc89e7da7071e82b00f7995e2cc9f8 | train_000.jsonl | 1472056500 | Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? | 256 megabytes | import java.util.Scanner;
public class Juicer {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int b = scan.nextInt();
int d = scan.nextInt();
long sum = 0;
int ans = 0;
for (int i = 0 ;i < n ; i++) {
int o = scan.nextInt();
if (o <= b) {
sum += o;
}
if (sum > d) {
ans++;
sum = 0;
}
}
System.out.println(ans);
}
}
| Java | ["2 7 10\n5 6", "1 5 10\n7", "3 10 10\n5 7 7", "1 1 1\n1"] | 1 second | ["1", "0", "1", "0"] | NoteIn the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | Java 8 | standard input | [
"implementation"
] | 06e9649963715e56d97297c6104fbc00 | The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. | 900 | Print one integer — the number of times Kolya will have to empty the waste section. | standard output | |
PASSED | 15c44d21e9419b637227231675a7ea7c | train_000.jsonl | 1472056500 | Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? | 256 megabytes | import java.util.*;
public class Just_test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int n ,b ,d ,sum=0,c=0 ;
n=in.nextInt();
b=in.nextInt();
d=in.nextInt();
int arr[]=new int[n];
for (int i = 0; i < arr.length; i++) {
arr[i]=in.nextInt();
if(arr[i]>b)
{
continue;
}
else {
sum+=arr[i];
if(sum>d)
{
c++;
sum=0;
}
else
{
continue;
}
}
}
System.out.print(c);
}
}
| Java | ["2 7 10\n5 6", "1 5 10\n7", "3 10 10\n5 7 7", "1 1 1\n1"] | 1 second | ["1", "0", "1", "0"] | NoteIn the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | Java 8 | standard input | [
"implementation"
] | 06e9649963715e56d97297c6104fbc00 | The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. | 900 | Print one integer — the number of times Kolya will have to empty the waste section. | standard output | |
PASSED | 1a2c02a06eb5e3d6c6d668972c5cb00e | train_000.jsonl | 1472056500 | Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Amine
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastInput in = new FastInput(inputStream);
FastOutput out = new FastOutput(outputStream);
AJuicer solver = new AJuicer();
solver.solve(1, in, out);
out.close();
}
static class AJuicer {
public void solve(int testNumber, FastInput in, FastOutput out) {
int n = in.nextInt();
int b = in.nextInt();
int d = in.nextInt();
int a[] = new int[n];
int sum = 0;
int res = 0;
for (int i = 0; i < n; i++) {
int k = in.nextInt();
if (k <= b) {
sum += k;
if (sum > d) {
res++;
// res+= sum/d;
sum = 0;
}
}
}
out.println(res);
/*long sum = 0;
for (int i = 0; i < n; i++) {
int k = in.nextInt();
if (k < b) sum+=k;
}
out.println(sum/d);*/
}
}
static class FastOutput {
private final PrintWriter writer;
public FastOutput(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public FastOutput(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void close() {
writer.close();
}
public void println(int i) {
writer.println(i);
}
}
static class FastInput {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private FastInput.SpaceCharFilter filter;
public FastInput(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
}
| Java | ["2 7 10\n5 6", "1 5 10\n7", "3 10 10\n5 7 7", "1 1 1\n1"] | 1 second | ["1", "0", "1", "0"] | NoteIn the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | Java 8 | standard input | [
"implementation"
] | 06e9649963715e56d97297c6104fbc00 | The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. | 900 | Print one integer — the number of times Kolya will have to empty the waste section. | standard output | |
PASSED | 5d01ba187a9f4dc96b4888d35792b630 | train_000.jsonl | 1472056500 | Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? | 256 megabytes | import java.util.Scanner;
public class submission {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int b = sc.nextInt();
int d = sc.nextInt();
int sum=0;
int i=0,times=0;
while(i<n){
int input = sc.nextInt();
if(input<=b){
sum+=input;
if(sum>d){sum=0; times++;}
}i++;
}
System.out.println(times);
}
} | Java | ["2 7 10\n5 6", "1 5 10\n7", "3 10 10\n5 7 7", "1 1 1\n1"] | 1 second | ["1", "0", "1", "0"] | NoteIn the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | Java 8 | standard input | [
"implementation"
] | 06e9649963715e56d97297c6104fbc00 | The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. | 900 | Print one integer — the number of times Kolya will have to empty the waste section. | standard output | |
PASSED | 17ceed3e13413d0dc1bb4636bb44629d | train_000.jsonl | 1571754900 | The only difference between easy and hard versions is the maximum value of $$$n$$$.You are given a positive integer number $$$n$$$. You really love good numbers so you want to find the smallest good number greater than or equal to $$$n$$$.The positive integer is called good if it can be represented as a sum of distinct powers of $$$3$$$ (i.e. no duplicates of powers of $$$3$$$ are allowed).For example: $$$30$$$ is a good number: $$$30 = 3^3 + 3^1$$$, $$$1$$$ is a good number: $$$1 = 3^0$$$, $$$12$$$ is a good number: $$$12 = 3^2 + 3^1$$$, but $$$2$$$ is not a good number: you can't represent it as a sum of distinct powers of $$$3$$$ ($$$2 = 3^0 + 3^0$$$), $$$19$$$ is not a good number: you can't represent it as a sum of distinct powers of $$$3$$$ (for example, the representations $$$19 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0$$$ are invalid), $$$20$$$ is also not a good number: you can't represent it as a sum of distinct powers of $$$3$$$ (for example, the representation $$$20 = 3^2 + 3^2 + 3^0 + 3^0$$$ is invalid). Note, that there exist other representations of $$$19$$$ and $$$20$$$ as sums of powers of $$$3$$$ but none of them consists of distinct powers of $$$3$$$.For the given positive integer $$$n$$$ find such smallest $$$m$$$ ($$$n \le m$$$) that $$$m$$$ is a good number.You have to answer $$$q$$$ independent queries. | 256 megabytes | import java.io.*;
import java.util.*;
public class C
{
public static void main(String[] args)throws IOException
{
BufferedReader ob=new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb=new StringBuffer();
int test=Integer.parseInt(ob.readLine());
while(test-->0)
{
long n=Long.parseLong(ob.readLine());
long pow=highestPowerof3(n);
long sum=1;
long prod=1;
while(sum<n)
{
prod*=3;
sum+=prod;
}
while(prod>=1)
{
if(sum-prod>=n)
sum-=prod;
// else
// break;
prod/=3;
}
sb.append(sum+"\n");
}
System.out.println(sb);
}
static long highestPowerof3(long n)
{
long p = (int)(Math.log(n)/Math.log(3));
return p;
}
static long fastPow(long n, long m) {
long res = 1L;
while (m > 0) {
if ((m & 1) != 0) {
res *= n;
m--;
} else {
n *= n;
m /= 2;
}
}
return res;
}
}
| Java | ["7\n1\n2\n6\n13\n14\n3620\n10000"] | 1 second | ["1\n3\n9\n13\n27\n6561\n19683"] | null | Java 8 | standard input | [
"binary search",
"meet-in-the-middle",
"greedy",
"math"
] | 5953b898995a82edfbd42b6c0f7138af | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Then $$$q$$$ queries follow. The only line of the query contains one integer $$$n$$$ ($$$1 \le n \le 10^4$$$). | 1,500 | For each query, print such smallest integer $$$m$$$ (where $$$n \le m$$$) that $$$m$$$ is a good number. | standard output | |
PASSED | 316203ed7e7c379135e3d9deab5ae123 | train_000.jsonl | 1571754900 | The only difference between easy and hard versions is the maximum value of $$$n$$$.You are given a positive integer number $$$n$$$. You really love good numbers so you want to find the smallest good number greater than or equal to $$$n$$$.The positive integer is called good if it can be represented as a sum of distinct powers of $$$3$$$ (i.e. no duplicates of powers of $$$3$$$ are allowed).For example: $$$30$$$ is a good number: $$$30 = 3^3 + 3^1$$$, $$$1$$$ is a good number: $$$1 = 3^0$$$, $$$12$$$ is a good number: $$$12 = 3^2 + 3^1$$$, but $$$2$$$ is not a good number: you can't represent it as a sum of distinct powers of $$$3$$$ ($$$2 = 3^0 + 3^0$$$), $$$19$$$ is not a good number: you can't represent it as a sum of distinct powers of $$$3$$$ (for example, the representations $$$19 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0$$$ are invalid), $$$20$$$ is also not a good number: you can't represent it as a sum of distinct powers of $$$3$$$ (for example, the representation $$$20 = 3^2 + 3^2 + 3^0 + 3^0$$$ is invalid). Note, that there exist other representations of $$$19$$$ and $$$20$$$ as sums of powers of $$$3$$$ but none of them consists of distinct powers of $$$3$$$.For the given positive integer $$$n$$$ find such smallest $$$m$$$ ($$$n \le m$$$) that $$$m$$$ is a good number.You have to answer $$$q$$$ independent queries. | 256 megabytes | import java.util.*;
import javax.imageio.ImageIO;
import javax.xml.bind.DatatypeConverter;
import java.awt.image.BufferedImage;
import java.io.*;
import java.math.BigInteger;
public class template {
public static void main(String[] args) throws Exception {
FastScanner sc = new FastScanner();
PrintWriter pw = new PrintWriter(System.out);
int n = sc.nextInt();
long[] x = new long[39];
for(int i=0;i<39;i++){
x[i]=get3p(i);
}
for(int i =0 ;i<n;i++){
long f = sc.nextLong();
long r = f;
StringBuilder t = new StringBuilder();
for(int j=38;j>=0;j--){
int app = 0;
while(f>=x[j]){
f-=x[j];
app++;
}
t.append(app);
}
String str = t.toString();
if(str.replaceAll("[01]", "").equals("")){
pw.println(r);
}
else{
int s=0;
int ind = 0;
for(int j =0;j<str.length();j++){
if(str.charAt(j)>'0'&&s==0){
s=j;
}
if(str.charAt(j)=='0'){
ind = j;
}
if(str.charAt(j)=='2'){
break;
}
}
if(ind ==0){
if(s==0){
pw.println(0);
}
else{
pw.println(get3p(39-s));
}
}
else {
long o = get3p(39-ind-1);
for(int j = 0;j<ind;j++){
if(str.charAt(j)>'0'){
o+=get3p(39-j-1);
}
}
pw.println(o);
}
}
}
pw.close();
}
static long get3p(int x){
long i = 1;
for(int j = 0;j<x;j++){
i*=3;
}
return i;
}
}
@SuppressWarnings("all")
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(String s) {
try {
br = new BufferedReader(new FileReader(s));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String nextToken() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(nextToken());
}
long nextLong() {
return Long.parseLong(nextToken());
}
double nextDouble() {
return Double.parseDouble(nextToken());
}
} | Java | ["7\n1\n2\n6\n13\n14\n3620\n10000"] | 1 second | ["1\n3\n9\n13\n27\n6561\n19683"] | null | Java 8 | standard input | [
"binary search",
"meet-in-the-middle",
"greedy",
"math"
] | 5953b898995a82edfbd42b6c0f7138af | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Then $$$q$$$ queries follow. The only line of the query contains one integer $$$n$$$ ($$$1 \le n \le 10^4$$$). | 1,500 | For each query, print such smallest integer $$$m$$$ (where $$$n \le m$$$) that $$$m$$$ is a good number. | standard output | |
PASSED | a7c9bc6a18d234679aeab4fa52997ac6 | train_000.jsonl | 1571754900 | The only difference between easy and hard versions is the maximum value of $$$n$$$.You are given a positive integer number $$$n$$$. You really love good numbers so you want to find the smallest good number greater than or equal to $$$n$$$.The positive integer is called good if it can be represented as a sum of distinct powers of $$$3$$$ (i.e. no duplicates of powers of $$$3$$$ are allowed).For example: $$$30$$$ is a good number: $$$30 = 3^3 + 3^1$$$, $$$1$$$ is a good number: $$$1 = 3^0$$$, $$$12$$$ is a good number: $$$12 = 3^2 + 3^1$$$, but $$$2$$$ is not a good number: you can't represent it as a sum of distinct powers of $$$3$$$ ($$$2 = 3^0 + 3^0$$$), $$$19$$$ is not a good number: you can't represent it as a sum of distinct powers of $$$3$$$ (for example, the representations $$$19 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0$$$ are invalid), $$$20$$$ is also not a good number: you can't represent it as a sum of distinct powers of $$$3$$$ (for example, the representation $$$20 = 3^2 + 3^2 + 3^0 + 3^0$$$ is invalid). Note, that there exist other representations of $$$19$$$ and $$$20$$$ as sums of powers of $$$3$$$ but none of them consists of distinct powers of $$$3$$$.For the given positive integer $$$n$$$ find such smallest $$$m$$$ ($$$n \le m$$$) that $$$m$$$ is a good number.You have to answer $$$q$$$ independent queries. | 256 megabytes | import java.util.Scanner;
import java.util.stream.IntStream;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int q = sc.nextInt();
for (int tc = 0; tc < q; tc++) {
long n = sc.nextLong();
System.out.println(solve(n));
}
sc.close();
}
static long solve(long n) {
String s = "";
while (n != 0) {
s = n % 3 + s;
n /= 3;
}
int twoIndex = s.indexOf('2');
if (twoIndex >= 0) {
int zeroIndex = s.substring(0, twoIndex).lastIndexOf('0');
if (zeroIndex >= 0) {
s = String.format("%s1%s", s.substring(0, zeroIndex), repeat('0', s.length() - zeroIndex - 1));
} else {
s = String.format("1%s", repeat('0', s.length()));
}
}
return Long.parseLong(s, 3);
}
static String repeat(char ch, int count) {
return IntStream.range(0, count).mapToObj(i -> ch)
.collect(StringBuilder::new, StringBuilder::append, StringBuilder::append).toString();
}
}
| Java | ["7\n1\n2\n6\n13\n14\n3620\n10000"] | 1 second | ["1\n3\n9\n13\n27\n6561\n19683"] | null | Java 8 | standard input | [
"binary search",
"meet-in-the-middle",
"greedy",
"math"
] | 5953b898995a82edfbd42b6c0f7138af | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Then $$$q$$$ queries follow. The only line of the query contains one integer $$$n$$$ ($$$1 \le n \le 10^4$$$). | 1,500 | For each query, print such smallest integer $$$m$$$ (where $$$n \le m$$$) that $$$m$$$ is a good number. | standard output | |
PASSED | b4dd810e2f6ee30a859ccb202a662a02 | train_000.jsonl | 1571754900 | The only difference between easy and hard versions is the maximum value of $$$n$$$.You are given a positive integer number $$$n$$$. You really love good numbers so you want to find the smallest good number greater than or equal to $$$n$$$.The positive integer is called good if it can be represented as a sum of distinct powers of $$$3$$$ (i.e. no duplicates of powers of $$$3$$$ are allowed).For example: $$$30$$$ is a good number: $$$30 = 3^3 + 3^1$$$, $$$1$$$ is a good number: $$$1 = 3^0$$$, $$$12$$$ is a good number: $$$12 = 3^2 + 3^1$$$, but $$$2$$$ is not a good number: you can't represent it as a sum of distinct powers of $$$3$$$ ($$$2 = 3^0 + 3^0$$$), $$$19$$$ is not a good number: you can't represent it as a sum of distinct powers of $$$3$$$ (for example, the representations $$$19 = 3^2 + 3^2 + 3^0 = 3^2 + 3^1 + 3^1 + 3^1 + 3^0$$$ are invalid), $$$20$$$ is also not a good number: you can't represent it as a sum of distinct powers of $$$3$$$ (for example, the representation $$$20 = 3^2 + 3^2 + 3^0 + 3^0$$$ is invalid). Note, that there exist other representations of $$$19$$$ and $$$20$$$ as sums of powers of $$$3$$$ but none of them consists of distinct powers of $$$3$$$.For the given positive integer $$$n$$$ find such smallest $$$m$$$ ($$$n \le m$$$) that $$$m$$$ is a good number.You have to answer $$$q$$$ independent queries. | 256 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.InputMismatchException;
import java.util.StringTokenizer;
public class C3 {
static class FastWriter {
private final BufferedWriter bw;
public FastWriter() {
this.bw = new BufferedWriter(new OutputStreamWriter(System.out));
}
public void print(Object object) throws IOException {
bw.append("" + object);
}
public void println(Object object) throws IOException {
print(object);
bw.append("\n");
}
public void close() throws IOException {
bw.close();
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
BigInteger nextBigInteger() {
try {
return new BigInteger(nextLine());
} catch (NumberFormatException e) {
throw new InputMismatchException();
}
}
}
public static void main(String[] args) {
FastReader fr = new FastReader();
FastWriter fw = new FastWriter();
int q = fr.nextInt();
while (q-- > 0) {
long n = fr.nextLong();
BigInteger val = BigInteger.ZERO;
int pow = 0;
BigInteger ans = BigInteger.ZERO;
while (val.compareTo(BigInteger.valueOf(n)) < 0) {
val = BigInteger.valueOf(3).pow(pow);
ans = ans.add(val);
pow++;
}
pow--;
for (int p = pow; p >= 0; p--) {
BigInteger hola = BigInteger.valueOf(3).pow(p);
BigInteger sub = ans.subtract(hola);
if (sub.compareTo(BigInteger.valueOf(n)) >= 0) ans = sub;
}
System.out.println(ans);
}
}
}
| Java | ["7\n1\n2\n6\n13\n14\n3620\n10000"] | 1 second | ["1\n3\n9\n13\n27\n6561\n19683"] | null | Java 8 | standard input | [
"binary search",
"meet-in-the-middle",
"greedy",
"math"
] | 5953b898995a82edfbd42b6c0f7138af | The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Then $$$q$$$ queries follow. The only line of the query contains one integer $$$n$$$ ($$$1 \le n \le 10^4$$$). | 1,500 | For each query, print such smallest integer $$$m$$$ (where $$$n \le m$$$) that $$$m$$$ is a good number. | standard output | |
PASSED | 29aa8c08a2729e75a66b1d937782d899 | train_000.jsonl | 1270136700 | A line on the plane is described by an equation Ax + By + C = 0. You are to find any point on this line, whose coordinates are integer numbers from - 5·1018 to 5·1018 inclusive, or to find out that such points do not exist. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution
{
static long gcd;
static long x,y;
public static void main(String ag[])
{
Scanner sc=new Scanner(System.in);
long A=sc.nextLong();
long B=sc.nextLong();
long C=sc.nextLong();
gcd(A,B);
if(C%gcd!=0)
System.out.println(-1);
else
{
C*=-1;
x*=C/gcd;
y*=C/gcd;
System.out.println(x+" "+y);
}
}
public static void gcd(long A,long B)
{
if(B==0)
{
x=1;
y=0;
gcd=A;
}
else
{
gcd(B,A%B);
long temp=x;
x=y;
y=temp-(A/B)*y;
}
}
} | Java | ["2 5 3"] | 1 second | ["6 -3"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a01e1c545542c1641eca556439f0692e | The first line contains three integers A, B and C ( - 2·109 ≤ A, B, C ≤ 2·109) — corresponding coefficients of the line equation. It is guaranteed that A2 + B2 > 0. | 1,800 | If the required point exists, output its coordinates, otherwise output -1. | standard output | |
PASSED | 004db46d27cedacd6fc57da0b8ad218e | train_000.jsonl | 1270136700 | A line on the plane is described by an equation Ax + By + C = 0. You are to find any point on this line, whose coordinates are integer numbers from - 5·1018 to 5·1018 inclusive, or to find out that such points do not exist. | 256 megabytes | import java.util.*;
import java.io.*;
public class hello {
public static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static FastReader sc = new FastReader();
public static void take_array(long arr[], int size) {
for (int i = 0; i < size; i++) {
arr[i] = sc.nextLong();
}
}
public static void print_arr(long arr[]) {
for (long x : arr)
System.out.print(x + " ");
}
public static String[] convert_String_to_arr(String s) {
String arr[] = new String[s.length()];
for (int i = 0; i < s.length(); i++) {
arr[i] = String.valueOf(s.charAt(i));
}
return arr;
}
public static void take_prefix_array(long arr[], int size, long []prefix) {
long temp = 0;
for (int i = 0; i < size; i++) {
temp += arr[i];
prefix[i] = temp;
}
}
public static void print(Object c, int a) {
if (a == -1)
System.out.print(c + " ");
else
System.out.println(c);
}
public static void space() {
System.out.println();
}
public static long sum_array(long arr[]) {
long sum = 0;
for (long x : arr)
sum += x;
return sum;
}
public static void swap(long a, long b) {
long temp = a;
a = b;
b = temp;
}
public static long min(long a, long b, long c) {
return Math.min(a, Math.min(b, c));
}
public static long max(long a, long b, long c) {
return Math.max(a, Math.max(b, c));
}
public static long gcd(long a, long b) {
if (a < b)swap(a, b);
if (b == 0)return a;
return gcd(b, a % b);
}
public static long sol(long a, long b) {
if (b == 0) {
x = 1; y = 0;
return a;
}
long res = sol(b, a % b);
long t = x;
x = y;
y = (t - (a / b) * y);
return res;
}
public static long x, y;
public static void main(String []args) {
long a = sc.nextLong(), b = sc.nextLong(), c = sc.nextLong();
long g = sol(a, b);
if (c % g != 0)
print(-1, 0);
else {
long k = (-c) / g;
print(k * x + " " + k * y, 0);
}
}
} | Java | ["2 5 3"] | 1 second | ["6 -3"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a01e1c545542c1641eca556439f0692e | The first line contains three integers A, B and C ( - 2·109 ≤ A, B, C ≤ 2·109) — corresponding coefficients of the line equation. It is guaranteed that A2 + B2 > 0. | 1,800 | If the required point exists, output its coordinates, otherwise output -1. | standard output | |
PASSED | cf019c38fba018587ef125ecd5311a0d | train_000.jsonl | 1270136700 | A line on the plane is described by an equation Ax + By + C = 0. You are to find any point on this line, whose coordinates are integer numbers from - 5·1018 to 5·1018 inclusive, or to find out that such points do not exist. | 256 megabytes | import java.util.*;
public class Line {
static long[] solution(long a, long b){
if(a==0) return new long[]{0,1,b};
long[] ans = solution(b%a,a);
return new long[]{ans[1]-(b/a)*ans[0],ans[0],ans[2]};
}
static void solve(){
Scanner sc = new Scanner(System.in);
long a = sc.nextLong();
long b = sc.nextLong();
long c = sc.nextLong();
long[] ans = solution(a,b);
long C = -c/ans[2];
if((c%ans[2])==0) System.out.println((C*ans[0])+" "+(C*ans[1]));
else System.out.println(-1);
}
public static void main(String args[]) {
solve();
}
}
| Java | ["2 5 3"] | 1 second | ["6 -3"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a01e1c545542c1641eca556439f0692e | The first line contains three integers A, B and C ( - 2·109 ≤ A, B, C ≤ 2·109) — corresponding coefficients of the line equation. It is guaranteed that A2 + B2 > 0. | 1,800 | If the required point exists, output its coordinates, otherwise output -1. | standard output | |
PASSED | 4df7f9336e06187e473669cb8b692801 | train_000.jsonl | 1270136700 | A line on the plane is described by an equation Ax + By + C = 0. You are to find any point on this line, whose coordinates are integer numbers from - 5·1018 to 5·1018 inclusive, or to find out that such points do not exist. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
public class Main{
public static StreamTokenizer sc=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
public static int nextint() throws IOException {
sc.nextToken();
return (int)sc.nval;
}
public static String nextLine() throws IOException{
sc.nextToken();
return sc.sval;
}
public static int gcd(int a,int b) {
if(b==0) {
return a;
}else {
return gcd(b,a%b);
}
}
public static int extgcd(int a,int b,Long x,Long y) {
int d=a;
if(b==0) {
x.v=1;
y.v=0;
}else {
d=extgcd(b,a%b,y,x);
y.v-=(a/b)*x.v;
}
return d;
}
static class Long{
long v;
}
public static void main(String args[]) throws IOException {
PrintWriter out=new PrintWriter(System.out);
int a=nextint();
int b=nextint();
int c=nextint();
Long x = new Long(),y=new Long();
int k=extgcd(a,b,x,y);
if((-c)%k!=0) {
out.print(-1);
}else {
out.print((-c)/k*x.v+" "+(-c)/k*y.v);
}
out.flush();
out.close();
}
}
| Java | ["2 5 3"] | 1 second | ["6 -3"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a01e1c545542c1641eca556439f0692e | The first line contains three integers A, B and C ( - 2·109 ≤ A, B, C ≤ 2·109) — corresponding coefficients of the line equation. It is guaranteed that A2 + B2 > 0. | 1,800 | If the required point exists, output its coordinates, otherwise output -1. | standard output | |
PASSED | fe373f688ba6dd04686bc6659f5e7c11 | train_000.jsonl | 1270136700 | A line on the plane is described by an equation Ax + By + C = 0. You are to find any point on this line, whose coordinates are integer numbers from - 5·1018 to 5·1018 inclusive, or to find out that such points do not exist. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*; // for bigInteger
public class practice {
private final static int M = (int)1e9+7;
private static final InputReader scan = new InputReader(System.in);
private static final PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
private static final StringBuilder sb = new StringBuilder();
public static void main(String args[]) throws Exception {
//scanner scan = new scanner(system.in);
//scan.usedelimiter(""); // for reading character by character
long a = scan.nextLong(), b = scan.nextLong(), c = -scan.nextLong();
long rpp = Math.abs(a), rp = Math.abs(b), r = -1;
long xpp = 1, xp = 0, x = -1;
long ypp = 0, yp = 1, y = -1;
while(r!=0) {
long q = (rp!=0)?rpp/rp:0;
r = rpp-rp*q;
x = xpp-xp*q;
y = ypp-yp*q;
rpp = rp;
rp = r;
xpp = xp;
xp = x;
ypp = yp;
yp = y;
}
long g = rpp;
x = xpp*(c/g);
y = ypp*(c/g);
if(Math.abs(xpp)*Math.abs(c/g)<0) x=Long.MAX_VALUE;
if(Math.abs(ypp)*Math.abs(c/g)<0) y=Long.MAX_VALUE;
if(a<0) x=-x;
if(b<0) y=-y;
long left = (long)-5e18;
long right = (long)5e18;
if(c%g!=0) {
out.println("-1");
} else {
if(left<=x && x<=right && left<=y && x<=right)
out.println(x+" "+y);
else
out.println("-1");
}
scan.close();
out.close();
}
private final static int m =(int)1e9+7;
private static class Pair<T,V> {
T first;
V second;
Pair(final T first, final V second) {
this.first = first;
this.second = second;
}
public boolean equals(Object o) {
Pair given = (Pair)o;
if(given.first == first && given.second == second) return true;
return false;
}
public int hashCode() {
long temp = (long)(first.hashCode())*31;
temp = (temp+(long)second.hashCode())%m;
return (int)temp;
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[8192];
private int curChar;
private int snumChars;
private SpaceCharFilter filter;
public InputReader(final InputStream stream) {
this.stream = stream;
}
public int snext() {
if (snumChars == -1)
throw new InputMismatchException();
if (curChar >= snumChars) {
curChar = 0;
try {
snumChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (snumChars <= 0)
return -1;
}
return buf[curChar++];
}
public int nextInt() {
int c = snext();
while (isSpaceChar(c))
c = snext();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = snext();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = snext();
} while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = snext();
while (isSpaceChar(c))
c = snext();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = snext();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = snext();
} while (!isSpaceChar(c));
return res * sgn;
}
public String next() {
int c = snext();
while (isSpaceChar(c))
c = snext();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = snext();
} while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
public void close() throws IOException {
if(stream==null) {
return;
}
stream.close();
}
}
public static void debug(final int[] ...var) {
for(final int[] row : var) {
debug(row);
}
}
public static void debug(final long[] ...var) {
for(final long[] row : var) {
debug(row);
}
}
public static void debug(final String[] ...var) {
for(final String[] row : var) {
debug(row);
}
}
public static void debug(final double[] ...var) {
for(final double[] row : var) {
debug(row);
}
}
public static void debug(final char[] ...var) {
for(final char[] row : var) {
debug(row);
}
}
public static void debug(final int ...var) {
for(final int i:var) System.err.print(i+" ");
System.err.println();
}
public static void debug(final String ...var) {
for(final String i:var) System.err.print(i+" ");
System.err.println();
}
public static void debug(final double ...var) {
for(final double i:var) System.err.print(i+" ");
System.err.println();
}
public static void debug(final long ...var) {
for(final long i:var) System.err.print(i+" ");
System.err.println();
}
public static void debug(final char ...var) {
for(final char c:var) System.err.print(c+" ");
System.err.println();
}
/*
public static <T> void debug(T ...varargs) {
// Warning
// Heap Pollution might occur
// this overrides even 1d and 2d array methods as it is an object...
// + i am not using object based array like Integer[]
// I am using int[] so that is a problem as i need Wrapper class as an argument
for(T val:varargs) System.err.printf("%s ",val);
System.err.println();
}
*/
}
| Java | ["2 5 3"] | 1 second | ["6 -3"] | null | Java 11 | standard input | [
"number theory",
"math"
] | a01e1c545542c1641eca556439f0692e | The first line contains three integers A, B and C ( - 2·109 ≤ A, B, C ≤ 2·109) — corresponding coefficients of the line equation. It is guaranteed that A2 + B2 > 0. | 1,800 | If the required point exists, output its coordinates, otherwise output -1. | standard output | |
PASSED | ffd4c0ad29e54cfa52827892dbf00cb6 | train_000.jsonl | 1276700400 | Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. | 128 megabytes | import java.math.BigInteger;
import java.util.Scanner;
public class test {
static boolean s[];
static int a[] ;
static BigInteger dp[][] = new BigInteger[5005][2005];
static int N;
static boolean vis[][] = new boolean [5005][2005];
/**
* @param args
*/
static BigInteger val[] = new BigInteger[2005];
static BigInteger TWO = BigInteger.valueOf(2);
static BigInteger f(int i,int x)
{
if( i == N)
return BigInteger.ZERO;
if( dp[i][x] != null )
return dp[i][x];
dp[i][x] = f(i+1,x);
if( s[i] )
dp[i][x] = dp[i][x].max(f(i+1,a[i]));
else if( a[i] == x)
dp[i][x] = dp[i][x].max(f(i+1,2001).add( val[x] ));
return dp[i][x];
}
public static void main(String[] args) {
// TODO Auto-generated method stub
//System.out.println("Hello JAVA!!!");
Scanner reader = new Scanner(System.in);
N = reader.nextInt();
s = new boolean[N];
a = new int[N];
String ss;
for(int i=0;i<N;i++)
{
ss = reader.next();
a[i] = reader.nextInt();
s[i] = true;
if( ss.equals("sell") )
{
//val[a[i]] = BigInteger.ONE.shiftLeft(a[i]);
val[a[i]] = TWO.pow(a[i]);
s[i] = false;
}
}
System.out.println(f(0,2001));
}
} | Java | ["7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "3\nwin 5\nsell 6\nsell 4"] | 2 seconds | ["1056", "0"] | null | Java 7 | standard input | [
"dp",
"greedy",
"brute force"
] | 217a3a48b927213f4d5e0a19048e2a32 | The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). | 2,000 | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | standard output | |
PASSED | 60ea785ae0e3ad4a4f598125a1228151 | train_000.jsonl | 1276700400 | Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. | 128 megabytes | import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
static int n;
static ArrayList<pair> values;
static BigInteger[] sv;
static BigInteger dp(int ind) {
if (ind == n)
return BigInteger.ZERO;
if (!sv[ind].equals(BigInteger.valueOf(-1)))
return sv[ind];
BigInteger x = dp(ind + 1);
if (!values.get(ind).sell) {
for (int i = ind + 1; i < n; i++) {
if (values.get(i).sell
&& values.get(ind).value == values.get(i).value) {
x = x.max(dp(i + 1).add(BigInteger.valueOf(2).pow(values.get(ind).value)));
}
}
}
return sv[ind] = x;
}
public static void main(String[] args) {
values = new ArrayList<pair>();
sv = new BigInteger[5001];
Scanner scan = new Scanner(System.in);
n = scan.nextInt();
String s;
int x;
for (int i = 0; i < n; i++) {
sv[i] = BigInteger.valueOf(-1);
s = scan.next();
x = scan.nextInt();
values.add(new pair(x, s));
}
BigInteger max = dp(0);
System.out.println(max);
}
}
class pair {
boolean sell;
int value;
public pair(int value, String s) {
if (s.charAt(0) == 'w')
sell = false;
else
sell = true;
this.value = value;
}
} | Java | ["7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "3\nwin 5\nsell 6\nsell 4"] | 2 seconds | ["1056", "0"] | null | Java 7 | standard input | [
"dp",
"greedy",
"brute force"
] | 217a3a48b927213f4d5e0a19048e2a32 | The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). | 2,000 | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | standard output | |
PASSED | 527618276eb0df95892a108d45a2bce3 | train_000.jsonl | 1276700400 | Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. | 128 megabytes | import java.util.Scanner;
import java.math.*;
public class Main{
public static void main(String[] args){
BigInteger mayor[] = new BigInteger[5001];
int arr[] = new int[5001];
boolean gano[] = new boolean[5001];
int donde, n;
BigInteger tengo;
Scanner in = new Scanner(System.in);
n = in.nextInt();
String cad;
for(int i = 1; i <= n; i++){
cad = in.next();
arr[i] = in.nextInt();
if(cad.charAt(0) == 'w') gano[i] = true;
}
mayor[0] = BigInteger.ZERO;
for(int i = 1; i <= n; i++){
mayor[i] = mayor[i - 1].add(BigInteger.ZERO);
if(!gano[i]){
donde = -1;
for(int j = i - 1; j > 0; j--)
if((gano[j]) && arr[i] == arr[j]){
donde = j;
break;
}
if(donde != -1){
tengo = new BigInteger("1");
tengo = tengo.shiftLeft(arr[i]); // valor
mayor[i] = mayor[i].max(tengo.add(mayor[donde - 1]));
}
}
}
System.out.println(mayor[n]);
}
}
| Java | ["7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "3\nwin 5\nsell 6\nsell 4"] | 2 seconds | ["1056", "0"] | null | Java 7 | standard input | [
"dp",
"greedy",
"brute force"
] | 217a3a48b927213f4d5e0a19048e2a32 | The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). | 2,000 | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | standard output | |
PASSED | 1c27d1eef7029ba19d285094033edaae | train_000.jsonl | 1276700400 | Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. | 128 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException{
//InputStream inputStream = new File("input.txt");
//OutputStream outputStream = new File("output.txt");
//Scanner in = new Scanner(new File("input.txt"));
//PrintWriter out = new PrintWriter(new File("output.txt"));
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int[] fs = new int[2010];
int[] ls = new int[2010];
for(int i = 0; i < 2010; ++i){
ls[i] = -1;
fs[i] = -1;
}
int n = in.nextInt();
String s;
int x;
for(int i = 0; i < n; ++i){
s = in.next();
x = in.nextInt();
if(Objects.equals(s, "win")){
if(ls[x] == -1) {
fs[x] = i;
}
}else{
ls[x] = i;
}
}
BigInteger sum = BigInteger.ZERO;
int[] t = new int[5010];
for(int i = 0; i < 5010; ++i){
t[i] = -1;
}
for(int i = 2000; i >= 0; --i){
if(fs[i] != -1 && ls[i] != -1 && fs[i] < ls[i]) {
Boolean b = true;
for (int j = fs[i]; j <= ls[i]; ++j){
if(t[j] != -1){
b = false;
break;
}
}
if(b){
sum = sum.add(BigInteger.valueOf(2).pow(i));
for(int j = fs[i]; j <= ls[i]; ++j){
t[j] = 1;
}
}
}
}
out.println(sum.toString());
out.flush();
}
}
// Thu Mar 31 2016 20:37:16 GMT+0300 (MSK) | Java | ["7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "3\nwin 5\nsell 6\nsell 4"] | 2 seconds | ["1056", "0"] | null | Java 7 | standard input | [
"dp",
"greedy",
"brute force"
] | 217a3a48b927213f4d5e0a19048e2a32 | The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). | 2,000 | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | standard output | |
PASSED | c733077a86b310cf6ef1e0f042eb6ad2 | train_000.jsonl | 1276700400 | Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. | 128 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException{
//InputStream inputStream = new File("input.txt");
//OutputStream outputStream = new File("output.txt");
//Scanner in = new Scanner(new File("input.txt"));
//PrintWriter out = new PrintWriter(new File("output.txt"));
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int[] fs = new int[2010];
int[] ls = new int[2010];
for(int i = 0; i < 2010; ++i){
ls[i] = -1;
fs[i] = -1;
}
int n = in.nextInt();
String s;
int x;
for(int i = 0; i < n; ++i){
s = in.next();
x = in.nextInt();
if(Objects.equals(s, "win")){
if(ls[x] == -1) {
fs[x] = i;
}
}else{
ls[x] = i;
}
}
BigInteger sum = BigInteger.ZERO;
int[] t = new int[5010];
for(int i = 0; i < 5010; ++i){
t[i] = -1;
}
for(int i = 2000; i >= 0; --i){
if(fs[i] != -1 && ls[i] != -1 && fs[i] < ls[i]) {
Boolean b = true;
for (int j = fs[i]; j <= ls[i]; ++j){
if(t[j] != -1){
b = false;
break;
}
}
if(b){
sum = sum.add(BigInteger.valueOf(2).pow(i));
for(int j = fs[i]; j <= ls[i]; ++j){
t[j] = 1;
}
}
}
}
out.println(sum.toString());
out.flush();
}
}
// Thu Mar 31 2016 20:36:19 GMT+0300 (MSK) | Java | ["7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "3\nwin 5\nsell 6\nsell 4"] | 2 seconds | ["1056", "0"] | null | Java 7 | standard input | [
"dp",
"greedy",
"brute force"
] | 217a3a48b927213f4d5e0a19048e2a32 | The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). | 2,000 | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | standard output | |
PASSED | f019022c21d6aa16ba21a34d8134b80a | train_000.jsonl | 1276700400 | Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. | 128 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException{
//InputStream inputStream = new File("input.txt");
//OutputStream outputStream = new File("output.txt");
//Scanner in = new Scanner(new File("input.txt"));
//PrintWriter out = new PrintWriter(new File("output.txt"));
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int[] fs = new int[2010];
int[] ls = new int[2010];
for(int i = 0; i < 2010; ++i){
ls[i] = -1;
fs[i] = -1;
}
int n = in.nextInt();
String s;
int x;
for(int i = 0; i < n; ++i){
s = in.next();
x = in.nextInt();
if(Objects.equals(s, "win")){
if(ls[x] == -1) {
fs[x] = i;
}
}else{
ls[x] = i;
}
}
BigInteger sum = BigInteger.ZERO;
int[] t = new int[5010];
for(int i = 0; i < 5010; ++i){
t[i] = -1;
}
for(int i = 2000; i >= 0; --i){
if(fs[i] != -1 && ls[i] != -1 && fs[i] < ls[i]) {
Boolean b = true;
for (int j = fs[i]; j <= ls[i]; ++j){
if(t[j] != -1){
b = false;
break;
}
}
if(b){
sum = sum.add(BigInteger.valueOf(2).pow(i));
for(int j = fs[i]; j <= ls[i]; ++j){
t[j] = 1;
}
}
}
}
out.println(sum.toString());
out.flush();
}
}
// Thu Mar 31 2016 20:39:50 GMT+0300 (MSK) | Java | ["7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "3\nwin 5\nsell 6\nsell 4"] | 2 seconds | ["1056", "0"] | null | Java 7 | standard input | [
"dp",
"greedy",
"brute force"
] | 217a3a48b927213f4d5e0a19048e2a32 | The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). | 2,000 | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | standard output | |
PASSED | ec51e6ac11ae1a84203b6f78bb566fc3 | train_000.jsonl | 1276700400 | Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. | 128 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
public class Program implements Runnable {
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
Thread thread = new Thread(new Program(in, out));
thread.start();
thread.join();
}
final Scanner in;
final PrintWriter out;
Program(Scanner in, PrintWriter out) {
this.in = in;
this.out = out;
}
public void run() {
out.println(solve());
out.flush();
}
class Segment implements Comparable<Segment> {
final int value;
final int start;
final int end;
public Segment(int value, int start, int end) {
this.value = value;
this.start = start;
this.end = end;
}
public int compareTo(Segment other) {
//return this.start - other.start;
return this.value - other.value;
}
public boolean intersects(Segment other) {
boolean left = other.end < this.start;
boolean right = other.start > this.end;
return !(left || right);
}
public String toString() {
return "" + value + "(" + start + ", " + end +")";
}
}
BigInteger solve() {
final int MAX_MEMORY = 2000;
List<Segment> segments = new ArrayList<Segment>();
int[] latestWins = new int[MAX_MEMORY + 1];
Arrays.fill(latestWins, -1);
int n = in.nextInt();
for (int i = 0; i < n; i++) {
String action = in.next();
int mem = in.nextInt();
if (action.equals("win")) {
latestWins[mem] = i;
} else {
int start = latestWins[mem];
if (start != -1) {
segments.add(new Segment(mem, start, i));
}
}
}
Collections.sort(segments);
BigInteger revenue = BigInteger.ZERO;
// for (int i = 0; i < segments.size();) {
// boolean take = true;
// Segment seg = segments.get(i);
// int j = i + 1;
// while (j < segments.size()) {
// Segment seg2 = segments.get(j);
// if (seg2.start > seg.end) {
// break;
// }
// if (seg2.value > seg.value) {
// take = false;
// break;
// }
// j++;
// }
// if (take) {
// i = j;
// revenue = revenue.setBit(seg.value);
// } else {
// i++;
// }
// }
List<Segment> taken = new ArrayList<Segment>();
for (int i = segments.size() - 1; i >= 0; i--) {
boolean take = true;
Segment seg = segments.get(i);
for (Segment seg2 : taken) {
if (seg.intersects(seg2)) {
take = false;
break;
}
// out.printf("%s does not intersect with %s\n", seg, seg2);
}
// out.printf("%s : %s\n", seg, take);
if (take) {
taken.add(seg);
revenue = revenue.setBit(seg.value);
}
}
return revenue;
}
} | Java | ["7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "3\nwin 5\nsell 6\nsell 4"] | 2 seconds | ["1056", "0"] | null | Java 7 | standard input | [
"dp",
"greedy",
"brute force"
] | 217a3a48b927213f4d5e0a19048e2a32 | The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). | 2,000 | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | standard output | |
PASSED | 083e6e77265993186536d5a15b7036c2 | train_000.jsonl | 1276700400 | Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. | 128 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
public class D implements Runnable {
BufferedReader in;
PrintWriter out;
StringTokenizer st;
Random rnd;
final int none = 2001;
BigInteger[][] d;
BigInteger[] pows;
BigInteger getMax(BigInteger a, BigInteger b) {
if(a == null) {
return b;
} else if(b == null) {
return a;
} else if(a.compareTo(b) > 0) {
return a;
} else {
return b;
}
}
void solve() throws IOException {
int n = nextInt();
pows = new BigInteger[none];
for(int i = 0; i < none; i++) {
pows[i] = BigInteger.valueOf(2).pow(i);
}
d = new BigInteger[n + 1][none + 1];
d[0][none] = BigInteger.ZERO;
for(int i = 1; i <= n; i++) {
String act = nextToken();
int x = nextInt();
BigInteger lastMaxValue = null;
for(int j = 0; j <= none; j++) {
d[i][j] = d[i - 1][j];
lastMaxValue = getMax(lastMaxValue, d[i][j]);
}
if(act.equals("win")) {
d[i][x] = lastMaxValue;
} else if(act.equals("sell")) {
if(d[i][x] != null) {
d[i][none] = getMax(d[i][none], d[i][x].add(pows[x]));
}
} else {
throw new AssertionError();
}
}
BigInteger res = getMax(BigInteger.ZERO, d[n][none]);
out.println(res);
}
public static void main(String[] args) {
final boolean oldChecker = false;
if(oldChecker) {
new Thread(null, new D(), "yarrr", 1 << 24).start();
} else {
new D().run();
}
}
public void run() {
try {
final String className = this.getClass().getName().toLowerCase();
try {
in = new BufferedReader(new FileReader(className + ".in"));
out = new PrintWriter(new FileWriter(className + ".out"));
} catch (FileNotFoundException e) {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}
rnd = new Random();
solve();
out.close();
} catch (IOException e) {
e.printStackTrace();
System.exit(42);
}
}
String nextToken() throws IOException {
while (st == null || !st.hasMoreTokens()) {
String line = in.readLine();
if (line == null) {
return null;
}
st = new StringTokenizer(line);
}
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
} | Java | ["7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "3\nwin 5\nsell 6\nsell 4"] | 2 seconds | ["1056", "0"] | null | Java 7 | standard input | [
"dp",
"greedy",
"brute force"
] | 217a3a48b927213f4d5e0a19048e2a32 | The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). | 2,000 | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | standard output | |
PASSED | 06a4226d36463d399d0c880a22d45255 | train_000.jsonl | 1276700400 | Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. | 128 megabytes | import java.math.BigInteger;
import java.util.LinkedList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
final int SIZE = 2001;
int N = in.nextInt();
int[] sell = new int[SIZE];
int[] win = new int[SIZE];
boolean[] take = new boolean[SIZE];
LinkedList<Integer> ranges = new LinkedList<Integer>();
String word;
int x;
for (int i = 1; i <= N; ++i) {
word = in.next();
x = in.nextInt();
if (word.equals("sell")) {
if (win[x] > 0) {
sell[x] = i;
take[x] = true;
}
} else {
if (take[x] == false)
win[x] = i;
}
}
boolean yeap = false;
BigInteger sum = new BigInteger("0");
BigInteger base = new BigInteger("2");
for (int i = 2000; i >= 0; --i) {
if (take[i]) {
yeap = true;
for (int j : ranges)
if (!((win[i] < win[j] && sell[i] < win[j]) || (win[i] > sell[j] && sell[i] > sell[j]))) {
yeap = false;
break;
}
if (yeap) {
sum = sum.add(base.pow(i));
ranges.add(i);
}
}
}
System.out.print(sum);
}
} | Java | ["7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "3\nwin 5\nsell 6\nsell 4"] | 2 seconds | ["1056", "0"] | null | Java 7 | standard input | [
"dp",
"greedy",
"brute force"
] | 217a3a48b927213f4d5e0a19048e2a32 | The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). | 2,000 | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | standard output | |
PASSED | 5b52063f5b9d41fece461e10f4fe16e8 | train_000.jsonl | 1276700400 | Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. | 128 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.StringTokenizer;
public class SellerBob {
static int[] t;
static int[] v;
static BigInteger[][] dp;
static BigInteger max(BigInteger a, BigInteger b) {
return a.compareTo(b) > 0 ? a : b;
}
static BigInteger pow(int x) {
if (x == 0)
return BigInteger.ONE;
if (x % 2 == 1)
return BigInteger.valueOf(2).multiply(pow(x - 1));
BigInteger res = pow(x / 2);
return res.multiply(res);
}
static BigInteger solve(int i, int x) {
if (i == t.length)
return BigInteger.ZERO;
if (dp[i][x + 1] != null)
return dp[i][x + 1];
if (t[i] == 0)
return dp[i][x + 1] = max(solve(i + 1, v[i]), solve(i + 1, x));
BigInteger ans = solve(i + 1, x);
if (v[i] == x)
ans = max(ans, pow(x).add(solve(i + 1, -1)));
return dp[i][x + 1] = ans;
}
public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
sc = new StringTokenizer("");
int n = nxtInt();
t = new int[n];
v = new int[n];
for (int i = 0; i < n; i++) {
if (nxtTok().equals("win"))
t[i] = 0;
else
t[i] = 1;
v[i] = nxtInt();
}
dp = new BigInteger[n][2002];
out.println(solve(0, -1));
br.close();
out.close();
}
static BufferedReader br;
static StringTokenizer sc;
static PrintWriter out;
static String nxtTok() throws IOException {
while (!sc.hasMoreTokens()) {
String s = br.readLine();
if (s == null)
return null;
sc = new StringTokenizer(s.trim());
}
return sc.nextToken();
}
static int nxtInt() throws IOException {
return Integer.parseInt(nxtTok());
}
static long nxtLng() throws IOException {
return Long.parseLong(nxtTok());
}
static double nxtDbl() throws IOException {
return Double.parseDouble(nxtTok());
}
static int[] nxtIntArr(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nxtInt();
return a;
}
static long[] nxtLngArr(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nxtLng();
return a;
}
static char[] nxtCharArr() throws IOException {
return nxtTok().toCharArray();
}
} | Java | ["7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "3\nwin 5\nsell 6\nsell 4"] | 2 seconds | ["1056", "0"] | null | Java 7 | standard input | [
"dp",
"greedy",
"brute force"
] | 217a3a48b927213f4d5e0a19048e2a32 | The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). | 2,000 | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | standard output | |
PASSED | cc24429789cfea0a08d62e1d87b49a4d | train_000.jsonl | 1276700400 | Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. | 128 megabytes | import java.util.Scanner;
import java.math.BigInteger;
import java.io.*;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n = cin.nextInt();
String []op = new String[n];
int []val = new int[n];
BigInteger []dp = new BigInteger[n];
BigInteger TWO = BigInteger.valueOf(2);
int i, j;
for(i = 0; i < n; ++i)
{
op[i] = cin.next();
val[i] = cin.nextInt();
}
dp[0] = BigInteger.ZERO;
for(i = 1; i < n; ++i) {
dp[i] = dp[i - 1];
if(op[i].length() == 4)
for(j = i - 1; j >= 0; --j)
if(val[i] == val[j] && op[j].length() == 3)
dp[i] = dp[i].max(dp[j].add(TWO.pow(val[j])));
}
System.out.println(dp[n - 1]);
}
} | Java | ["7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "3\nwin 5\nsell 6\nsell 4"] | 2 seconds | ["1056", "0"] | null | Java 7 | standard input | [
"dp",
"greedy",
"brute force"
] | 217a3a48b927213f4d5e0a19048e2a32 | The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). | 2,000 | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | standard output | |
PASSED | 9888736b6d53728f0e768921ff30e194 | train_000.jsonl | 1276700400 | Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. | 128 megabytes | import java.math.BigInteger;
import java.util.Scanner;
public class Main {
static Scanner sc = new Scanner(System.in);
static int n,v[],ty[];
static BigInteger dp[]= new BigInteger[5009];
/*static BigInteger solve(int i,int l)
{
if(i==n) return BigInteger.ZERO;
if(!dp[i][l].equals(new BigInteger("-1"))) return dp[i][l];
if(ty[i]==0) dp[i][l]=solve(i+1,l).max(solve(i+1,v[i]));
else if(l==v[i]) dp[i][l]=solve(i+1,n+1).add(new BigInteger("2").pow(l));
else dp[i][l]=BigInteger.ZERO;
return dp[i][l];
}*/
public static void main(String[] args) {
n= sc.nextInt();
v = new int[n];
ty = new int [n];
for (int i = 0; i < n; i++) {
String s = sc.next();
int r = sc.nextInt();
ty[i]=((s.charAt(0)=='s')?1:0);
v[i]=r;
}
/*for (int i = 0; i < 2010; i++) {
dp[n%2][i]=BigInteger.ZERO;
}
for (int i = n-1; i >= 0; i--) {
for (int j = 0; j < 2010; j++) {
if(ty[i]==0){//win
dp[i%2][j]=dp[(i+1)%2][j].max(dp[(i+1)%2][v[i]]);
}
else if(v[i]==j){
//System.out.println(j);
dp[i%2][j]=dp[(i+1)%2][2001].add(new BigInteger("2").pow(j));
}
else dp[i%2][j]=BigInteger.ZERO;
}
}
BigInteger an=BigInteger.ZERO;
for (int i = n; i >= 0; i--) {
an=dp[0][i].max(an);
}
**/
dp[0]=BigInteger.ZERO;
for (int i = 1; i < n; i++) {
if(ty[i]==0){
dp[i]=dp[i-1];
}
else{
dp[i]=dp[i-1];
for(int j=0;j<i;j++){
if(ty[j]==0&&v[j]==v[i]){
dp[i]=dp[i].max(dp[j].add(new BigInteger("2").pow(v[j])));
}
}
}
}
System.out.println(dp[n-1]);
}
}
| Java | ["7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "3\nwin 5\nsell 6\nsell 4"] | 2 seconds | ["1056", "0"] | null | Java 7 | standard input | [
"dp",
"greedy",
"brute force"
] | 217a3a48b927213f4d5e0a19048e2a32 | The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). | 2,000 | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | standard output | |
PASSED | 6802af9eb6a9b32d08075afa141a8c47 | train_000.jsonl | 1276700400 | Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. | 128 megabytes | import java.util.*;
import java.math.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
String s[] = new String[n+1];
int x[] = new int[n+1];
BigInteger dp[] = new BigInteger[n+1];
dp[0] = BigInteger.ZERO;
for(int i = 1; i <= n; ++i)
{
s[i] = in.next();
x[i] = in.nextInt();
dp[i] = dp[i-1];
if(s[i].compareTo("sell") == 0)
for(int j = 1; j < i; ++j)
if(x[i] == x[j] && s[j].compareTo("win") == 0){
BigInteger tmp = dp[j-1];
tmp = tmp.add(BigInteger.valueOf(2).pow(x[i]));
if(tmp.compareTo(dp[i]) > 0)
dp[i] = tmp;
}
}
System.out.println(dp[n]);
}
}
| Java | ["7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "3\nwin 5\nsell 6\nsell 4"] | 2 seconds | ["1056", "0"] | null | Java 7 | standard input | [
"dp",
"greedy",
"brute force"
] | 217a3a48b927213f4d5e0a19048e2a32 | The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). | 2,000 | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | standard output | |
PASSED | 0160eca48597d83b51e58bc49689a25f | train_000.jsonl | 1276700400 | Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. | 128 megabytes | import java.io.BufferedInputStream;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static final BigInteger neg = BigInteger.valueOf(-1);
public static final BigInteger two = BigInteger.valueOf(2);
public static BigInteger[][] dp = new BigInteger[2002][5001];
public static String[] s = new String[5001];
public static int[] a = new int[5001];
public static int n;
public static BigInteger calc(int last, int cur) {
if( cur >= n )
return BigInteger.ZERO;
if( !dp[last][cur].equals(neg) )
return dp[last][cur];
dp[last][cur] = BigInteger.ZERO;
if( a[cur] == last && s[cur].equals("sell") )
dp[last][cur] = calc(2001, cur+1).add(two.pow(a[cur]));
BigInteger r1 = BigInteger.ZERO, r2 = BigInteger.ZERO;
if( s[cur].equals("win") )
r1 = calc(a[cur], cur+1);
r2 = calc(last, cur+1);
return dp[last][cur] = r1.max(r2).max(dp[last][cur]);
}
public static void main(String[] args) {
Scanner scan = new Scanner(new BufferedInputStream(System.in));
while( scan.hasNext() )
{
n = scan.nextInt();
for( int i = 0 ; i < 2002 ; i++ )
for( int j = 0 ; j < 5001 ; j++ )
dp[i][j] = neg;
for( int i = 0 ; i < n ; i++ )
{
s[i] = scan.next();
a[i] = scan.nextInt();
}
System.out.println(calc(0, 0));
}
}
}
| Java | ["7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "3\nwin 5\nsell 6\nsell 4"] | 2 seconds | ["1056", "0"] | null | Java 7 | standard input | [
"dp",
"greedy",
"brute force"
] | 217a3a48b927213f4d5e0a19048e2a32 | The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). | 2,000 | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | standard output | |
PASSED | a9cd36dee0f9df699de1e7c1a4bfabb6 | train_000.jsonl | 1276700400 | Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. | 128 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
public class Solution {
final static int M = 2001;
public void run() {
try {
int n = reader.nextInt();
int[] hash = new int[M];
Arrays.fill(hash, -1);
int[][] order = new int[M][];
for (int i = 0; i < n; ++ i) {
String type = reader.next();
int x = reader.nextInt();
if (type.equals("win")) {
hash[x] = i;
} else if (hash[x] != -1) {
order[x] = new int[]{hash[x], i};
}
}
boolean[] used = new boolean[n];
boolean[] pick = new boolean[M];
for (int i = M - 1; i >= 0; -- i) {
if (order[i] == null) {
continue;
}
boolean valid = true;
for (int x = order[i][0]; x <= order[i][1]; ++ x) {
valid &= !used[x];
}
if (valid) {
pick[i] = true;
for (int x = order[i][0]; x <= order[i][1]; ++ x) {
used[x] = true;
}
}
}
BigInteger answer = BigInteger.ZERO;
BigInteger power = BigInteger.ONE;
for (int i = 0; i < M; ++ i) {
if (pick[i]) {
answer = answer.add(power);
}
power = power.multiply(BigInteger.valueOf(2));
}
writer.println(answer);
} catch (IOException ex) {
}
writer.close();
}
InputReader reader;
PrintWriter writer;
Solution() {
reader = new InputReader();
writer = new PrintWriter(System.out);
}
public static void main(String[] args) {
new Solution().run();
}
}
class InputReader {
BufferedReader reader;
StringTokenizer tokenizer;
InputReader() {
reader = new BufferedReader(new InputStreamReader(System.in));
tokenizer = new StringTokenizer("");
}
String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
Integer nextInt() throws IOException {
return Integer.parseInt(next());
}
}
| Java | ["7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "3\nwin 5\nsell 6\nsell 4"] | 2 seconds | ["1056", "0"] | null | Java 7 | standard input | [
"dp",
"greedy",
"brute force"
] | 217a3a48b927213f4d5e0a19048e2a32 | The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). | 2,000 | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | standard output | |
PASSED | 0ddf167499d4d09cbb79508de5e8b5ca | train_000.jsonl | 1276700400 | Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. | 128 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner cin=new Scanner(System.in);
int n=cin.nextInt();
int[] next=new int[n];
int[] val=new int[n];
BigInteger[] dp=new BigInteger[n+1];
BigInteger[] p2=new BigInteger[2001];
p2[0]=BigInteger.ONE;
for(int i=1;i<=2000;++i)
p2[i]=p2[i-1].multiply(BigInteger.valueOf(2));
String[] s=new String[n];
for(int i=0;i<n;++i){
s[i]=cin.next();
val[i]=cin.nextInt();
}
for(int i=0;i<n;++i){
next[i]=-1;
if(s[i].equals("win"))
for(int j=i+1;j<n;++j)
if(val[j]==val[i] && s[j].equals("sell"))
next[i]=j;
}
dp[n]=BigInteger.ZERO;
BigInteger tmp;
for(int i=n-1;i>=0;--i){
dp[i]=dp[i+1];
if(next[i]!=-1){
tmp=dp[next[i]].add(p2[val[i]]);
if(dp[i].compareTo(tmp)<0)
dp[i]=tmp;
}
}
System.out.println(dp[0]);
}
} | Java | ["7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "3\nwin 5\nsell 6\nsell 4"] | 2 seconds | ["1056", "0"] | null | Java 7 | standard input | [
"dp",
"greedy",
"brute force"
] | 217a3a48b927213f4d5e0a19048e2a32 | The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). | 2,000 | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | standard output | |
PASSED | 7fa04068f99b0254ded77515b4d0584e | train_000.jsonl | 1276700400 | Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. | 128 megabytes | import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.*;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Task solver = new Task();
solver.solve(1, in, out);
out.close();
}
static class Task {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int a[] = new int[2048];
int v[] = new int[6000];
for (int i = 0; i < a.length; i++) {
a[i] = -1;
}
BigInteger b [] = new BigInteger[6000];
int n = in.nextInt();
int x;
BigInteger c = BigInteger.ZERO;
String type;
for (int i = 0; i < n; i++) {
type = in.next();
v[i] = x = in.nextInt();
if (Objects.equals(type, "win")) {
b[i] = c;
a[x] = i;
} else {
if (a[x] != -1) {
c = b[i] = b[a[x]].add(BigInteger.valueOf(2).pow(v[a[x]])).max(c);
}
}
}
out.println(c.toString());
/*BigInteger a = new BigInteger(in.next());
BigInteger b = new BigInteger(in.next());
BigDecimal d = BigDecimal.valueOf(in.nextDouble());
List<Integer> l = new ArrayList<Integer>();
Set<Integer> s = new TreeSet<Integer>();
for (Integer aa : s) {
out.print(aa);
}
Map<Integer, String> m = new HashMap<>();
for (Integer integer : m.keySet()) {
out.print(m.get(integer));
}
Iterator<Map.Entry<Integer, String>> jt = m.entrySet().iterator();
Collections.sort(l, new Comparator<Integer>() {
@Override
public int compare(Integer integer, Integer t1) {
return 0;
}
});*/
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
}
// Tue Mar 29 2016 22:33:58 GMT+0300 (MSK) | Java | ["7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "3\nwin 5\nsell 6\nsell 4"] | 2 seconds | ["1056", "0"] | null | Java 7 | standard input | [
"dp",
"greedy",
"brute force"
] | 217a3a48b927213f4d5e0a19048e2a32 | The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). | 2,000 | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | standard output | |
PASSED | 3a8f94e506e992ad574b896f53c7260d | train_000.jsonl | 1276700400 | Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. | 128 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException{
//InputStream inputStream = new File("input.txt");
//OutputStream outputStream = new File("output.txt");
//Scanner in = new Scanner(new File("input.txt"));
//PrintWriter out = new PrintWriter(new File("output.txt"));
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int[] fs = new int[2010];
int[] ls = new int[2010];
for(int i = 0; i < 2010; ++i){
ls[i] = -1;
fs[i] = -1;
}
int n = in.nextInt();
String s;
int x;
for(int i = 0; i < n; ++i){
s = in.next();
x = in.nextInt();
if(Objects.equals(s, "win")){
if(ls[x] == -1) {
fs[x] = i;
}
}else{
ls[x] = i;
}
}
BigInteger sum = BigInteger.ZERO;
int[] t = new int[5010];
for(int i = 0; i < 5010; ++i){
t[i] = -1;
}
for(int i = 2000; i >= 0; --i){
if(fs[i] != -1 && ls[i] != -1 && fs[i] < ls[i]) {
Boolean b = true;
for (int j = fs[i]; j <= ls[i]; ++j){
if(t[j] != -1){
b = false;
break;
}
}
if(b){
sum = sum.add(BigInteger.valueOf(2).pow(i));
for(int j = fs[i]; j <= ls[i]; ++j){
t[j] = 1;
}
}
}
}
out.println(sum.toString());
out.flush();
}
}
// Thu Mar 31 2016 20:36:25 GMT+0300 (MSK) | Java | ["7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "3\nwin 5\nsell 6\nsell 4"] | 2 seconds | ["1056", "0"] | null | Java 7 | standard input | [
"dp",
"greedy",
"brute force"
] | 217a3a48b927213f4d5e0a19048e2a32 | The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). | 2,000 | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | standard output | |
PASSED | 47cd900e38a7f793381ac8b31c76b9fb | train_000.jsonl | 1276700400 | Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. | 128 megabytes | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException{
//InputStream inputStream = new File("input.txt");
//OutputStream outputStream = new File("output.txt");
//Scanner in = new Scanner(new File("input.txt"));
//PrintWriter out = new PrintWriter(new File("output.txt"));
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int[] fs = new int[2010];
int[] ls = new int[2010];
for(int i = 0; i < 2010; ++i){
ls[i] = -1;
fs[i] = -1;
}
int n = in.nextInt();
String s;
int x;
for(int i = 0; i < n; ++i){
s = in.next();
x = in.nextInt();
if(Objects.equals(s, "win")){
if(ls[x] == -1) {
fs[x] = i;
}
}else{
ls[x] = i;
}
}
BigInteger sum = BigInteger.ZERO;
int[] t = new int[5010];
for(int i = 0; i < 5010; ++i){
t[i] = -1;
}
for(int i = 2000; i >= 0; --i){
if(fs[i] != -1 && ls[i] != -1 && fs[i] < ls[i]) {
Boolean b = true;
for (int j = fs[i]; j <= ls[i]; ++j){
if(t[j] != -1){
b = false;
break;
}
}
if(b){
sum = sum.add(BigInteger.valueOf(2).pow(i));
for(int j = fs[i]; j <= ls[i]; ++j){
t[j] = 1;
}
}
}
}
out.println(sum.toString());
out.flush();
}
}
// Thu Mar 31 2016 20:37:23 GMT+0300 (MSK) | Java | ["7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "3\nwin 5\nsell 6\nsell 4"] | 2 seconds | ["1056", "0"] | null | Java 7 | standard input | [
"dp",
"greedy",
"brute force"
] | 217a3a48b927213f4d5e0a19048e2a32 | The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). | 2,000 | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | standard output | |
PASSED | eab04717303e31d3a0fa39605da3b4c3 | train_000.jsonl | 1276700400 | Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. | 128 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
public class Main
{
public static void main ( String[] args ) throws IOException
{
Scanner in = new Scanner(System.in);
BufferedReader Reader = new BufferedReader(new InputStreamReader(System.in));
FastScanner sc = new FastScanner(Reader);
int n = in.nextInt();
BigInteger[] dp = new BigInteger[n];
int[] values = new int[n];
boolean[] types = new boolean[n];
for (int i = 0; i < n; ++i)
{
String operation = in.next();
if (operation.compareTo("win") == 0)
types[i] = true;
values[i] = in.nextInt();
if (i > 0)
dp[i] = dp[i - 1];
else
dp[i] = BigInteger.ZERO;
int ind = i - 1;
if (types[i])
continue;
while (ind >= 0)
{
if (types[ind] && values[ind] == values[i])
break;
--ind;
}
if (ind >= 0)
{
BigInteger tmp = ind > 0 ? dp[ind - 1] : BigInteger.ZERO;
tmp = tmp.add(BigInteger.valueOf(2).pow(values[i]));
if (tmp.compareTo(dp[i]) == 1)
dp[i] = tmp;
}
}
/* for (int i = 0; i < n; ++i)
System.out.print(dp[i] + " ");*/
System.out.print(dp[n - 1]);
System.out.close();
}
}
class FastScanner
{
private BufferedReader Reader;
private StringTokenizer Tokenizer;
public FastScanner (BufferedReader Reader)
{
this.Reader = Reader;
}
public String nextToken() throws IOException
{
while (Tokenizer == null || !Tokenizer.hasMoreTokens())
Tokenizer = new StringTokenizer(Reader.readLine());
return Tokenizer.nextToken();
}
public int nextInt() throws NumberFormatException, IOException
{
return Integer.parseInt(nextToken());
}
public long nextLong() throws NumberFormatException, IOException
{
return Long.parseLong(nextToken());
}
public double nextDouble() throws NumberFormatException, IOException
{
return Double.parseDouble(nextToken());
}
} | Java | ["7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "3\nwin 5\nsell 6\nsell 4"] | 2 seconds | ["1056", "0"] | null | Java 7 | standard input | [
"dp",
"greedy",
"brute force"
] | 217a3a48b927213f4d5e0a19048e2a32 | The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). | 2,000 | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | standard output | |
PASSED | 3c75a0960f0712259b69361550d8093c | train_000.jsonl | 1276700400 | Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars. Bob won some programming competition and got a 2x MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last n days, Bob wants to know, how much money he could have earned, if he had acted optimally. | 128 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
public class a {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
int[] sell = new int[5005];
int[] lastWin = new int[5005];
int[] it = new int[5005];
boolean[] done = new boolean[5005];
String[] op = new String[5005];
BigInteger[] dua = new BigInteger[5005];
Arrays.fill(sell, 0);
Arrays.fill(lastWin, 0);
Arrays.fill(done, false);
dua[0] = BigInteger.valueOf(1);
int i, j;
for(i = 1; i <= 2500; ++i)
dua[i] = dua[i-1].multiply(BigInteger.valueOf(2));
int n = in.nextInt();
for(i = 1; i <= n; ++i) {
op[i] = in.next();
it[i] = in.nextInt();
if(op[i].equals("sell"))
sell[it[i]] = i;
}
for(i = 1; i <= n; ++i) {
if(op[i].equals("win"))
if(i < sell[it[i]])
lastWin[it[i]] = i;
}
BigInteger ans = BigInteger.valueOf(0);
for(i = 2000; i >= 0; i--) {
if(sell[i] > 0 && lastWin[i] > 0) {
boolean ada = false;
for(j = lastWin[i]; j <= sell[i]; j++)
if(done[j])
ada = true;
if(!ada) {
ans = ans.add(dua[i]);
for(j = lastWin[i]; j <= sell[i]; j++)
done[j] = true;
}
}
}
out.println(ans);
out.close();
}
}
/* Java Template */
class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
} | Java | ["7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "3\nwin 5\nsell 6\nsell 4"] | 2 seconds | ["1056", "0"] | null | Java 7 | standard input | [
"dp",
"greedy",
"brute force"
] | 217a3a48b927213f4d5e0a19048e2a32 | The first input line contains number n (1 ≤ n ≤ 5000) — amount of Bob's working days. The following n lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2x MB memory stick (0 ≤ x ≤ 2000). It's guaranteed that for each x there is not more than one line sell x. Line win x stands for a day when Bob won a 2x MB memory stick (0 ≤ x ≤ 2000). | 2,000 | Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. | standard output | |
PASSED | 0a4b9bde2fdc06f41c4fb164bf964ce0 | train_000.jsonl | 1542033300 | You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters.You have to remove at most one (i.e. zero or one) character of this string in such a way that the string you obtain will be lexicographically smallest among all strings that can be obtained using this operation.String $$$s = s_1 s_2 \dots s_n$$$ is lexicographically smaller than string $$$t = t_1 t_2 \dots t_m$$$ if $$$n < m$$$ and $$$s_1 = t_1, s_2 = t_2, \dots, s_n = t_n$$$ or there exists a number $$$p$$$ such that $$$p \le min(n, m)$$$ and $$$s_1 = t_1, s_2 = t_2, \dots, s_{p-1} = t_{p-1}$$$ and $$$s_p < t_p$$$.For example, "aaa" is smaller than "aaaa", "abb" is smaller than "abc", "pqr" is smaller than "z". | 256 megabytes | /*
Aman Agarwal
algo.java
*/
import java.util.*;
import java.io.*;
public class A1076
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
static FastReader sc = new FastReader();
static PrintWriter out = new PrintWriter(System.out);
static int ni()throws IOException{return sc.nextInt();}
static long nl()throws IOException{return sc.nextLong();}
static int[][] nai2(int n,int m)throws IOException{int a[][] = new int[n][m];for(int i=0;i<n;i++)for(int j=0;j<m;j++)a[i][j] = ni();return a;}
static int[] nai(int N,int start)throws IOException{int[]A=new int[N+start];for(int i=start;i!=(N+start);i++){A[i]=ni();}return A;}
static Integer[] naI(int N,int start)throws IOException{Integer[]A=new Integer[N+start];for(int i=start;i!=(N+start);i++){A[i]=ni();}return A;}
static long[] nal(int N)throws IOException{long[]A=new long[N];for(int i=0;i!=N;i++){A[i]=nl();}return A;}
static char[] nac()throws IOException{char[]A=sc.next().toCharArray();return A;}
static void print(int arr[]){for(int i=0;i<arr.length;i++)out.print(arr[i]+" ");out.println();}
static void print(long arr[]){for(int i=0;i<arr.length;i++)out.print(arr[i]+" ");out.println();}
static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));} // return the number of set bits.
static boolean isPrime(int number){if(number==1) return false;if (number == 2 || number == 3){return true;}if (number % 2 == 0) {return false;}int sqrt = (int) Math.sqrt(number) + 1;for(int i = 3; i < sqrt; i += 2){if (number % i == 0){return false;}}return true;}
static boolean isPrime(long number){if(number==1) return false;if (number == 2 || number == 3){return true;}if (number % 2 == 0) {return false;}long sqrt = (long) Math.sqrt(number) + 1;for(int i = 3; i < sqrt; i += 2){if (number % i == 0){return false;}}return true;}
static int power(int n,int p){if(p==0)return 1;int a = power(n,p/2);a = a*a;int b = p & 1;if(b!=0){a = n*a;}return a;}
static long power(long n,long p){if(p==0)return 1;long a = power(n,p/2);a = a*a;long b = p & 1;if(b!=0){a = n*a;}return a;}
static void reverse(int[] a) {int b;for (int i = 0, j = a.length - 1; i < j; i++, j--) {b = a[i];a[i] = a[j];a[j] = b;}}
static void reverse(long[] a) {long b;for (int i = 0, j = a.length - 1; i < j; i++, j--) {b = a[i];a[i] = a[j];a[j] = b;}}
static void swap(int a[],int i,int j){a[i] = a[i] ^ a[j];a[j] = a[j] ^ a[i];a[i] = a[i] ^ a[j];}
static void swap(long a[],int i,int j){a[i] = a[i] ^ a[j];a[j] = a[j] ^ a[i];a[i] = a[i] ^ a[j];}
static int count(int n){int c=0;while(n>0){c++;n = n/10;}return c;}
static int[] prefix_sum(int a[],int n){int s[] = new int[n];s[0] = a[0];for(int i=1;i<n;i++){s[i] = a[i]+s[i-1];}return s;}
static long[] prefix_sum_int(int a[],int n){long s[] = new long[n];s[0] = (long)a[0];for(int i=1;i<n;i++){s[i] = ((long)a[i])+s[i-1];}return s;}
static long[] prefix_sum_Integer(Integer a[],int n){long s[] = new long[n];s[0] = (long)a[0];for(int i=1;i<n;i++){s[i] = ((long)a[i])+s[i-1];}return s;}
static long[] prefix_sum_long(long a[],int n){long s[] = new long[n];s[0] = a[0];for(int i=1;i<n;i++){s[i] = a[i]+s[i-1];}return s;}
static boolean isPerfectSquare(double x){double sr = Math.sqrt(x);return ((sr - Math.floor(sr)) == 0);}
static ArrayList<Integer> sieve(int n) {int k=0; boolean prime[] = new boolean[n+1];ArrayList<Integer> p_arr = new ArrayList<>();for(int i=0;i<n;i++) prime[i] = true;for(int p = 2; p*p <=n; p++){ k=p;if(prime[p] == true) { p_arr.add(p);for(int i = p*2; i <= n; i += p) prime[i] = false; } }for(int i = k+1;i<=n;i++){if(prime[i]==true)p_arr.add(i);}return p_arr;}
static boolean[] seive_check(int n) {boolean prime[] = new boolean[n+1];for(int i=0;i<n;i++) prime[i] = true;for(int p = 2; p*p <=n; p++){ if(prime[p] == true) { for(int i = p*2; i <= n; i += p) prime[i] = false; } }prime[1]=false;return prime;}
static int get_bits(int n){int p=0;while(n>0){p++;n = n>>1;}return p;}
static int get_bits(long n){int p=0;while(n>0){p++;n = n>>1;}return p;}
static int get_2_power(int n){if((n & (n-1))==0)return get_bits(n)-1;return -1;}
static int get_2_power(long n){if((n & (n-1))==0)return get_bits(n)-1;return -1;}
//gives the divisors of first n natural numbers in n*sqrt(n) time..
static ArrayList<ArrayList<Integer>> divisors_n(int n){int i,j;ArrayList<ArrayList<Integer>> ans = new ArrayList<>();ArrayList<Integer> arr = new ArrayList<>();arr.add(1);ans.add(arr);for (i = 2; i <= n; i++){arr = new ArrayList<>();for (j = 1; j * j <= i; j++){if (i % j == 0){arr.add(j);if (i / j != j)arr.add(i/j);}}ans.add(arr);} return ans;}
//gives divisors of a particular number in sqrt(n) time..
static ArrayList<Integer> divisors_1(int n){ArrayList<Integer> ans = new ArrayList<>();for (int i=1; i<=Math.sqrt(n); i++){if (n%i==0){if (n/i == i)ans.add(i);else{ans.add(i);ans.add(n/i);}}}return ans;}
static void close(){out.flush();}
/*-------------------------Main Code Starts(algo.java)----------------------------------*/
public static void solve() throws IOException
{
int n = ni();
char s[] = sc.next().toCharArray();
char c[] = new char[n-1];
boolean tr = false;
int k=0;
for(int i=0;i<n;i++)
{
if(tr==false && i==n-1)
break;
char p1 = s[i];
if(i==n-1)
c[k++] = p1;
else
{
char p2 = s[i+1];
if(p2<p1 && tr==false)
{
tr=true;
continue;
}
c[k++] = p1;
}
}
out.println(String.valueOf(c));
}
public static void main(String[] args) throws IOException
{
int test = 1;
//test = sc.nextInt();
while(test-- > 0)
{
solve();
}
close();
}
}
| Java | ["3\naaa", "5\nabcda"] | 1 second | ["aa", "abca"] | NoteIn the first example you can remove any character of $$$s$$$ to obtain the string "aa".In the second example "abca" < "abcd" < "abcda" < "abda" < "acda" < "bcda". | Java 8 | standard input | [
"greedy",
"strings"
] | c01fc2cb6efc7eef290be12015f8d920 | The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the length of $$$s$$$. The second line of the input contains exactly $$$n$$$ lowercase Latin letters — the string $$$s$$$. | 1,200 | Print one string — the smallest possible lexicographically string that can be obtained by removing at most one character from the string $$$s$$$. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.