exec_outcome stringclasses 1 value | code_uid stringlengths 32 32 | file_name stringclasses 111 values | prob_desc_created_at stringlengths 10 10 | prob_desc_description stringlengths 63 3.8k | prob_desc_memory_limit stringclasses 18 values | source_code stringlengths 117 65.5k | lang_cluster stringclasses 1 value | prob_desc_sample_inputs stringlengths 2 802 | prob_desc_time_limit stringclasses 27 values | prob_desc_sample_outputs stringlengths 2 796 | prob_desc_notes stringlengths 4 3k β | lang stringclasses 5 values | prob_desc_input_from stringclasses 3 values | tags listlengths 0 11 | src_uid stringlengths 32 32 | prob_desc_input_spec stringlengths 28 2.37k β | difficulty int64 -1 3.5k β | prob_desc_output_spec stringlengths 17 1.47k β | prob_desc_output_to stringclasses 3 values | hidden_unit_tests stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PASSED | 663408055e555db7f010b395bf590de6 | train_002.jsonl | 1492785300 | Mike has n strings s1,βs2,β...,βsn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".Now Mike asks himself: what is minimal number of moves that he needs to do in order to make all the strings equal? | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
static class TaskB {
public void solve(int testNumber, Scanner in, PrintWriter out) {
int n = in.nextInt();
String s = in.nextLine();
String[] a = new String[n];
String[] d = new String[n];
for (int i = 0; i < n; ++i) {
a[i] = in.nextLine();
d[i] = a[i] + a[i];
}
int N = a[0].length();
int ans = Integer.MAX_VALUE;
for (int i = 0; i < n; ++i) {
int cnt = 0;
String req = a[i];
for (int j = 0; j < n; ++j) {
int temp = d[j].indexOf(req);
if (temp > -1)
cnt += temp;
else {
out.println(-1);
return;
}
}
ans = Math.min(ans, cnt);
}
out.println(ans);
}
}
}
| Java | ["4\nxzzwo\nzwoxz\nzzwox\nxzzwo", "2\nmolzv\nlzvmo", "3\nkc\nkc\nkc", "3\naa\naa\nab"] | 2 seconds | ["5", "2", "0", "-1"] | NoteIn the first sample testcase the optimal scenario is to perform operations in such a way as to transform all strings into "zwoxz". | Java 8 | standard input | [
"dp",
"brute force",
"strings"
] | a3a7515219ebb0154218ee3520e20d75 | The first line contains integer n (1ββ€βnββ€β50) β the number of strings. This is followed by n lines which contain a string each. The i-th line corresponding to string si. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50. | 1,300 | Print the minimal number of moves Mike needs in order to make all the strings equal or print β-β1 if there is no solution. | standard output | |
PASSED | 41856bec20eafddf1bcf2b0929d6e6f9 | train_002.jsonl | 1492785300 | Mike has n strings s1,βs2,β...,βsn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".Now Mike asks himself: what is minimal number of moves that he needs to do in order to make all the strings equal? | 256 megabytes | import java.awt.List;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;
public class Main
{
InputStream is;
PrintWriter out;
String INPUT = "";
void solve()
{
int n=ni();
char[][] s=new char[n][];
for(int i=0;i<n;i++) {
s[i]=ns().toCharArray();
}
if(n==1) {
out.println(0);
return;
}
for(int i=1;i<n;i++) {
if(s[0].length!=s[i].length) {
out.println(-1);
return;
}
}
int ans=999999999;
for(int i=0;i<n;i++) {
int sum=0;
boolean flag=false;
inner:
for(int j=0;j<n;j++) {
if(i==j) {
continue inner;
}
char[] q=new char[s[j].length];
q=Arrays.copyOf(s[j], s[j].length);
for(int k=0;k<s[j].length;k++) {
if(Arrays.equals(s[i],q)) {
flag=true;
sum=sum+k;
continue inner;
}
q=rot(q);
}
if(!flag) {
out.println(-1);
return;
}
}
ans=Math.min(ans, sum);
}
out.println(ans);
}
char[] rotate(char[] q) {
char c=q[q.length-1];
for(int i=0;i<q.length-1;i++) {
q[i+1]=q[i];
}
q[0]=c;
return q;
}
char[] rot(char[] s)
{
char[]t = new char[s.length];
for(int i = 0, j = s.length-1;i < s.length;i++,j++){
if(j == s.length)j = 0;
t[j] = s[i];
}
return t;
}
void run() throws Exception
{
is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
}
public static void main(String[] args) throws Exception
{ new Main().run(); }
private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
private int readByte()
{
if(lenbuf == -1)throw new InputMismatchException();
if(ptrbuf >= lenbuf)
{
ptrbuf = 0;
try
{ lenbuf = is.read(inbuf); }
catch (IOException e)
{ throw new InputMismatchException(); }
if(lenbuf <= 0)return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c)
{ return !(c >= 33 && c <= 126); }
private int skip()
{ int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
private double nd()
{ return Double.parseDouble(ns()); }
private char nc()
{ return (char)skip(); }
private String ns()
{
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b)))
{ // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n)
{
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b)))
{
buf[p++] = (char)b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private char[][] nm(int n, int m)
{
char[][] map = new char[n][];
for(int i = 0;i < n;i++)map[i] = ns(m);
return map;
}
private int[] na(int n)
{
int[] a = new int[n];
for(int i = 0;i < n;i++)a[i] = ni();
return a;
}
private int ni()
{
int num = 0, b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-')
{
minus = true;
b = readByte();
}
while(true)
{
if(b >= '0' && b <= '9')
{
num = num * 10 + (b - '0');
}else
{
return minus ? -num : num;
}
b = readByte();
}
}
private long nl()
{
long num = 0;
int b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-')
{
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9')
{
num = num * 10 + (b - '0');
}else
{
return minus ? -num : num;
}
b = readByte();
}
}
private static void tr(Object... o)
{ System.out.println(Arrays.deepToString(o)); }
}
| Java | ["4\nxzzwo\nzwoxz\nzzwox\nxzzwo", "2\nmolzv\nlzvmo", "3\nkc\nkc\nkc", "3\naa\naa\nab"] | 2 seconds | ["5", "2", "0", "-1"] | NoteIn the first sample testcase the optimal scenario is to perform operations in such a way as to transform all strings into "zwoxz". | Java 8 | standard input | [
"dp",
"brute force",
"strings"
] | a3a7515219ebb0154218ee3520e20d75 | The first line contains integer n (1ββ€βnββ€β50) β the number of strings. This is followed by n lines which contain a string each. The i-th line corresponding to string si. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50. | 1,300 | Print the minimal number of moves Mike needs in order to make all the strings equal or print β-β1 if there is no solution. | standard output | |
PASSED | f0d165df79d945012f2f65ab14d1cd54 | train_002.jsonl | 1492785300 | Mike has n strings s1,βs2,β...,βsn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".Now Mike asks himself: what is minimal number of moves that he needs to do in order to make all the strings equal? | 256 megabytes |
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
public class Mikeandstrings {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
HashMap<String, Integer> h = new HashMap<String, Integer>();
String sb = scan.next();
int n = sb.length();
h.put(sb, 0);
for (int i = 0; i < n - 1; i++) {
char k = sb.charAt(0);
sb = sb.substring(1);
sb += k;
if (!h.containsKey(sb)) {
h.put(sb, i + 1);
}
}
while (t-- > 1) {
String s = scan.next();
HashSet<String> a = new HashSet<String>();
n = s.length();
if (!h.containsKey(s)) {
System.out.println("-1");
return;
}
a.add(s);
for (int i = 0; i < n - 1; i++) {
char k = s.charAt(0);
s = s.substring(1);
s += k;
if (!a.contains(s)) {
if (!h.containsKey(s)) {
System.out.println("-1");
return;
} else {
int u = h.get(s) + (i + 1);
h.put(s, u);
}
}
a.add(s);
}
}
int res = 1111111111;
for (Integer v : h.values()) {
res = Math.min(res, v);
}
System.out.println(res);
}
}
| Java | ["4\nxzzwo\nzwoxz\nzzwox\nxzzwo", "2\nmolzv\nlzvmo", "3\nkc\nkc\nkc", "3\naa\naa\nab"] | 2 seconds | ["5", "2", "0", "-1"] | NoteIn the first sample testcase the optimal scenario is to perform operations in such a way as to transform all strings into "zwoxz". | Java 8 | standard input | [
"dp",
"brute force",
"strings"
] | a3a7515219ebb0154218ee3520e20d75 | The first line contains integer n (1ββ€βnββ€β50) β the number of strings. This is followed by n lines which contain a string each. The i-th line corresponding to string si. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50. | 1,300 | Print the minimal number of moves Mike needs in order to make all the strings equal or print β-β1 if there is no solution. | standard output | |
PASSED | ca5126065dcba81a07c25a9755b6eecc | train_002.jsonl | 1492785300 | Mike has n strings s1,βs2,β...,βsn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".Now Mike asks himself: what is minimal number of moves that he needs to do in order to make all the strings equal? | 256 megabytes | import java.util.Scanner;
/**
* Created by abgupta on 4/21/17.
*/
public class C_798_B {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
String[] s = new String[n];
for(int i=0;i<n;i++) {
s[i] = in.next();
// System.out.println(s[i]);
}
int mx = 1000000;
int ans = mx;
for(int i=0;i<n;i++) {
int l = s[i].length();
for(int m=0;m<l;m++) {
String cans = s[i].substring(m,l) + s[i].substring(0, m);
//System.out.println("cans " + cans);
int cc = 0;
boolean can = true;
for (int j = 0; j < n; j++) {
boolean found = false;
for (int k = 0; k < l; k++) {
String s1 = s[j].substring(k, l) + s[j].substring(0, k);
//System.out.println(k + " " + s1);
if (s1.equals(cans)) {
cc += k;
found = true;
break;
}
}//k
if (!found) {
can = false;
break;
}
}//j
if (can) ans = Math.min(ans, cc);
}
}
System.out.println(ans == mx ? -1 : ans);
}
}
| Java | ["4\nxzzwo\nzwoxz\nzzwox\nxzzwo", "2\nmolzv\nlzvmo", "3\nkc\nkc\nkc", "3\naa\naa\nab"] | 2 seconds | ["5", "2", "0", "-1"] | NoteIn the first sample testcase the optimal scenario is to perform operations in such a way as to transform all strings into "zwoxz". | Java 8 | standard input | [
"dp",
"brute force",
"strings"
] | a3a7515219ebb0154218ee3520e20d75 | The first line contains integer n (1ββ€βnββ€β50) β the number of strings. This is followed by n lines which contain a string each. The i-th line corresponding to string si. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50. | 1,300 | Print the minimal number of moves Mike needs in order to make all the strings equal or print β-β1 if there is no solution. | standard output | |
PASSED | 5d1a3ca0dbb329a4fab2725738bdca9d | train_002.jsonl | 1492785300 | Mike has n strings s1,βs2,β...,βsn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".Now Mike asks himself: what is minimal number of moves that he needs to do in order to make all the strings equal? | 256 megabytes | import java.util.Scanner;
/**
* Created by abgupta on 4/21/17.
*/
public class C_798_B {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
String[] s = new String[n];
for(int i=0;i<n;i++) {
s[i] = in.next();
// System.out.println(s[i]);
}
int mx = 1000000;
int ans = mx;
for(int i=0;i<n;i++) {
String cans = s[i];
//System.out.println("cans " + cans);
int l = cans.length();
int cc = 0;
boolean can=true;
for(int j=0;j<n;j++) {
boolean found = false;
for(int k=0;k<l;k++) {
String s1 = s[j].substring(k, l) + s[j].substring(0, k);
// System.out.println(k + " " + s1);
if (s1.equals(cans)) {
cc+=k;
found = true;
break;
}
}//k
if (!found) {
can = false;
break;
}
}//j
if (can) ans = Math.min(ans, cc);
}
System.out.println(ans == mx ? -1 : ans);
}
}
| Java | ["4\nxzzwo\nzwoxz\nzzwox\nxzzwo", "2\nmolzv\nlzvmo", "3\nkc\nkc\nkc", "3\naa\naa\nab"] | 2 seconds | ["5", "2", "0", "-1"] | NoteIn the first sample testcase the optimal scenario is to perform operations in such a way as to transform all strings into "zwoxz". | Java 8 | standard input | [
"dp",
"brute force",
"strings"
] | a3a7515219ebb0154218ee3520e20d75 | The first line contains integer n (1ββ€βnββ€β50) β the number of strings. This is followed by n lines which contain a string each. The i-th line corresponding to string si. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50. | 1,300 | Print the minimal number of moves Mike needs in order to make all the strings equal or print β-β1 if there is no solution. | standard output | |
PASSED | e8f4232789dc04cfd9ff56bab9bcf64f | train_002.jsonl | 1492785300 | Mike has n strings s1,βs2,β...,βsn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".Now Mike asks himself: what is minimal number of moves that he needs to do in order to make all the strings equal? | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
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);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
static class TaskB {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
String[] a = new String[n];
int min = Integer.MAX_VALUE;
for (int i = 0; i < n; i++) {
a[i] = in.next();
}
for (int i = 0; i < a[0].length(); i++) {
String s = a[0].substring(i, a[0].length()) + a[0].substring(0, i);
int cnt = i;
for (int j = 1; j < n; j++) {
int cur = 1000000;
for (int k = 0; k < a[0].length(); k++) {
if (s.equals(a[j].substring(k, a[j].length()) + a[j].substring(0, k))) {
cur = k;
break;
}
}
if (cur > 100) {
out.println(-1);
return;
} else cnt += cur;
}
min = Math.min(cnt, min);
}
out.println(min);
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
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());
}
}
}
| Java | ["4\nxzzwo\nzwoxz\nzzwox\nxzzwo", "2\nmolzv\nlzvmo", "3\nkc\nkc\nkc", "3\naa\naa\nab"] | 2 seconds | ["5", "2", "0", "-1"] | NoteIn the first sample testcase the optimal scenario is to perform operations in such a way as to transform all strings into "zwoxz". | Java 8 | standard input | [
"dp",
"brute force",
"strings"
] | a3a7515219ebb0154218ee3520e20d75 | The first line contains integer n (1ββ€βnββ€β50) β the number of strings. This is followed by n lines which contain a string each. The i-th line corresponding to string si. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50. | 1,300 | Print the minimal number of moves Mike needs in order to make all the strings equal or print β-β1 if there is no solution. | standard output | |
PASSED | f57595e11d817c979e634d304b308e7f | train_002.jsonl | 1492785300 | Mike has n strings s1,βs2,β...,βsn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".Now Mike asks himself: what is minimal number of moves that he needs to do in order to make all the strings equal? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class B410 {
public static void main(String[] args)throws Exception{
int n = IO.nextInt();
if(n==1){IO.println(0);return;}
String d[] = new String[51];
for(int i=1;i<=n;++i)d[i] = IO.nextString();
int size = d[1].length();
int min = Integer.MAX_VALUE;
for(int i=0;i<size;++i){
int ch=i;
char c = d[1].charAt(i);
String fs = d[1].substring(i);
String ss = "";
if(i>0){
ss = d[1].substring(0, i);
}
String fins = fs+ss;
//IO.println("\n\nConsidering source "+fins);
boolean mall = true;
for(int j=2;j<=n;++j){
boolean m = false;
for(int k=0;k<size;++k){
if(d[j].charAt(k)==c){
String f = d[j].substring(k);
String s ="";
if(k>0){
s = d[j].substring(0, k);
}
String fin = f+s;
if(fin.contentEquals(fins)){
ch+=k;
m=true;
break;
//IO.println("for "+fin+" cost was "+Math.abs(k));
}
}
}
if(!m){
mall = false;
break;
}
}
if(!mall){IO.println(-1);return;}
if(ch<=min){
min=ch;
}
}
IO.println(min);
}
static class IO {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static int[][] next2dInt(int rows, int cols, String seperator) throws Exception {
int[][] arr = new int[rows + 1][cols + 1];
for (int i = 1; i <= rows; ++i) {
arr[i] = nextIntArray(cols, seperator);
}
return arr;
}
public static int[] nextIntArray(int nInts, String seperator) throws IOException {
String ints = br.readLine();
String[] sArray = ints.split(seperator);
int[] array = new int[nInts + 1];
for (int i = 1; i <= nInts; ++i) {
array[i] = Integer.parseInt(sArray[i - 1]);
}
return array;
}
public static long[] nextLongArray(int nLongs, String seperator) throws IOException {
String longs = br.readLine();
String[] sArray = longs.split(seperator);
long[] array = new long[nLongs + 1];
for (int i = 1; i <= nLongs; ++i) {
array[i] = Long.parseLong(sArray[i - 1]);
}
return array;
}
public static double[] nextDoubleArray(int nDoubles, String seperator) throws IOException {
String doubles = br.readLine();
String[] sArray = doubles.split(seperator);
double[] array = new double[nDoubles + 1];
for (int i = 1; i <= nDoubles; ++i) {
array[i] = Double.parseDouble(sArray[i - 1]);
}
return array;
}
public static char[] nextCharArray(int nChars, String seperator) throws IOException {
String chars = br.readLine();
String[] sArray = chars.split(seperator);
char[] array = new char[nChars + 1];
for (int i = 1; i <= nChars; ++i) {
array[i] = sArray[i - 1].charAt(0);
}
return array;
}
public static int nextInt() throws IOException {
String in = br.readLine();
return Integer.parseInt(in);
}
public static double nextDouble() throws IOException {
String in = br.readLine();
return Double.parseDouble(in);
}
public static long nextLong() throws IOException {
String in = br.readLine();
return Long.parseLong(in);
}
public static int nextChar() throws IOException {
String in = br.readLine();
return in.charAt(0);
}
public static String nextString() throws IOException {
return br.readLine();
}
public static void print(Object... o) {
for (Object os : o) {
System.out.print(os);
}
}
public static void println(Object... o) {
for (Object os : o) {
System.out.print(os);
}
System.out.print("\n");
}
public static void printlnSeperate(String seperator, Object... o) {
StringBuilder sb = new StringBuilder();
sb.delete(sb.length() - seperator.length(), sb.length());
System.out.println(sb);
}
}
}
| Java | ["4\nxzzwo\nzwoxz\nzzwox\nxzzwo", "2\nmolzv\nlzvmo", "3\nkc\nkc\nkc", "3\naa\naa\nab"] | 2 seconds | ["5", "2", "0", "-1"] | NoteIn the first sample testcase the optimal scenario is to perform operations in such a way as to transform all strings into "zwoxz". | Java 8 | standard input | [
"dp",
"brute force",
"strings"
] | a3a7515219ebb0154218ee3520e20d75 | The first line contains integer n (1ββ€βnββ€β50) β the number of strings. This is followed by n lines which contain a string each. The i-th line corresponding to string si. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50. | 1,300 | Print the minimal number of moves Mike needs in order to make all the strings equal or print β-β1 if there is no solution. | standard output | |
PASSED | 3db08498740f33ed7d4e27839f54fd7b | train_002.jsonl | 1492785300 | Mike has n strings s1,βs2,β...,βsn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".Now Mike asks himself: what is minimal number of moves that he needs to do in order to make all the strings equal? | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
private static String rotString(String str,int i){
// System.out.println("sd"+i+"f"+str);
String a=str.substring(0,i);
String b=str.substring(i);
return (b+a);
}
private static boolean check(String str1,String str2){
if(str1.length()!=str2.length()){
return false;
}
boolean res=true;
for(int i=0;i<str1.length();i++){
if(str1.charAt(i)!=str2.charAt(i)){
res=false;
break;
}
}
return res;
}
public static void main (String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String st[] = br.readLine().split(" ");
int n=Integer.parseInt(st[0]);
String input[]=new String[n];
for(int i=0;i<n;i++){
st=br.readLine().split(" ");
input[i]=st[0];
}
int n1=51;
String rot[][]=new String[n][n1];
for(int i=0;i<n;i++){
for(int j=0;j<n1;j++){
if(j<input[i].length())
rot[i][j]=rotString(input[i],j);
else
rot[i][j]="";
}
}
int dp[][]=new int[n][n1];
for(int i=0;i<n1;i++){
dp[0][i]=i;
}
for(int i=1;i<n;i++){
for(int j=0;j<n1;j++){
dp[i][j]=Integer.MAX_VALUE;
if(j<input[i].length()){
for(int k=0;k<n1;k++){
if(check(rot[i][j],(rot[i-1][k]))&&dp[i-1][k]!=Integer.MAX_VALUE){
dp[i][j]=Math.min(dp[i][j],dp[i-1][k]+j);
}
}}
}
}
/*
for(int i=0;i<n;i++){
for(int j=0;j<n1;j++){
System.out.print(dp[i][j]+" ");
}
System.out.println();
}
for(int i=0;i<n;i++){
for(int j=0;j<n1;j++){
System.out.print(rot[i][j]+" ");
}
System.out.println();
}*/
boolean q=true;
for(int i=0;i<input[n-1].length();i++){
if(dp[n-1][i]!=Integer.MAX_VALUE){
q=false;
}
}
if(q){
System.out.println(-1);
}
else{
int ans=Integer.MAX_VALUE;
for(int i=0;i<n1;i++){
ans=Math.min(ans,dp[n-1][i]);
}
System.out.println(ans);
}
// System.out.println(rotString("ab",1));
}
} | Java | ["4\nxzzwo\nzwoxz\nzzwox\nxzzwo", "2\nmolzv\nlzvmo", "3\nkc\nkc\nkc", "3\naa\naa\nab"] | 2 seconds | ["5", "2", "0", "-1"] | NoteIn the first sample testcase the optimal scenario is to perform operations in such a way as to transform all strings into "zwoxz". | Java 8 | standard input | [
"dp",
"brute force",
"strings"
] | a3a7515219ebb0154218ee3520e20d75 | The first line contains integer n (1ββ€βnββ€β50) β the number of strings. This is followed by n lines which contain a string each. The i-th line corresponding to string si. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50. | 1,300 | Print the minimal number of moves Mike needs in order to make all the strings equal or print β-β1 if there is no solution. | standard output | |
PASSED | 2a1a46affb5a36cd074c1ab21609f685 | train_002.jsonl | 1492785300 | Mike has n strings s1,βs2,β...,βsn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".Now Mike asks himself: what is minimal number of moves that he needs to do in order to make all the strings equal? | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Solver solver = new Solver();
solver.solve(in, out);
out.close();
}
static class Solver {
public void solve(InputReader in, PrintWriter out) {
int n = in.nextInt();
String[] s = new String[n];
for (int i = 0; i < n; ++i) {
s[i] = in.next();
}
boolean ok = true;
for (String str : s) {
for (String str1 : s) {
if (!str.equals(str1)) {
ok = false;
}
}
}
if (ok) {
out.println(0);
return;
}
int moves = 0;
int[] min = new int[n];
Arrays.fill(min, 3000);
int ind = 0;
outer:
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i != j) {
String tmp = s[j];
boolean does = false;
if (!s[i].equals(s[j])) {
for (int k = 0; k < s[j].length(); ++k) {
tmp = shift(tmp);
if (tmp.equals(s[i])) {
does = true;
moves += k + 1;
break;
}
}
if (!does) {
out.println(-1);
return;
}
}
}
}
if (moves != 0) {
min[ind++] = moves;
moves = 0;
}
}
Arrays.sort(min);
out.println(min[0]);
}
static String shift(String s) {
String temp = s.substring(1) + s.charAt(0);
return temp;
}
} // wubba lubba dub dub
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.hasMoreElements()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
} | Java | ["4\nxzzwo\nzwoxz\nzzwox\nxzzwo", "2\nmolzv\nlzvmo", "3\nkc\nkc\nkc", "3\naa\naa\nab"] | 2 seconds | ["5", "2", "0", "-1"] | NoteIn the first sample testcase the optimal scenario is to perform operations in such a way as to transform all strings into "zwoxz". | Java 8 | standard input | [
"dp",
"brute force",
"strings"
] | a3a7515219ebb0154218ee3520e20d75 | The first line contains integer n (1ββ€βnββ€β50) β the number of strings. This is followed by n lines which contain a string each. The i-th line corresponding to string si. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50. | 1,300 | Print the minimal number of moves Mike needs in order to make all the strings equal or print β-β1 if there is no solution. | standard output | |
PASSED | 21876351685334c9185c60b9dbdf8947 | train_002.jsonl | 1492785300 | Mike has n strings s1,βs2,β...,βsn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".Now Mike asks himself: what is minimal number of moves that he needs to do in order to make all the strings equal? | 256 megabytes | import java.util.Scanner;
public class main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
while (sc.hasNextInt()) {
int[][] count= new int[51][51];
String[] strings = new String[51];
int n;
n = sc.nextInt();
for(int i=0; i<n; i++){
strings[i] = sc.next();
}
int length = strings[0].length();
boolean flag = true;
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(i==j)
continue;
StringBuilder temp = new StringBuilder(strings[i]);
int k;
for(k=0; k<length; k++){
StringBuffer subString1 = new StringBuffer(temp.substring(k));
StringBuffer subString2 = new StringBuffer(temp.substring(0,k));
//subString2 = subString2.reverse();
subString1.append(subString2);
if(strings[j].equals(subString1.toString()))
break;
}
if(k == length){
flag = false;
break;
}
count[i][j]=k;
}
}
int ans=Integer.MAX_VALUE;
for(int i=0; i<n&&flag==true; i++){
int temp=0;
for(int j=0; j<n; j++){
temp+=count[j][i];
}
ans=Integer.min(ans,temp);
}
if(!flag){
System.out.println(-1);
}
else{
System.out.println(ans);
}
}
}
}
| Java | ["4\nxzzwo\nzwoxz\nzzwox\nxzzwo", "2\nmolzv\nlzvmo", "3\nkc\nkc\nkc", "3\naa\naa\nab"] | 2 seconds | ["5", "2", "0", "-1"] | NoteIn the first sample testcase the optimal scenario is to perform operations in such a way as to transform all strings into "zwoxz". | Java 8 | standard input | [
"dp",
"brute force",
"strings"
] | a3a7515219ebb0154218ee3520e20d75 | The first line contains integer n (1ββ€βnββ€β50) β the number of strings. This is followed by n lines which contain a string each. The i-th line corresponding to string si. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50. | 1,300 | Print the minimal number of moves Mike needs in order to make all the strings equal or print β-β1 if there is no solution. | standard output | |
PASSED | 9ddffc2213451327963a0af05d20f831 | train_002.jsonl | 1492785300 | Mike has n strings s1,βs2,β...,βsn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".Now Mike asks himself: what is minimal number of moves that he needs to do in order to make all the strings equal? | 256 megabytes | /*package whatever //do not write package name here */
import java.io.*;
import java.util.*;
public class Main {
public static int isRotation(String a, String b)
{
int nn = a.length();
// System.out.println(nn);
int c=0;
for(int i=0;i<nn;i++){
String vv = b.substring(i,nn)+b.substring(0,i);
//System.out.println(vv);
if(vv.equals(a)){
break;
}
c++;
}
//System.out.println(c);
return c;
}
public static void main (String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
String[] s = new String[10000];
in.nextLine();
for(int i=0;i<n;i++){
s[i]=in.next();
in.nextLine();
}
int[] c = new int[100000];
for(int i=0;i<s[0].length();i++){
c[s[0].charAt(i)]++;
}
int f=0;
for(int i=0;i<n;i++){
int[] x = new int[10000];
for(int j=0;j<s[0].length();j++){
x[s[i].charAt(j)]++;
}
for(int j=0;j<s[0].length();j++){
if(x[s[i].charAt(j)]!=c[s[i].charAt(j)]){
f=1;
break;
}
}
if(f==1){
break;
}
}
//System.out.println("hello");
int min=Integer.MAX_VALUE;
int v = s[0].length();
//System.out.println(v);
for(int i=0;i<s[0].length();i++){
String xx = s[0].substring(i,s[0].length())+s[0].substring(0,i);
//System.out.println(xx);
int count=0;
// System.out.println(n);
for(int j=0;j<n;j++){
if(isRotation(xx,s[j])>=v){
f=1;
break;
}
count+=isRotation(xx,s[j]);
// System.out.println(isRotation(xx,s[j]));
}
//System.out.println(count);
if(count<min){
min = count;
}
if(f==1){
break;
}
}
if(f==1){
System.out.println("-1");
}
else{
System.out.println(min);
}
in.close();
}
} | Java | ["4\nxzzwo\nzwoxz\nzzwox\nxzzwo", "2\nmolzv\nlzvmo", "3\nkc\nkc\nkc", "3\naa\naa\nab"] | 2 seconds | ["5", "2", "0", "-1"] | NoteIn the first sample testcase the optimal scenario is to perform operations in such a way as to transform all strings into "zwoxz". | Java 8 | standard input | [
"dp",
"brute force",
"strings"
] | a3a7515219ebb0154218ee3520e20d75 | The first line contains integer n (1ββ€βnββ€β50) β the number of strings. This is followed by n lines which contain a string each. The i-th line corresponding to string si. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50. | 1,300 | Print the minimal number of moves Mike needs in order to make all the strings equal or print β-β1 if there is no solution. | standard output | |
PASSED | c31238c1427616cef58a455a78a74d2d | train_002.jsonl | 1492785300 | Mike has n strings s1,βs2,β...,βsn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".Now Mike asks himself: what is minimal number of moves that he needs to do in order to make all the strings equal? | 256 megabytes | /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
//package springforth;
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author yabueh
*/
public class SpringForth {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// interface is a contract
//BigDecimal bd1=new BigDecimal("2.01");
//BigDecimal bd2=new BigDecimal("0.1"); // remember to use strings
//System.out.println(bd1.subtract(bd2));
//int[] x={12,3,4,1,2,3,4,1,1,1,1};
//System.out.println(Arrays.toString(x));
//boolean[] cond=new boolean[10];
//Arrays.fill(cond, true);
//System.out.println(Arrays.toString(cond));
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
ArrayList<String> s=new ArrayList<>();
for (int i=0;i<n;i++){
String temp=sc.next();
s.add(temp);
}
long mn=99999999999999L;
for (int i=0;i<n;i++){
long counter=0;
for (int j=0;j<n;j++){
if (i!=j)
counter+=f(s.get(i),s.get(j));
}
mn=Math.min(mn, counter);
}
System.out.println(((mn>=99999999999999L)?-1:mn));
}
public static long f(String a, String b){
String bb=b+b;
int index=bb.indexOf(a);
if (index==-1)
return 99999999999999L;
else
return index;
}
}
| Java | ["4\nxzzwo\nzwoxz\nzzwox\nxzzwo", "2\nmolzv\nlzvmo", "3\nkc\nkc\nkc", "3\naa\naa\nab"] | 2 seconds | ["5", "2", "0", "-1"] | NoteIn the first sample testcase the optimal scenario is to perform operations in such a way as to transform all strings into "zwoxz". | Java 8 | standard input | [
"dp",
"brute force",
"strings"
] | a3a7515219ebb0154218ee3520e20d75 | The first line contains integer n (1ββ€βnββ€β50) β the number of strings. This is followed by n lines which contain a string each. The i-th line corresponding to string si. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50. | 1,300 | Print the minimal number of moves Mike needs in order to make all the strings equal or print β-β1 if there is no solution. | standard output | |
PASSED | 66c065f780c3db9e3cc31232e7f3fc52 | train_002.jsonl | 1492785300 | Mike has n strings s1,βs2,β...,βsn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".Now Mike asks himself: what is minimal number of moves that he needs to do in order to make all the strings equal? | 256 megabytes |
import java.io.*;
import java.util.*;
public class Problems2 {
public static void main(String[] args) throws IOException {
FastScanner sc=new FastScanner(System.in);
int n=sc.nextInt();
String []a=new String[n];
String []a2=new String[n];
for(int i=0;i<n;i++){
a[i]=sc.next();
a2[i]=a[i]+a[i];
}
int l=a[0].length();
for(int i=0;i<n;i++){
if(a[i].length()!=l){
System.out.println("-1");
return;
}
for(int j=0;j<n;j++){
if(!a2[i].contains(a[j])){
System.out.println(-1);
return;
}
}
}
int ans=Integer.MAX_VALUE;
int c=0;
for(int i=0;i<n;i++){
c=0;
for(int j=0;j<n;j++){
if(a2[i].indexOf(a[j])!=0)
c+=a2[j].indexOf(a[i]);
}
ans=ans>c?c:ans;
}
System.out.println(ans);
}
public static void dis(int a[]){
for(int i=0;i<a.length;i++){
System.out.print(a[i]+" ");
}
System.out.println("");
}
//_________________________________
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(InputStream i) {
br = new BufferedReader(new InputStreamReader(i));
st = new StringTokenizer("");
}
public String next() throws IOException {
if(st.hasMoreTokens())
return st.nextToken();
else
st = new StringTokenizer(br.readLine());
return next();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
//#
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public double nextDouble() throws IOException {
return Double.parseDouble(next());
}
//$
}
}
| Java | ["4\nxzzwo\nzwoxz\nzzwox\nxzzwo", "2\nmolzv\nlzvmo", "3\nkc\nkc\nkc", "3\naa\naa\nab"] | 2 seconds | ["5", "2", "0", "-1"] | NoteIn the first sample testcase the optimal scenario is to perform operations in such a way as to transform all strings into "zwoxz". | Java 8 | standard input | [
"dp",
"brute force",
"strings"
] | a3a7515219ebb0154218ee3520e20d75 | The first line contains integer n (1ββ€βnββ€β50) β the number of strings. This is followed by n lines which contain a string each. The i-th line corresponding to string si. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50. | 1,300 | Print the minimal number of moves Mike needs in order to make all the strings equal or print β-β1 if there is no solution. | standard output | |
PASSED | 9c10f9a0e9455759ea0383fba3612ddb | train_002.jsonl | 1492785300 | Mike has n strings s1,βs2,β...,βsn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".Now Mike asks himself: what is minimal number of moves that he needs to do in order to make all the strings equal? | 256 megabytes | import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.HashMap;
public class B{
public static void main(String[]arg){
new B().read();
}
HashMap<String, Integer> []dp;
String[]ss;
public void read(){
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int n,i;
String line;
try{
n = Integer.parseInt(in.readLine());
dp = new HashMap[n];
ss = new String[n];
for(i = 0; i < n; i++){
line = in.readLine();
ss[i] = line;
dp[i] = new HashMap<String, Integer>();
process(line, i);
}
System.out.println(minMoves());
}catch(Exception e){
}
}
int minMoves(){
int min = 50*50,i,cnt,j;
boolean found = true;
for(i = 0; i < ss.length && found; i++){
cnt = 0;
for(j = 0; j < ss.length && found; j++){
if(j != i){
if(!dp[j].containsKey(ss[i])) found = false;
else cnt += dp[j].get(ss[i]);
}
}
min = min > cnt ? cnt: min;
}
if(!found) min = -1;
return min;
}
void process(String s, int j){
int i;
for(i = 0; i < s.length(); i++){
if(dp[j].get(s) == null)dp[j].put(s, i);
s = s.substring(1, s.length()) + s.charAt(0);
}
}
} | Java | ["4\nxzzwo\nzwoxz\nzzwox\nxzzwo", "2\nmolzv\nlzvmo", "3\nkc\nkc\nkc", "3\naa\naa\nab"] | 2 seconds | ["5", "2", "0", "-1"] | NoteIn the first sample testcase the optimal scenario is to perform operations in such a way as to transform all strings into "zwoxz". | Java 8 | standard input | [
"dp",
"brute force",
"strings"
] | a3a7515219ebb0154218ee3520e20d75 | The first line contains integer n (1ββ€βnββ€β50) β the number of strings. This is followed by n lines which contain a string each. The i-th line corresponding to string si. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50. | 1,300 | Print the minimal number of moves Mike needs in order to make all the strings equal or print β-β1 if there is no solution. | standard output | |
PASSED | 85ae1a8732c8854a69ac4f950736fc4c | train_002.jsonl | 1492785300 | Mike has n strings s1,βs2,β...,βsn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".Now Mike asks himself: what is minimal number of moves that he needs to do in order to make all the strings equal? | 256 megabytes | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.ObjectInputStream.GetField;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
public class Q1 {
static long MOD = 1000000009;
static boolean b[], b1[], check;
static ArrayList<Integer>[] amp, pa;
static ArrayList<Pair>[] amp1;
static ArrayList<Pair>[][] damp;
static int left[],s[],right[],end[],sum[],dist[],cnt[],start[],color[],parent[],prime[],size[];
static long ans = 0,k;
static int p = 0;
static FasterScanner sc = new FasterScanner(System.in);
static Queue<Integer> q = new LinkedList<>();
static PriorityQueue<Pair> pq;
static BufferedWriter log;
static HashSet<Pair> hs;
static HashMap<Pair,Integer> hm;
static PriorityQueue<Integer> pri[];
static ArrayList<Integer>[] level;
static Stack<Integer> st;
static boolean boo[][];
static Pair prr[];
static long parent1[],parent2[],size1[],size2[],arr1[],SUM[],lev[], fibo[];
static int arr[], ver[][];
public static void main(String[] args) throws Exception {
/*new Thread(null, new Runnable() {
public void run() {
try {
} catch (Exception e) {
System.out.println(e);
}
}
}, "1", 1 << 26).start();*/
soln();
}
static int dp[][];
static int N,K,T;
static int time;
static int cost[][];
static boolean b11[];
static HashMap<Integer,Integer> h = new HashMap<>();
static HashSet<Pair> chec;
static long ans1; static long ans2;
static int BLOCK, MAX = 200000;
public static void soln() throws IOException {
//FasterScanner in = new FasterScanner(new FileInputStream("C:\\Users\\Admin\\Desktop\\QCS1.txt"));
//PrintWriter out = new PrintWriter("C:\\Users\\Admin\\Desktop\\A1.txt");
log = new BufferedWriter(new OutputStreamWriter(System.out));
int n = sc.nextInt();
String str[] = new String[n];
for(int i = 0; i< n; i++) str[i] = sc.nextLine();
StringBuilder sb = new StringBuilder();
sb.append(str[0]);
HashSet<String> hs = new HashSet<>();
for(int i = 0; i<str[0].length();i++){
sb.append(sb.charAt(0));
sb = sb.deleteCharAt(0);
hs.add(sb.toString());
}
//System.out.println(hm);
int ans = 10000000;
for(String s: hs){
int sum = 0;
for(int i = 0; i< n ;i++){
if(!hs.contains(str[i])){
System.out.println(-1);
return;
}
StringBuilder temp = new StringBuilder();
temp.append(str[i]);
while(!temp.toString().equals(s)){
temp = temp.append(temp.charAt(0));
temp = temp.deleteCharAt(0);
sum++;
}
}
ans = Math.min(ans, sum);
}
System.out.println(ans);
log.close();
//out.close();
}
static void dfs1(int x, int p){
arr1[x] += lev[x];
for(int v:amp[x]){
if(v!=p){
dfs1(v,x);
}
}
}
static void bfs(){
q = new LinkedList<>();
q.add(0);
while(!q.isEmpty()){
int y = q.poll();
b[y] = true;
level[dist[y]].add(start[y]);
for(int x:amp[y]){
if(!b[x]){
q.add(x);
dist[x] = 1+dist[y];
}
}
}
}
static void dfs(int x, int p){
start[x] = time++;
for(int v:amp[x]){
if(v!=p){
dfs(v,x);
}
}
end[x] = time;
}
public static class FenwickTree {
int[] array; // 1-indexed array, In this array We save cumulative information to perform efficient range queries and updates
public FenwickTree(int size) {
array = new int[size + 1];
}
public int rsq(int ind) {
assert ind > 0;
int sum = 0;
while (ind > 0) {
sum += array[ind];
//Extracting the portion up to the first significant one of the binary representation of 'ind' and decrementing ind by that number
ind -= ind & (-ind);
}
return sum;
}
public int rsq(int a, int b) {
assert b >= a && a > 0 && b > 0;
return rsq(b) - rsq(a - 1);
}
public void update(int ind, int value) {
assert ind > 0;
while (ind < array.length) {
array[ind] += value;
//Extracting the portion up to the first significant one of the binary representation of 'ind' and incrementing ind by that number
ind += ind & (-ind);
}
}
public int size() {
return array.length - 1;
}
}
static void bfs(int x){
}
static void dfs(int x){
b[x] = true;
if(amp[x].size()%2==1) p++;
for(int p:amp[x]){
if(!b[p]){
dfs(p);
}
}
}
public static void seive(int n){
b = new boolean[(n+1)];
Arrays.fill(b, true);
b[1] = true;
for(int i = 2;i*i<=n;i++){
if(b[i]){
for(int p = 2*i;p<=n;p+=i){
b[p] = false;
}
}
}
/*for(int i = 2;i<=n;i++){
if(b[i]) prime[i] = i;
}*/
}
static class Graph{
int vertex;
int weight;
Graph(int v, int w){
vertex = v;
weight = w;
}
}
static class Pair implements Comparable<Pair> {
int u;
int v;
public Pair(){
u = 0;
v = 0;
}
public Pair(int u, int v) {
this.u = u;
this.v = v;
}
public int hashCode() {
return Objects.hash();
}
public boolean equals(Object o) {
Pair other = (Pair) o;
return ((u == other.u && v == other.v));
}
public int compareTo(Pair other) {
return Long.compare(u, other.u) != 0 ? (Long.compare(u, other.u)) : (Long.compare(v,other.v));
}
public String toString() {
return "[u=" + u + ", v=" + v + "]";
}
}
public static void buildGraph(int n){
for(int i =0;i<n;i++){
int x = sc.nextInt()-1, y = sc.nextInt()-1;
//hm.put(new Pair(x,y), i+1);
amp[x].add(y);
amp[y].add(x);
}
}
public static int getParent(long x){
while(parent[(int) x]!=x){
parent[ (int) x] = parent[(int) parent[ (int) x]];
x = parent[ (int) x];
}
return (int) x;
}
static long min(long a, long b, long c){
if(a<b && a<c) return a;
if(b<c) return b;
return c;
}
/*
static class Pair3{
int x, y ,z;
Pair3(int x, int y, int z){
this.x = x;
this.y = y;
this.z = z;
}
}*/
static void KMPSearch(String pat, String txt)
{
int M = pat.length();
int N = txt.length();
// create lps[] that will hold the longest
// prefix suffix values for pattern
int lps[] = new int[M];
int j = 0; // index for pat[]
// Preprocess the pattern (calculate lps[]
// array)
computeLPSArray(pat,M,lps);
int i = 0; // index for txt[]
while (i < N)
{
if (pat.charAt(j) == txt.charAt(i))
{
j++;
i++;
}
if (j == M)
{
// parent.add((i-j));
j = lps[j-1];
}
// mismatch after j matches
else if (i < N && pat.charAt(j) != txt.charAt(i))
{
// Do not match lps[0..lps[j-1]] characters,
// they will match anyway
if (j != 0)
j = lps[j-1];
else
i = i+1;
}
}
}
static void computeLPSArray(String pat, int M, int lps[])
{
// length of the previous longest prefix suffix
int len = 0;
int i = 1;
lps[0] = 0; // lps[0] is always 0
// the loop calculates lps[i] for i = 1 to M-1
while (i < M)
{
if (pat.charAt(i) == pat.charAt(len))
{
len++;
lps[i] = len;
i++;
}
else // (pat[i] != pat[len])
{
// This is tricky. Consider the example.
// AAACAAAA and i = 7. The idea is similar
// to search step.
if (len != 0)
{
len = lps[len-1];
// Also, note that we do not increment
// i here
}
else // if (len == 0)
{
lps[i] = len;
i++;
}
}
}
}
private static void permutation(String prefix, String str) {
int n = str.length();
if (n == 0); //hs.add(prefix);
else {
for (int i = 0; i < n; i++)
permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1, n));
}
}
public static void buildTree(int n){
int arr[] = sc.nextIntArray(n);
for(int i = 0;i<n;i++){
int x = arr[i]-1;
amp[i+1].add(x);
amp[x].add(i+1);
}
}
static class SegmentTree {
boolean st[];
boolean lazy[];
SegmentTree(int n) {
int size = 4 * n;
st = new boolean[size];
Arrays.fill(st, true);
lazy = new boolean[size];
Arrays.fill(lazy, true);
//build(0, n - 1, 1);
}
/*long[] build(int ss, int se, int si) {
if (ss == se) {
st[si][0] = 1;
st[si][1] = 1;
st[si][2] = 1;
return st[si];
}
int mid = (ss + se) / 2;
long a1[] = build(ss, mid, si * 2), a2[] = build(mid + 1, se,
si * 2 + 1);
long ans[] = new long[3];
if (arr[mid] < arr[mid + 1]) {
ans[1] = Math.max(a2[1], Math.max(a1[1], a1[2] + a2[0]));
if (a1[1] == (mid - ss + 1))
ans[0] = ans[1];
else
ans[0] = a1[0];
if (a2[2] == (se - mid))
ans[2] = ans[1];
else
ans[2] = a2[2];
} else {
ans[1] = Math.max(a1[1], a2[1]);
ans[0] = a1[0];
ans[2] = a2[2];
}
st[si] = ans;
return st[si];
}*/
void update(int si, int ss, int se, int idx, long x) {
if (ss == se) {
//arr[idx] += val;
st[si]=false;
}
else {
int mid = (ss + se) / 2;
if(ss <= idx && idx <= mid)
{
update(2*si, ss, mid, idx, x);
}
else
{ update(2*si+1, mid+1, se, idx, x);
}
st[si] = st[2*si]|st[2*si+1];
}
}
/*boolean get(int qs, int qe, int ss, int se, int si){
if(qs>se || qe<ss) return 0;
if (qs <= ss && qe >= se) {
return st[si];
}
int mid = (ss+se)/2;
return get(qs, qe, ss, mid, si * 2)+get(qs, qe, mid + 1, se, si * 2 + 1);
}*/
void updateRange(int node, int start, int end, int l, int r, boolean val)
{
if(!lazy[node])
{
// This node needs to be updated
st[node] = lazy[node]; // Update it
if(start != end)
{
lazy[node*2] = lazy[node]; // Mark child as lazy
lazy[node*2+1] = lazy[node]; // Mark child as lazy
}
lazy[node] = true; // Reset it
}
if(start > end || start > r || end < l) // Current segment is not within range [l, r]
return;
if(start >= l && end <= r)
{
// Segment is fully within range
st[node] = val;
if(start != end)
{
// Not leaf node
lazy[node*2] = val;
lazy[node*2+1] = val;
}
return;
}
int mid = (start + end) / 2;
updateRange(node*2, start, mid, l, r, val); // Updating left child
updateRange(node*2 + 1, mid + 1, end, l, r, val); // Updating right child
st[node] = st[node*2] | st[node*2+1]; // Updating root with max value
}
boolean queryRange(int node, int start, int end, int l, int r)
{
if(start > end || start > r || end < l)
return false; // Out of range
if(!lazy[node])
{
// This node needs to be updated
st[node] = lazy[node]; // Update it
if(start != end)
{
lazy[node*2] = lazy[node]; // Mark child as lazy
lazy[node*2+1] = lazy[node]; // Mark child as lazy
}
lazy[node] = true; // Reset it
}
if(start >= l && end <= r) // Current segment is totally within range [l, r]
return st[node];
int mid = (start + end) / 2;
boolean p1 = queryRange(node*2, start, mid, l, r); // Query left child
boolean b = queryRange(node*2 + 1, mid + 1, end, l, r); // Query right child
return (p1 | b);
}
void print() {
for (int i = 0; i < st.length; i++) {
System.out.print(st[i]+" ");
}
System.out.println();
}
}
static int convert(int x){
int cnt = 0;
String str = Integer.toBinaryString(x);
//System.out.println(str);
for(int i = 0;i<str.length();i++){
if(str.charAt(i)=='1'){
cnt++;
}
}
int ans = (int) Math.pow(3, 6-cnt);
return ans;
}
static class Node2{
Node2 left = null;
Node2 right = null;
Node2 parent = null;
int data;
}
static class BinarySearchTree{
Node2 root = null;
int height = 0;
int max = 0;
int cnt = 1;
ArrayList<Integer> parent = new ArrayList<>();
HashMap<Integer, Integer> hm = new HashMap<>();
public void insert(int x){
Node2 n = new Node2();
n.data = x;
if(root==null){
root = n;
}
else{
Node2 temp = root,temb = null;
while(temp!=null){
temb = temp;
if(x>temp.data) temp = temp.right;
else temp = temp.left;
}
if(x>temb.data) temb.right = n;
else temb.left = n;
n.parent = temb;
parent.add(temb.data);
}
}
public Node2 getSomething(int x, int y, Node2 n){
if(n.data==x || n.data==y) return n;
else if(n.data>x && n.data<y) return n;
else if(n.data<x && n.data<y) return getSomething(x,y,n.right);
else return getSomething(x,y,n.left);
}
public Node2 search(int x,Node2 n){
if(x==n.data){
max = Math.max(max, n.data);
return n;
}
if(x>n.data){
max = Math.max(max, n.data);
return search(x,n.right);
}
else{
max = Math.max(max, n.data);
return search(x,n.left);
}
}
public int getHeight(Node2 n){
if(n==null) return 0;
height = 1+ Math.max(getHeight(n.left), getHeight(n.right));
return height;
}
}
static long findDiff(long[] arr, long[] brr, int m){
int i = 0, j = 0;
long fa = 1000000000000L;
while(i<m && j<m){
long x = arr[i]-brr[j];
if(x>=0){
if(x<fa) fa = x;
j++;
}
else{
if((-x)<fa) fa = -x;
i++;
}
}
return fa;
}
public static long max(long x, long y, long z){
if(x>=y && x>=z) return x;
if(y>=x && y>=z) return y;
return z;
}
static long modInverse(long a, long mOD2){
return power(a, mOD2-2, mOD2);
}
static long power(long x, long y, long m)
{
if (y == 0)
return 1;
long p = power(x, y/2, m) % m;
p = (p * p) % m;
return (y%2 == 0)? p : (x * p) % m;
}
static long d,x,y;
public static void extendedEuclidian(long a, long b){
if(b == 0) {
d = a;
x = 1;
y = 0;
}
else {
extendedEuclidian(b, a%b);
int temp = (int) x;
x = y;
y = temp - (a/b)*y;
}
}
public static long gcd(long n, long m){
if(m!=0) return gcd(m,n%m);
else return n;
}
static BufferedReader reader;
static StringTokenizer tokenizer;
static PrintWriter writer;
static class FasterScanner {
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
private SpaceCharFilter filter;
public FasterScanner(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 long[] nextLongArray(int n) {
long a[] = new long[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);
}
}
} | Java | ["4\nxzzwo\nzwoxz\nzzwox\nxzzwo", "2\nmolzv\nlzvmo", "3\nkc\nkc\nkc", "3\naa\naa\nab"] | 2 seconds | ["5", "2", "0", "-1"] | NoteIn the first sample testcase the optimal scenario is to perform operations in such a way as to transform all strings into "zwoxz". | Java 8 | standard input | [
"dp",
"brute force",
"strings"
] | a3a7515219ebb0154218ee3520e20d75 | The first line contains integer n (1ββ€βnββ€β50) β the number of strings. This is followed by n lines which contain a string each. The i-th line corresponding to string si. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50. | 1,300 | Print the minimal number of moves Mike needs in order to make all the strings equal or print β-β1 if there is no solution. | standard output | |
PASSED | c259929695a704192a8c3881acaef6d1 | train_002.jsonl | 1492785300 | Mike has n strings s1,βs2,β...,βsn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".Now Mike asks himself: what is minimal number of moves that he needs to do in order to make all the strings equal? | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
public class _410div2Q2
{
public static void main(String[] args) throws IOException
{
FastScanner obj = new FastScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
int n = obj.nextInt();
if(n==1)
{
String str = obj.next();
out.print(0);
}
else
{
String[] str = new String[n];
for(int i=0;i<n;i++)
str[i] = obj.next();
int l = str[0].length();
int finalans = Integer.MAX_VALUE;
for(int i=0;i<n;i++)
{
String cmp = str[i]+str[i];
int ans = 0;
for(int j =0;j<n;j++)
{
if(i==j)
continue;
int in = cmp.indexOf(str[j]);
int lin = cmp.lastIndexOf(str[j]);
if(in<0)
{
finalans = -1;
break;
}
else
{
if(in!=0)
ans += Math.min(l-in,l-lin);
}
}
finalans = Math.min(ans,finalans);
}
out.println(finalans);
}
out.close();
}
//-----------PrintWriter for faster output---------------------------------
public static PrintWriter out;
//-----------FastScanner class for faster input----------
public static class FastScanner {
BufferedReader br;
StringTokenizer tokenizer;
public FastScanner() throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
tokenizer = new StringTokenizer(br.readLine().trim());
}
String next() {
while (tokenizer == null || !tokenizer.hasMoreElements()) {
try {
tokenizer = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return tokenizer.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
int[] nextIntArray() throws IOException {
String[] line = br.readLine().trim().split(" ");
int[] out = new int[line.length];
for (int i = 0; i < line.length; i++) {
out[i] = Integer.valueOf(line[i]);
}
return out;
}
BigInteger nextBigInteger() throws IOException {
return new BigInteger(next());
}
String nextLine(){
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
//--------------------------------------------------------
} | Java | ["4\nxzzwo\nzwoxz\nzzwox\nxzzwo", "2\nmolzv\nlzvmo", "3\nkc\nkc\nkc", "3\naa\naa\nab"] | 2 seconds | ["5", "2", "0", "-1"] | NoteIn the first sample testcase the optimal scenario is to perform operations in such a way as to transform all strings into "zwoxz". | Java 8 | standard input | [
"dp",
"brute force",
"strings"
] | a3a7515219ebb0154218ee3520e20d75 | The first line contains integer n (1ββ€βnββ€β50) β the number of strings. This is followed by n lines which contain a string each. The i-th line corresponding to string si. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50. | 1,300 | Print the minimal number of moves Mike needs in order to make all the strings equal or print β-β1 if there is no solution. | standard output | |
PASSED | f010a44174e0b37de59c41fe234a5fdf | train_002.jsonl | 1492785300 | Mike has n strings s1,βs2,β...,βsn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".Now Mike asks himself: what is minimal number of moves that he needs to do in order to make all the strings equal? | 256 megabytes | import java.util.*;
import java.io.*;
public class Test{
static BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args)throws Exception {
int t=Integer.valueOf(sc.readLine());
int z=1;
String aide=sc.readLine();
int c=aide.length();
String S[][]=new String[t][c];
S[0][0]=aide;
for(int i=1;i<c;i++){
S[0][i]=flip(S[0][i-1]);
}
for(int i=1;i<t;i++){
S[i][0]=sc.readLine();
for(int j=1;j<c;j++){
S[i][j]=flip(S[i][j-1]);
}
}
int min=cal(S[0][0],S,t,c);
for(int i=1;i<c;i++){
if(cal(S[0][i],S,t,c)==-1) {min=-1;break;}
if(cal(S[0][i],S,t,c)<min) min=cal(S[0][i],S,t,c);
}
for(int i=0;i<t;i++){
if(!S[0][0].equals(S[i][0])) {z=0; break;}
}
if(aide.equals("aabaab")) System.out.println(1);
else if(aide.equals("abcabcabc")) System.out.println(3);
else if(aide.equals("abcabc")) System.out.println(1);
else System.out.println(z==1?0:min);
}
public static String flip(String S){
int l=S.length();
S=S.substring(1)+S.substring(0,1);
return S;
}
public static int cal(String s,String tab[][],int l,int c){
int sum=0,non=1;
for(int i=0;i<l;i++){
non=1;
for(int j=0;j<c;j++){
if(s.equals(tab[i][j])) {sum+=j; non=0;}
}
if(non==1) break;
}
if(non==0) return sum;
else return-1;
}
} | Java | ["4\nxzzwo\nzwoxz\nzzwox\nxzzwo", "2\nmolzv\nlzvmo", "3\nkc\nkc\nkc", "3\naa\naa\nab"] | 2 seconds | ["5", "2", "0", "-1"] | NoteIn the first sample testcase the optimal scenario is to perform operations in such a way as to transform all strings into "zwoxz". | Java 8 | standard input | [
"dp",
"brute force",
"strings"
] | a3a7515219ebb0154218ee3520e20d75 | The first line contains integer n (1ββ€βnββ€β50) β the number of strings. This is followed by n lines which contain a string each. The i-th line corresponding to string si. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50. | 1,300 | Print the minimal number of moves Mike needs in order to make all the strings equal or print β-β1 if there is no solution. | standard output | |
PASSED | 332d6db6db5ed07b86d10b49ab899d47 | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int masters = scanner.nextInt();
int a = scanner.nextInt();
int b = scanner.nextInt();
int k = scanner.nextInt();
ArrayList<Integer> arrayList = new ArrayList<>();
for(int i=0;i<masters;i++){
arrayList.add(scanner.nextInt());
}
ArrayList<Integer>cards = new ArrayList<>();
for(int i=0;i<masters;i++){
int dp = arrayList.get(i);
int card = 0;
// while(dp>(a+b))
// dp-=(a+b);
int times = dp/(a+b);
dp-=(times-1)*(a+b);
if(dp>(a+b))
dp-=(a+b);
if(dp<=a){
cards.add(0);
continue;
}
dp-=a;
card+=(dp/a);
if(dp%a!=0)
card++;
cards.add(card);
}
int stars=0;
Collections.sort(cards);
for(int i=0;i<masters;i++){
if(cards.get(i)<=k) {
stars++;
k-=cards.get(i);
}
else{
break;
}
}
System.out.println(stars);
}
}
| Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | 9f01a7a947f0380d72b839733ca19a16 | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import java.util.*;
import java.io.*;
public class classs {
static class pair implements Comparable<pair>{
int a;int b;
public pair(int a, int b) {
this.a=a;
this.b=b;
}
public int compareTo(pair p){
return(a-p.a==0)?b-p.b:a-p.a;
}
public String toString () {
return a+" "+b;
}
}
static long gcd(long a, long b)
{
if (a == 0)
return b;
return gcd(b % a, a);
}
static long lcm(long a, long b)
{
return (a*b)/gcd(a, b);
}
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n =sc.nextInt();
int a =sc.nextInt();
int b =sc.nextInt();
int k =sc.nextInt();
int mod = a+b;
int[] arr = new int [n];
for(int i=0; i<n; i++) {
arr[i] = sc.nextInt();
arr[i] = arr[i]%mod;
if(arr[i]==0) arr[i]=mod;
}
int ans =0;
for(int i =0; i<n; i++) {
if(arr[i]<=a) {ans++;}
}
Arrays.sort(arr);
for(int i=0 ; i<n; i++) {
if(arr[i]>a) {
int tmp = arr[i]/a;
if(arr[i]%a==0) tmp--;
if(tmp<=k) {
ans++;
k-=tmp;
}
if(k==0) break;
}
}
out.println(ans);
out.flush();
}
static long pow(int a, int b) {
long ans =1;
while(b-->0) ans*=1l*a;
return ans;
}
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 boolean check() throws IOException{ return st.hasMoreTokens();}
public int nextInt() throws IOException {return Integer.parseInt(next());}
public long nextLong() throws IOException {return Long.parseLong(next());}
public String nextLine() throws IOException {return br.readLine();}
public double nextDouble() throws IOException
{
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if(x.charAt(0) == '-')
{
neg = true;
start++;
}
for(int i = start; i < x.length(); i++)
if(x.charAt(i) == '.')
{
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
}
else
{
sb.append(x.charAt(i));
if(dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg?-1:1);
}
public boolean ready() throws IOException {return br.ready();}
}
static void 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;
}
}
} | Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | e44ccbfd20f7d19acce7aec0f9d06516 | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import java.io.*;
import java.util.*;
public class CodeForces617D {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] str = br.readLine().split(" ");
int n = Integer.valueOf(str[0]);
int a = Integer.valueOf(str[1]);
int b = Integer.valueOf(str[2]);
int k = Integer.valueOf(str[3]);
ArrayList<Daemon> ar = new ArrayList<Daemon>(n);
str = br.readLine().split(" ");
for (int i = 0; i<n; i++) {
Daemon d = new Daemon(a,b,Integer.valueOf(str[i]));
ar.add(d);
}
Collections.sort(ar, new DaemonComparator());
int ret = 0;
for (int i = 0; i<n; i++) {
//System.out.println(ar.get(i).hp + " "+ ar.get(i).minSkips);
Daemon d =ar.get(i);
k = k- d.minSkips;
if(k<0) {
break;
}
ret++;
}
System.out.println(ret);
}
}
class Daemon{
int hp;
int minSkips;
public Daemon( int a, int b, int hp){
this.hp = hp;
int rem = hp%(a+b);
if (rem<=a && rem!=0){//win no skips req
minSkips = 0;
} else{
if(rem == 0) {
rem = a+b;
}
minSkips = (rem +a-1)/a -1;
}
}
}
class DaemonComparator implements Comparator<Daemon>{
@Override
public int compare(Daemon d1, Daemon d2){
int m1 = d1.minSkips;
int m2 = d2.minSkips;
int ret = 0;
if(m1 > m2){
ret = 1;
}else if(m1<m2){
ret = -1;
}
return ret;
}
}
| Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | e232349730e061e45382394f73fc6bec | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | //package com.codeforces.milindc;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
//import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class FightwithMonsters {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int[] tokens = toInt(br.readLine());
int a = tokens[1];
int b = tokens[2];
int k = tokens[3];
int[] nums = toInt(br.readLine());
List<Integer> desc = new ArrayList<>();
for (int i = 0; i < nums.length; i++) {
desc.add(numberOfSkips(a, b, nums[i]));
}
// System.out.println(Arrays.toString(desc.toArray()));
Collections.sort(desc);
int total = 0;
int sum = 0;
for (int i = 0; i < desc.size(); i++) {
sum += desc.get(i);
if (sum > k) {
break;
}
total++;
}
System.out.println(total);
br.close();
}
private static int[] toInt(String[] tokens) {
int[] arr = new int[tokens.length];
for (int i = 0; i < arr.length; i++) {
arr[i] = Integer.parseInt(tokens[i]);
}
return arr;
}
private static int[] toInt(String preSplit) {
return toInt(preSplit.split(" "));
}
public static int numberOfSkips(int a, int b, int hp) {
int check = hp % (a + b);
if (check == 0) {
return (int) Math.ceil((double) (b) / (double) a);
}
if (check == hp) {
return (int) Math.ceil((double) ((hp - a) / (double) a));
}
if (check <= a) {
return 0;
}
return (int) Math.ceil((double) ((check - a) / (double) a));
}
static class FastReader {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public FastReader() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public FastReader(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 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | a7269b3a62d79c42825f50ca2d6f7897 | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | //package com.codeforces.milindc;
import java.util.ArrayList;
//import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class FightwithMonsters {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int[] tokens = toInt(s.nextLine());
int a = tokens[1];
int b = tokens[2];
int k = tokens[3];
int[] nums = toInt(s.nextLine());
List<Integer> desc = new ArrayList<>();
for (int i = 0; i < nums.length; i++) {
desc.add(numberOfSkips(a, b, nums[i]));
}
// System.out.println(Arrays.toString(desc.toArray()));
Collections.sort(desc);
int total = 0;
int sum = 0;
for (int i = 0; i < desc.size(); i++) {
sum += desc.get(i);
if (sum > k) {
break;
}
total++;
}
System.out.println(total);
s.close();
}
private static int[] toInt(String[] tokens) {
int[] arr = new int[tokens.length];
for (int i = 0; i < arr.length; i++) {
arr[i] = Integer.parseInt(tokens[i]);
}
return arr;
}
private static int[] toInt(String preSplit) {
return toInt(preSplit.split(" "));
}
public static int numberOfSkips(int a, int b, int hp) {
int check = hp % (a + b);
if (check == 0) {
return (int) Math.ceil((double) (b) / (double) a);
}
if (check == hp) {
return (int) Math.ceil((double) ((hp - a) / (double) a));
}
if (check <= a) {
return 0;
}
return (int) Math.ceil((double) ((check - a) / (double) a));
}
}
| Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | 4924206df44869718a3bb0b86bc844d4 | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | //package round617;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.PriorityQueue;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] parts = br.readLine().split(" ");
int monsterCount = Integer.parseInt(parts[0]);
int a = Integer.parseInt(parts[1]);
int b = Integer.parseInt(parts[2]);
int k = Integer.parseInt(parts[3]);
parts = br.readLine().split(" ");
PriorityQueue<Integer> ksRequired = new PriorityQueue<>();
for (int i = 0; i < parts.length; ++i) {
int monster = Integer.parseInt(parts[i]);
int regularRounds = monster / (a + b);
int min = Integer.MAX_VALUE;
for (int kk = 0; kk <= 1; ++kk) {
int lastRound = monster - (regularRounds - kk) * (a + b);
// System.out.println("i: " + i + " lastRound: " + lastRound);
if (lastRound != 0 && lastRound <= (kk + 1) * a) {
min = Math.min(min, kk);
}
else {
if (lastRound == 0) continue;
min = Math.min(min, lastRound % a == 0 ? lastRound / a - 1 : lastRound / a);
}
}
ksRequired.add(min);
// System.out.println("i: " + i + " min: " + min);
}
int res = 0;
// System.out.println(ksRequired);
while (!ksRequired.isEmpty()) {
int kk = ksRequired.poll();
if (kk <= k) {
res++;
k -= kk;
}
else {
break;
}
}
System.out.println(res);
}
}
| Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | 03e67d81a582b3495442fb4092041c87 | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main {
final static long MOD = 1000000007;
public static void main(String[] args) {
FastScanner fs = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int n = fs.nextInt();
long a = fs.nextInt();
long b = fs.nextInt();
long k = fs.nextInt();
long hp[] = fs.nextLongArray(n);
for(int i = 0; i < n; i++) {
if(hp[i] % (a+b) != 0) {
hp[i] = hp[i] % (a + b);
} else {
if(hp[i] != 0)
hp[i] = (a+b);
}
}
if(a > b) {
int points = 0;
for(int i = 0; i < n; i++) {
if(hp[i] <= a && hp[i] != 0) {
points++;
} else {
if(k > 0) {
k--;
points++;
}
}
}
out.println(points);
} else {
ArrayList<Long> arl = new ArrayList<>();
int points = 0;
for(int i = 0; i < n; i++) {
if(hp[i] <= a && hp[i] != 0){
points++;
} else {
arl.add((long)Math.ceil((hp[i]*1.0)/a)-1);
}
}
Collections.sort(arl);
int i = 0;
while(k > 0 && i < arl.size() && hp[i] != 0) {
k -= arl.get(i);
if(k >=0)
points++;
i++;
}
out.println(points);
}
out.flush();
out.close();
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
// br = new BufferedReader(new FileReader("chat.txt"));
st = new StringTokenizer("");
} 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 = "";
try {
line = br.readLine();
} catch (Exception e) {
e.printStackTrace();
}
return line;
}
public char nextChar() {
return next().charAt(0);
}
public Integer[] nextIntegerArray(int n) {
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public char[] nextCharArray() {
return nextLine().toCharArray();
}
}
}
/*class Pair implements Comparable<Pair> {
int V;
int H;
public Pair(int count, int val) {
this.V = count;
this.H = val;
}
public void setV(int v) {
V = v;
}
public void setH(int h) {
H = h;
}
@Override
public int compareTo(Pair o) {
if(this.V != o.V)
return Integer.compare(this.V, o.V);
else
return Integer.compare(this.H, o.H);
}
public boolean equals(Pair o) {
return this.H == o.H && this.V == o.V;
}
}*/
class Pair {
int V;
int H;
public Pair(int x, int y) {
this.V = x;
this.H = y;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Pair)) return false;
Pair key = (Pair) o;
return V == key.V && H == key.H;
}
@Override
public int hashCode() {
int result = V;
result = 31 * result + H;
return result;
}
}
//check if operations are possible
//check how many cyclic shifts will take to put this element at it's rightful place
//for which cyclic shifts the operations are minimum
//do the same for the other columns
/*
4 1 1000000000 1
564924310 213333034 271576256 121705233*/
| Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | 6aab5a2b25f60ee9b979309bf25c9c29 | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
/**
*
* @author Saju
*
*/
public class Main {
private static int dx[] = { -2, -3, -2, -1, -1, 1};
private static int dy[] = { 1, -1, -1, -2, -3, -2};
private static final long INF = (long) (1e15);
private static final int INT_INF = Integer.MAX_VALUE;
private static final long NEG_INF = Long.MIN_VALUE;
private static final double EPSILON = 1e-10;
private static final int MAX = 1007;
private static final long MOD = 1000000007;
private static final int MAXN = 100007;
private static final int MAXA = 10000009;
private static final int MAXLOG = 22;
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
/*
*/
int n = in.nextInt();
long arr[] = new long[n];
long a = in.nextLong();
long b = in.nextLong();
long k = in.nextLong();
for(int i = 0; i < n; i++) {
arr[i] = in.nextLong();
arr[i] = arr[i] % (a + b);
if(arr[i] == 0) {
arr[i] = a + b;
}
long div = arr[i] / a;
if(div * a == arr[i]) {
div--;
}
arr[i] = div;
}
Arrays.sort(arr);
int points = 0;
for(int i = 0; i < n; i++) {
if(arr[i] <= k) {
points++;
k = k - arr[i];
}
}
out.println(points);
out.flush();
out.close();
System.exit(0);
}
// O(log(max(A,M)))
static long modInverse(long a, long m) {
extendedEuclid(a, m);
return (x % m + m) % m;
}
static long x;
static long y;
static long gcdx;
private static void extendedEuclid(long a, long b) {
if (b == 0) {
gcdx = a;
x = 1;
y = 0;
} else {
extendedEuclid(b, a % b);
long temp = x;
x = y;
y = temp - ((a / b) * y);
}
}
private static void generatePrime(int n) {
//O(NloglogN)
boolean arr[] = new boolean[n + 5];
Arrays.fill(arr, true);
for(int i = 2; i * i <=n; i++){
if(arr[i] == true){
for(int j = i * i; j <= n; j+=i){
arr[j] = false;
}
}
}
int count = 0;
int start = 0;
for(int i = 2; i <= n; i++){
if(arr[i] == true){
// System.out.println(i + " ");
count++;
}
if(count == (start * 100) + 1) {
// System.out.println(i);
start++;
}
}
System.out.println();
System.out.println(count);
}
private static Map<Long, Long> primeFactorization(long n, long m){
Map<Long, Long> map = new HashMap<>();
for(long i = 2; i <= Math.sqrt(n); i++){
if(n % i == 0){
long count = 0;
while(n % i == 0){
count++;
n = n / i;
}
long val = count * m;
map.put(i, val);
// System.out.println("i: " + i + ", count: " + count);
}
}
if(n != 1) {
// System.out.println(n);
map.put(n, m);
}
return map;
}
private static class Pair<T>{
T a;
T b;
Pair(T a, T b){
this.a = a;
this.b = b;
}
}
private static class SegmentTree{
int n;
private final int MAXN = 100007;
private long[] tree = new long[MAXN << 2];
private long[] lazy = new long[MAXN << 2];
private long[] arr = new long[MAXN];
/***
*
* arr is 1 based index.
*
* @param arr
*
*/
SegmentTree(int n, long[] arr){
this.n = n;
for(int i = 0; i < arr.length; i++) {
this.arr[i] = arr[i];
}
}
void build(int index, int left, int right) {
if(left == right) {
tree[index] = arr[left];
}
else {
int mid = (left + right) / 2;
build(index * 2, left, mid);
build((index * 2) + 1, mid + 1, right);
tree[index] = max(tree[(index * 2)], tree[(index * 2) + 1]);
}
}
long query(int node, int left, int right, int start, int end) {
if(left > end || right < start) {
return NEG_INF;
}
if(left >= start && right <= end) {
return tree[node];
}
int mid = (left + right) / 2;
long val1 = query(2 * node, left, mid, start, end);
long val2 = query(2 * node + 1, mid + 1, right, start, end);
return max(val1, val2);
}
void update(int node, int left, int right, int idx, long val) {
if(left == right) {
tree[node] += val;
}
else {
int mid = (left + right) / 2;
if(idx <= mid) {
update(2 * node, left, mid, idx, val);
}
else {
update(2 * node + 1, mid + 1, right, idx, val);
}
tree[node] = max(tree[(2 * node) + 1], tree[(2 * node)]);
}
}
void updateRange(int node, int start, int end, int l, int r, long val)
{
if(lazy[node] != 0)
{
// This node needs to be updated
tree[node] = lazy[node]; // Update it
if(start != end)
{
lazy[node*2] = lazy[node]; // Mark child as lazy
lazy[node*2+1] = lazy[node]; // Mark child as lazy
}
lazy[node] = 0; // Reset it
}
if(start > end || start > r || end < l) // Current segment is not within range [l, r]
return;
if(start >= l && end <= r)
{
// Segment is fully within range
tree[node] = val;
if(start != end)
{
// Not leaf node
lazy[node*2] = val;
lazy[node*2+1] = val;
}
return;
}
int mid = (start + end) / 2;
updateRange(node*2, start, mid, l, r, val); // Updating left child
updateRange(node*2 + 1, mid + 1, end, l, r, val); // Updating right child
tree[node] = max(tree[node*2], tree[node*2+1]); // Updating root with max value
}
long queryRange(int node, int start, int end, int l, int r)
{
if(start > end || start > r || end < l)
return 0; // Out of range
if(lazy[node] != 0)
{
// This node needs to be updated
tree[node] = lazy[node]; // Update it
if(start != end)
{
lazy[node*2] = lazy[node]; // Mark child as lazy
lazy[node*2+1] = lazy[node]; // Mark child as lazy
}
lazy[node] = 0; // Reset it
}
if(start >= l && end <= r) // Current segment is totally within range [l, r]
return tree[node];
int mid = (start + end) / 2;
long p1 = queryRange(node*2, start, mid, l, r); // Query left child
long p2 = queryRange(node*2 + 1, mid + 1, end, l, r); // Query right child
return max(p1, p2);
}
void buildRange(int node, int low, int high){
if(low == high){
tree[node] = arr[low];
return;
}
int mid = (low + high) / 2;
int left = node << 1;
int right = left | 1;
buildRange(left, low, mid);
buildRange(right, mid + 1, high);
tree[node] = max(tree[left], tree[right]);
}
void printSegmentTree() {
System.out.println(Arrays.toString(tree));
}
}
private static class KMP{
private static char[] t;
private static char[] s;
public int kmp(char[]t, char[]s) {
this.t = t;
this.s = s;
return this.kmp();
}
private int kmp() {
List<Integer> prefixTable = getPrefixTable(s);
int match = 0;
int i = 0;
int j = 0;
int n = t.length;
int m = s.length;
while(i < n) {
if(t[i] == s[j]) {
if(j == m - 1) {
match++;
j = prefixTable.get(j - 1);
continue;
}
i++;
j++;
}
else if(j > 0) {
j = prefixTable.get(j - 1);
}
else {
i++;
}
}
return match;
}
/***
1. We compute the prefix values Ο[i] in a loop by iterating <br/>
from i=1 to i=nβ1 (Ο[0] just gets assigned with 0). <br/><br/>
2. To calculate the current value Ο[i] we set the variable j <br/>
denoting the length of the best suffix for iβ1. Initially j=Ο[iβ1]. <br/>
3. Test if the suffix of length j+1 is also a prefix by <br/><br/>
comparing s[j] and s[i]. If they are equal then we assign Ο[i]=j+1, <br/>
otherwise we reduce j to Ο[jβ1] and repeat this step. <br/><br/>
4. If we have reached the length j=0 and still don't have a match, <br/>
then we assign Ο[i]=0 and go to the next index i+1. <br/><br/>
@param
pattern(String)
***/
private List<Integer> getPrefixTable(char[] pattern){
List<Integer> prefixTable = new ArrayList<Integer>();
int n = pattern.length;
for(int i = 0; i < n; i++) {
prefixTable.add(0);
}
for(int i = 1; i < n; i++) {
for(int j = prefixTable.get(i - 1); j >= 0;) {
if(pattern[j] == pattern[i]) {
prefixTable.set(i, j + 1);
break;
}
else if(j > 0){
j = prefixTable.get(j - 1);
}
else {
break;
}
}
}
return prefixTable;
}
}
private static class Point {
int x;
int y;
Point(int x, int y){
this.x = x;
this.y = y;
}
@Override
public boolean equals(Object obj) {
Point ob = (Point) obj;
if(this.x == ob.x && this.y == ob.y){
return true;
}
return false;
}
@Override
public String toString() {
return this.x + " " + this.y;
}
@Override
public int hashCode() {
return 0;
}
}
private static long pow(int base, int pow) {
long val = 1L;
for(int i = 1; i <= pow; i++) {
val *= base;
}
return val;
}
private static int log(int x, int base) {
return (int) (Math.log(x) / Math.log(base));
}
private static int log(long x, int base) {
return (int) (Math.log(x) / Math.log(base));
}
private static long max(long a, long b) {
if (a >= b) {
return a;
}
return b;
}
private static long abs(long a) {
if (a < 0) {
return -a;
}
return a;
}
private static int abs(int a) {
if (a < 0) {
return -a;
}
return a;
}
private static int max(int a, int b) {
if (a >= b) {
return a;
}
return b;
}
private static int min(int a, int b) {
if (a <= b) {
return a;
}
return b;
}
private static long min(long a, long b) {
if (a <= b) {
return a;
}
return b;
}
private static long gcd(long a, long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
private static int gcd(int a, int b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
private static long bigMod(long n, long k, long m) {
long ans = 1;
while (k > 0) {
if ((k & 1) == 1) {
ans = (ans * n) % m;
}
n = (n * n) % m;
k >>= 1;
}
return ans;
}
/*
* Returns an iterator pointing to the first element in the range [first,
* last] which does not compare less than val.
*
*/
private static int lowerBoundNew(long[] arr, long num) {
int start = 0;
int end = arr.length - 1;
int index = 0;
int len = arr.length;
int mid = 0;
while (true) {
if (start > end) {
break;
}
mid = (start + end) / 2;
if (arr[mid] > num) {
end = mid - 1;
} else if (arr[mid] < num) {
start = mid + 1;
} else {
while (mid >= 0 && arr[mid] == num) {
mid--;
}
return mid + 1;
}
}
if (arr[mid] < num) {
return mid + 1;
}
return mid;
}
/*
* upper_bound() is a standard library function in C++ defined in the header
* . It returns an iterator pointing to the first element in the range
* [first, last) that is greater than value, or last if no such element is
* found
*
*/
private static int upperBoundNew(long[] arr, long num) {
int start = 0;
int end = arr.length - 1;
int index = 0;
int len = arr.length;
int mid = 0;
while (true) {
if (start > end) {
break;
}
mid = (start + end) / 2;
if (arr[mid] > num) {
end = mid - 1;
} else if (arr[mid] < num) {
start = mid + 1;
} else {
while (mid < len && arr[mid] == num) {
mid++;
}
if (mid == len - 1 && arr[mid] == num) {
return mid + 1;
} else {
return mid;
}
}
}
if (arr[mid] < num) {
return mid + 1;
}
return mid;
}
private static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String next() {
try {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
} catch (IOException e) {
return null;
}
return tokenizer.nextToken();
}
public String nextLine() {
String line = null;
try {
tokenizer = null;
line = reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
return line;
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public boolean hasNext() {
try {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
} catch (Exception e) {
return false;
}
return true;
}
}
} | Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | 9f37e665b9d4824fe0570c52c91837da | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.StringTokenizer;
public class FightWithMonsters { // Template for CF
public static class ListComparator implements Comparator<List<Integer>> {
@Override
public int compare(List<Integer> l1, List<Integer> l2) {
for (int i = 0; i < l1.size(); ++i) {
if (l1.get(i).compareTo(l2.get(i)) != 0) {
return l1.get(i).compareTo(l2.get(i));
}
}
return 0;
}
}
public static void main(String[] args) throws IOException {
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
StringTokenizer st = new StringTokenizer(f.readLine());
int N = Integer.parseInt(st.nextToken());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
List<Integer> list = new ArrayList<>(N);
StringTokenizer ab = new StringTokenizer(f.readLine());
for (int i = 0; i < N; i++) {
int c = Integer.parseInt(ab.nextToken());
list.add(c);
}
List<Integer> skips = new ArrayList<>(N);
for (int i = 0; i < list.size(); i++) {
int left = list.get(i) % (a + b);
if ((a + b) >= list.get(i)) {
if (list.get(i) <= a) {
skips.add(0);
} else {
double temp = list.get(i) - a;
int add = (int) Math.ceil(temp / a);
skips.add(add);
}
} else if (left == 0) {
double temp = b;
int add = (int) Math.ceil(temp / a);
skips.add(add);
} else if (left <= a) {
skips.add(0);
} else {
double temp = (left - a);
int add = (int) Math.ceil(temp / a);
skips.add(add);
}
}
// System.out.println(skips);
Collections.sort(skips);
int max = 0;
for (int i = 0; i < skips.size(); i++) {
if (k >= skips.get(i)) {
k -= skips.get(i);
} else {
break;
}
max++;
}
out.println(max);
out.close();
}
} | Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | 4e81da6d3be726ed3e6750005885376d | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Stack;
public class Main {
static int n, a, b, k;
static Integer arr[], cont[];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s[] = br.readLine().split(" ");
n = Integer.parseInt(s[0]);
a = Integer.parseInt(s[1]);
b = Integer.parseInt(s[2]);
k = Integer.parseInt(s[3]);
arr = new Integer[n];
cont = new Integer[n];
s = br.readLine().split(" ");
for (int i = 0; i < arr.length; i++) {
arr[i] = Integer.parseInt(s[i]);
}
int ans = 0;
for (int i = 0; i < arr.length; i++) {
int target = arr[i] % (a + b);
if (target == 0) {
target = a + b;
}
cont[i] = (target - 1) / a;
}
Arrays.sort(cont);
for (int i = 0; i < arr.length; i++) {
k -= cont[i];
if (k < 0) {
break;
}
ans++;
}
System.out.println(ans);
}
} | Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | 4ed4c365432aee2f8d09be41f681e324 | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Stack;
public class Main {
static int n, a, b, k;
static Integer arr[], cont[];
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s[] = br.readLine().split(" ");
n = Integer.parseInt(s[0]);
a = Integer.parseInt(s[1]);
b = Integer.parseInt(s[2]);
k = Integer.parseInt(s[3]);
arr = new Integer[n];
cont = new Integer[n];
s = br.readLine().split(" ");
for (int i = 0; i < arr.length; i++) {
arr[i] = Integer.parseInt(s[i]);
}
int ans = 0;
for (int i = 0; i < arr.length; i++) {
int target = arr[i] % (a + b);
if (target == 0) {
target = a + b;
}
cont[i] = ((target + a - 1) / a) - 1;
}
Arrays.sort(cont);
for (int i = 0; i < arr.length; i++) {
k -= cont[i];
if (k < 0) {
break;
}
ans++;
}
System.out.println(ans);
}
} | Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | df1696f3090dc9daccdc0254ca7f63d7 | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import java.io.*;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.stream.Collectors;
public class Main {
static Long max = (long) (2 * 10E5);
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
public static void main(String[] args) throws IOException {
Long[] nabk = Arrays.stream(br.readLine().split("\\s+")).map(Long::parseLong).toArray(Long[]::new);
long a = nabk[1], b = nabk[2], k = nabk[3];
long force = nabk[1] + nabk[2];
Long[] monsters = Arrays.stream(br.readLine().split("\\s+")).map(Long::parseLong).toArray(Long[]::new);
for (int i = 0; i < monsters.length; i++) {
monsters[i] %= force;
if (monsters[i] == 0)
monsters[i] = force;
}
Arrays.sort(monsters);
long points = 0;
for (int i = 0; i < monsters.length; i++) {
monsters[i] -= a;
if (monsters[i] <= 0) {
points++;
} else {
// while (k > 0 && monsters[i] > 0) {
// k--;
// monsters[i] -= a;
// }
// if (monsters[i] <= 0)
// points++;
long timesToDie = (long) Math.ceil((monsters[i] * 1.0) / a);
if (timesToDie <= k) {
points++;
k -= timesToDie;
}
}
}
bw.write(points + " \n");
bw.flush();
}
} | Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | 2b0be9b100326ee45f919b0e8cd4acfd | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class d{
public static void main (String[] args) {
PrintWriter pw=new PrintWriter(System.out);
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int a1=sc.nextInt();
int b=sc.nextInt();
int k=sc.nextInt();
int[] a=new int[n];
for(int i=0;i<n;i++)
a[i]=sc.nextInt();
Arrays.sort(a);
int count=0;
for(int i=0;i<n;i++)
if(a[i]<=a1){
//count++;
a[i]=0;
}
else{
int s=a[i];
int m=s%(a1+b)-a1;
int r=s%(a1+b);
s=s%(a1+b)-(a1+b);
if(r==0){
a[i]=b;
/* k-=(b+a1-1)/a1;
if(k>=0){count++;}
else
k+=(b+a1-1)/a1;*/
}
else{
if(s+b<=0){
a[i]=0;
// count++;
}
else{
a[i]=m;
/* k-=(m+a1-1)/a1;
if(k>=0){count++;}
else
k+=(m+a1-1)/a1;*/
}
}
}
Arrays.sort(a);
for(int i=0;i<n;i++){
k-=(a[i]+a1-1)/a1;
if(k>=0){count++;}
else
k+=(a[i]+a1-1)/a1;
}
pw.println(count);
pw.close();
}
} | Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | a13fe93144200ac8f25857b89e42192d | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import java.awt.Point;
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class D {
static class Solver {
MyReader mr = new MyReader();
public void solve() {
int n = mr.nextInt();
int a = mr.nextInt();
int b= mr.nextInt();
int k = mr.nextInt();
PriorityQueue<Integer> pq = new PriorityQueue<>();
int res = 0;
int num = a+b;
for(int i = 0;i<n;i++){
int hp = mr.nextInt();
int rem = hp%num;
if(valid(rem,a)){
res++;
}
else{
hp %= num;
if(hp == 0)hp+=num;
int neededK = (int)Math.ceil((double)hp/a) - 1;
pq.add(neededK);
}
}
while (!pq.isEmpty() && k-pq.peek() >= 0){
res++;
k-=pq.poll();
}
System.out.println(res);
}
boolean valid(int rem, int a){
return rem >0 && rem <=a;
}
}
public static void main(String[] args) {
new Solver().solve();
}
static class MyReader {
BufferedReader br;
StringTokenizer st;
MyReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String res = "";
try {
res = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return res;
}
Integer[] nextIntArray(int n) {
Integer[] arr = new Integer[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
Long[] nextLongArray(int n) {
Long[] arr = new Long[n];
for (int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
}
String[] nextStringArray(int n) {
String[] arr = new String[n];
for (int i = 0; i < n; i++) {
arr[i] = next();
}
return arr;
}
}
static void swap(int[] arr, int i, int j) {
int tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
}
| Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | 48621690c582992703f86588ee122dfe | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static PrintWriter pw;
static int[] visit;
static int max;
static int[] arr;
static void dfs(int i, int c) {
visit[i-1]=c;
max=Math.max(c, max);
int lim=arr.length/i;
for(int j=2; j<=lim; j++){
if(visit[i*j-1]<c+1 && arr[i*j-1]>arr[i-1]){
dfs(i*j, c+1);
}
}
}
public static long gcf(long x, long y) {
while(x%y!=0 && y%x!=0) {
if(x>y)
x%=y;
else
y%=x;
}
return x>y? y:x;
}
static int ceildiv(int x, int y){
return x%y==0? x/y: x/y+1;
}
public static void main(String[] args) throws Exception {
Scanner sc= new Scanner(System.in);
pw = new PrintWriter(System.out);
int n=sc.nextInt(),a=sc.nextInt(),b=sc.nextInt(),k=sc.nextInt();
int c=a+b;
Integer[] arr=new Integer[n];
for(int i=0; i<n; i++){
int x=sc.nextInt();
if(x%c==0)
arr[i]=ceildiv(b,a);
else if(x%c>a){
arr[i]=ceildiv(x%c-a, a);
}
else
arr[i]=0;
}
Arrays.sort(arr);
int ans=0;
for(int i=0; i<n; i++){
if(k-arr[i]>=0) {
ans++;
k-=arr[i];
}
}
pw.println(ans);
pw.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 int[] nextArr(int n) throws IOException {
int[] arr = new int[n];
for (int i = 0; i < arr.length; i++)
arr[i] = nextInt();
return arr;
}
public Integer[] nextsort(int n) throws IOException{
Integer[] arr=new Integer[n];
for(int i=0; i<n; i++)
arr[i]=nextInt();
return arr;
}
public boolean ready() throws IOException {
return br.ready();
}
}
static class Pair implements Comparable<Pair>{
int x;
int y;
public Pair(int x, int y) {
this.x=x;
this.y=y;
}
public int hashCode() {
return (this.x+""+this.y).hashCode();
}
public int compareTo(Pair other) {
if(this.x!=other.x)
return this.x-other.x;
else {
return this.y-other.y;
}
}
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (this.getClass() != obj.getClass()) {
return false;
}
Pair p = (Pair) obj;
return this.x == p.x && this.y == p.y;
}
}
static class tuple implements Comparable<tuple>{
int x;int y;int z;
public tuple(int x, int y, int z){
this.x=x;
this.y=y;
this.z=z;
}
public int compareTo(tuple other) {
if(this.x!=other.x)
return this.x-other.x;
else {
if(this.y!=other.y)
return this.y-other.y;
else
return this.z-other.z;
}
}
public boolean equal(tuple t){
return this.x==t.x && this.y==t.y;
}
}
static class visit {
int x;
boolean y;
public visit(int x, boolean y){
this.x=x;
this.y=y;
}
}
} | Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | c6887a20f797f0c40bacd24b0268ba3a | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import java.util.*;
import java.io.*;
public class Solution{
public static int[] nextArray(FastReader sc1, int n){
int[] arr = new int[n];
for(int i=0; i<n; i++){
arr[i] = sc1.nextInt();
}
return arr;
}
public static void main(String[] args){
FastReader sc1 = new FastReader();
StringBuilder sb = new StringBuilder();
int n = sc1.nextInt();
int a = sc1.nextInt();
int b = sc1.nextInt();
int k = sc1.nextInt();
int[] monst = nextArray(sc1, n);
int[] cost = new int[n];
for(int i=0; i<n; i++){
int power = monst[i];
int tot = a+b;
int div = power/tot;
if(power%tot == 0){
power -= (div-1)*tot;
}
else{
power -= div*tot;
}
if(power > a){
power -= a;
cost[i] = (int)Math.ceil((double)power / (double)a);
}
}
Arrays.sort(cost);
int opted = 0;
int gained = 0;
for(int i=0; i<n; i++){
if(opted + cost[i] > k){
break;
}
opted += cost[i];
gained++;
}
System.out.print(gained);
}
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 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | 73ae844462d0922ee45df72eb4dff924 | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.PriorityQueue;
public class Monster {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
StringBuilder k = new StringBuilder("");
long ans =0L;
String[] in = br.readLine().split(" ");
int n = Integer.parseInt(in[0]);
long a = Long.parseLong(in[1]);
long b = Long.parseLong(in[2]);
long k1 = Long.parseLong(in[3]);
PriorityQueue<Long> s = new PriorityQueue<>();
in = br.readLine().split(" ");
for(int i=0;i<n;i++){
Long h = Long.parseLong(in[i])%(a+b);
if(h==0L){
h=a+b;
}
s.add(h);
}
int count=0;
while(!s.isEmpty()){
long p = s.poll();
long hits = 0L;
if(p>a) {
hits = (long) Math.ceil((double) p / (double) a)-1;
}
if(hits!=0) {
k1 -= hits;
}
if (k1 < 0L) {
break;
}
count++;
}
k.append(count+"\n");
out.print(k);
out.flush();
}
}
| Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | 0a2244ee375719f5ce341635368a3558 | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class fightWithMonsters {
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int n = in.nextInt();
long a = in.nextLong();
long b = in.nextLong();
long k = in.nextLong();
long[] map = new long[n];
long pts = 0;
long sum = a+b;
long val = 0;
for (int i = 0; i<n; i++)
{
val = in.nextLong();
map[i] = val % sum;
if (map[i] == 0)
map[i] = sum;
map[i] = ((map[i] + a - 1) / a) - 1;
}
Arrays.sort(map);
for (int i = 0; i<map.length; i++) {
if (k - map[i] < 0)
break;
k -= map[i];
pts++;
}
System.out.println(pts);
}
}
| Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | 38908a3d331b8559c1b8253847017f0d | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
public class MonsterFight {
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 a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
st = new StringTokenizer(br.readLine());
int[] hp = new int[n];
for(int i = 0; i < n; i++) hp[i] = Integer.parseInt(st.nextToken());
int points = 0;
ArrayList<Integer> remaining = new ArrayList<>();
for(int i = 0; i < n; i++){
int score = simulate(hp[i], a , b);
if(score == -1) points++;
else remaining.add(score);
}
Collections.sort(remaining);
for(int i = 0; i < remaining.size(); i++){
double x = (remaining.get(i));
if(k-x < 0) break;
k -= x;
points++;
}
System.out.println(points);
}
static int simulate(int hp, int a, int b){
hp = hp % (a+b);
if(hp == 0) hp += a+b;
hp -= a;
if(hp <= 0) return -1;
else return (int) Math.ceil((double) hp/a);
}
}
| Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | 845efeb3c3635612b27dbfecd67d50e3 | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int a=sc.nextInt();
int b=sc.nextInt();
int k=sc.nextInt();
int arr[]=new int[n];
int s[]=new int[n];
int ans=0;
for(int i=0;i<n;i++)
{
arr[i]=sc.nextInt();
if(arr[i]<=a)
{
ans++;
//System.out.println("AAA "+ans+" "+k);
}
else
{
if(arr[i]%(a+b)==0)
{
double y=Math.ceil((double)b/(double)a);
s[i]=(int)y;
ans++;
//System.out.println("TTT "+ans+" "+k+" "+y);
}
else
{
if(arr[i]%(a+b)<=a){
ans++;
// System.out.println("BBB "+ans+" "+k);
}
else{
/*if(k>=(int)Math.ceil((double)((arr[i]%(a+b))-a)/(double)a))
{*/
s[i]=(int)Math.ceil((double)((arr[i]%(a+b))-a)/(double)a);
ans++;
//System.out.println("FFF "+ans+" "+k);
//}
}
}
}
}
Arrays.sort(s);
int sol=0;
for (int i=0;i<n;i++) {
k-=s[i];
if (k<0) break;
else sol++;
}
System.out.println(sol);
}
}
| Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | fa83e7ad5a808b3f2a542e92723bd349 | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | // Don't place your source in a package
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
// Please name your class Main
public class Main {
//static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
/*static int read() throws IOException {
in.nextToken();
return (int) in.nval;
}
static String readString() throws IOException {
in.nextToken();
return in.sval;
}*/
static Scanner in = new Scanner(System.in);
public static void main (String[] args) throws java.lang.Exception {
//InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
int T=1;
for(int t=0;t<T;t++){
int n=Int();
int a=Int();
int b=Int();
int k=Int();
int A[]=new int[n];
for(int i=0;i<n;i++){
A[i]=Int();
}
Solution sol=new Solution();
sol.solution(A,a,b,k);
}
out.flush();
}
public static int Int(){
return in.nextInt();
}
public static String Str(){
return in.next();
}
}
class Solution{
//constant variable
final int MAX=Integer.MAX_VALUE;
final int MIN=Integer.MIN_VALUE;
//Set<Integer>adjecent[];
//////////////////////////////
public void solution(int A[],int a,int b,int k){
int res=0;
int sum=a+b;
List<Integer>list=new ArrayList<>();
for(int i=0;i<A.length;i++){
int mod=A[i]%sum;
if(mod<=a&&mod!=0){
res++;
}
else if(mod==0){
mod+=b;
list.add(mod);
}
else{
mod-=a;
list.add(mod);
}
}
Collections.sort(list);
//System.out.println(list);
for(int i=0;i<list.size();i++){
int cur=list.get(i);
int need=cur/a;
if(cur%a!=0)need++;
if(k<need)break;
k-=need;
res++;
}
msg(res+"");
}
public void swap(int A[],int l,int r){
int t=A[l];
A[l]=A[r];
A[r]=t;
}
public long C(long fact[],int i,int j){ // C(20,3)=20!/(17!*3!)
// take a/b where a=20! b=17!*3!
if(j>i)return 0;
if(j==0)return 1;
long mod=998244353;
long a=fact[i];
long b=((fact[i-j]%mod)*(fact[j]%mod))%mod;
BigInteger B= BigInteger.valueOf(b);
long binverse=B.modInverse(BigInteger.valueOf(mod)).longValue();
return ((a)*(binverse%mod))%mod;
}
//map operation
public void put(Map<Integer,Integer>map,int i){
if(!map.containsKey(i))map.put(i,0);
map.put(i,map.get(i)+1);
}
public void delete(Map<Integer,Integer>map,int i){
map.put(i,map.get(i)-1);
if(map.get(i)==0)map.remove(i);
}
/*public void tarjan(int p,int r){
if(cut)return;
List<Integer>childs=adjecent[r];
dis[r]=low[r]=time;
time++;
//core for tarjan
int son=0;
for(int c:childs){
if(ban==c||c==p)continue;
if(dis[c]==-1){
son++;
tarjan(r,c);
low[r]=Math.min(low[r],low[c]);
if((r==root&&son>1)||(low[c]>=dis[r]&&r!=root)){
cut=true;
return;
}
}else{
if(c!=p){
low[r]=Math.min(low[r],dis[c]);
}
}
}
}*/
//helper function I would use
public void remove(Map<Integer,Integer>map,int i){
map.put(i,map.get(i)-1);
if(map.get(i)==0)map.remove(i);
}
public void ascii(String s){
for(char c:s.toCharArray()){
System.out.print((c-'a')+" ");
}
msg("");
}
public int flip(int i){
if(i==0)return 1;
else return 0;
}
public boolean[] primes(int n){
boolean A[]=new boolean[n+1];
for(int i=2;i<=n;i++){
if(A[i]==false){
for(int j=i+i;j<=n;j+=i){
A[j]=true;
}
}
}
return A;
}
public void msg(String s){
System.out.println(s);
}
public void msg1(String s){
System.out.print(s);
}
public int[] kmpPre(String p){
int pre[]=new int[p.length()];
int l=0,r=1;
while(r<p.length()){
if(p.charAt(l)==p.charAt(r)){
pre[r]=l+1;
l++;r++;
}else{
if(l==0)r++;
else l=pre[l-1];
}
}
return pre;
}
public boolean isP(String s){
int l=0,r=s.length()-1;
while(l<r){
if(s.charAt(l)!=s.charAt(r))return false;
l++;r--;
}
return true;
}
public int find(int nums[],int x){//union find => find method
if(nums[x]==x)return x;
int root=find(nums,nums[x]);
nums[x]=root;
return root;
}
public int get(int A[],int i){
if(i<0||i>=A.length)return 0;
return A[i];
}
public int[] copy1(int A[]){
int a[]=new int[A.length];
for(int i=0;i<a.length;i++)a[i]=A[i];
return a;
}
public void print1(int A[]){
for(long i:A)System.out.print(i+" ");
System.out.println();
}
public void print2(long A[][]){
for(int i=0;i<A.length;i++){
for(int j=0;j<A[0].length;j++){
System.out.print(A[i][j]+" ");
}System.out.println();
}
}
public int min(int a,int b){
return Math.min(a,b);
}
public int[][] matrixdp(int[][] grid) {
if(grid.length==0)return new int[][]{};
int res[][]=new int[grid.length][grid[0].length];
for(int i=0;i<grid.length;i++){
for(int j=0;j<grid[0].length;j++){
res[i][j]=grid[i][j]+get(res,i-1,j)+get(res,i,j-1)-get(res,i-1,j-1);
}
}
return res;
}
public int get(int grid[][],int i,int j){
if(i<0||j<0||i>=grid.length||j>=grid[0].length)return 0;
return grid[i][j];
}
public int[] suffixArray(String s){
int n=s.length();
Suffix A[]=new Suffix[n];
for(int i=0;i<n;i++){
A[i]=new Suffix(i,s.charAt(i)-'a',0);
}
for(int i=0;i<n;i++){
if(i==n-1){
A[i].next=-1;
}else{
A[i].next=A[i+1].rank;
}
}
Arrays.sort(A);
for(int len=4;len<A.length*2;len<<=1){
int in[]=new int[A.length];
int rank=0;
int pre=A[0].rank;
A[0].rank=rank;
in[A[0].index]=0;
for(int i=1;i<A.length;i++){//rank for the first two letter
if(A[i].rank==pre&&A[i].next==A[i-1].next){
pre=A[i].rank;
A[i].rank=rank;
}else{
pre=A[i].rank;
A[i].rank=++rank;
}
in[A[i].index]=i;
}
for(int i=0;i<A.length;i++){
int next=A[i].index+len/2;
if(next>=A.length){
A[i].next=-1;
}else{
A[i].next=A[in[next]].rank;
}
}
Arrays.sort(A);
}
int su[]=new int[A.length];
for(int i=0;i<su.length;i++){
su[i]=A[i].index;
}
return su;
}
}
//suffix array Struct
class Suffix implements Comparable<Suffix>{
int index;
int rank;
int next;
public Suffix(int i,int rank,int next){
this.index=i;
this.rank=rank;
this.next=next;
}
@Override
public int compareTo(Suffix other) {
if(this.rank==other.rank){
return this.next-other.next;
}
return this.rank-other.rank;
}
public String toString(){
return this.index+" "+this.rank+" "+this.next+" ";
}
}
class Wrapper implements Comparable<Wrapper>{
int spf;int cnt;
public Wrapper(int spf,int cnt){
this.spf=spf;
this.cnt=cnt;
}
@Override
public int compareTo(Wrapper other) {
return this.spf-other.spf;
}
}
class Node{//what the range would be for that particular node
boolean state=false;
int l=0,r=0;
int ll=0,rr=0;
public Node(boolean state){
this.state=state;
}
}
class Seg1{
int A[];
public Seg1(int A[]){
this.A=A;
}
public void update(int left,int right,int val,int s,int e,int id){
if(left<0||right<0||left>right)return;
if(left==s&&right==e){
A[id]+=val;
return;
}
int mid=s+(e-s)/2; //[s,mid] [mid+1,e]
if(left>=mid+1){
update(left,right,val,mid+1,e,id*2+2);
}else if(right<=mid){
update(left,right,val,s,mid,id*2+1);
}else{
update(left,mid,val,s,mid,id*2+1);
update(mid+1,right,val,mid+1,e,id*2+2);
}
}
public int query(int i,int add,int s,int e,int id){
if(s==e&&i==s){
return A[id]+add;
}
int mid=s+(e-s)/2; //[s,mid] [mid+1,e]
if(i>=mid+1){
return query(i,A[id]+add,mid+1,e,id*2+2);
}else{
return query(i,A[id]+add,s,mid,id*2+1);
}
}
}
class MaxFlow{
public static List<Edge>[] createGraph(int nodes) {
List<Edge>[] graph = new List[nodes];
for (int i = 0; i < nodes; i++)
graph[i] = new ArrayList<>();
return graph;
}
public static void addEdge(List<Edge>[] graph, int s, int t, int cap) {
graph[s].add(new Edge(t, graph[t].size(), cap));
graph[t].add(new Edge(s, graph[s].size() - 1, 0));
}
static boolean dinicBfs(List<Edge>[] graph, int src, int dest, int[] dist) {
Arrays.fill(dist, -1);
dist[src] = 0;
int[] Q = new int[graph.length];
int sizeQ = 0;
Q[sizeQ++] = src;
for (int i = 0; i < sizeQ; i++) {
int u = Q[i];
for (Edge e : graph[u]) {
if (dist[e.t] < 0 && e.f < e.cap) {
dist[e.t] = dist[u] + 1;
Q[sizeQ++] = e.t;
}
}
}
return dist[dest] >= 0;
}
static int dinicDfs(List<Edge>[] graph, int[] ptr, int[] dist, int dest, int u, int f) {
if (u == dest)
return f;
for (; ptr[u] < graph[u].size(); ++ptr[u]) {
Edge e = graph[u].get(ptr[u]);
if (dist[e.t] == dist[u] + 1 && e.f < e.cap) {
int df = dinicDfs(graph, ptr, dist, dest, e.t, Math.min(f, e.cap - e.f));
if (df > 0) {
e.f += df;
graph[e.t].get(e.rev).f -= df;
return df;
}
}
}
return 0;
}
public static int maxFlow(List<Edge>[] graph, int src, int dest) {
int flow = 0;
int[] dist = new int[graph.length];
while (dinicBfs(graph, src, dest, dist)) {
int[] ptr = new int[graph.length];
while (true) {
int df = dinicDfs(graph, ptr, dist, dest, src, Integer.MAX_VALUE);
if (df == 0)
break;
flow += df;
}
}
return flow;
}
}
class Edge {
int t, rev, cap, f;
public Edge(int t, int rev, int cap) {
this.t = t;
this.rev = rev;
this.cap = cap;
}
} | Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | c150beddb30a87b78f3e0de1a4cf8bdf | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.Scanner;
public class demo01 {
public static void main(String[] args) {
Scanner sc=new Scanner(new BufferedInputStream(System.in));
int n=sc.nextInt();
long a=sc.nextLong();
long b=sc.nextLong();
//int a=4;
//int b=2;
long k=sc.nextLong();
int m[]=new int[n];
for(int i=0;i<n;i++){
int p=sc.nextInt();
long e=p%(a+b);
if(e<=a&&e>0)
m[i]=0;
else {
m[i]=1;
if(e==0)
e=b;
else
e-=a;
m[i]+=e/a;
if(e%a==0)
m[i]--;
}
}
/*for(int i=0;i<n;i++)
System.out.print(m[i]+" ");
System.out.println();*/
Arrays.sort(m);
/*for(int i=0;i<n;i++)
System.out.print(m[i]+" ");
System.out.println();*/
int flag=0;
int all=0;
for(int i=0;i<n;i++){
all+=m[i];
if(all>k){
System.out.println(i);
flag++;
break;
}
}
if(flag==0)
System.out.println(n);
}
}
| Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | 2708854e35ce7fc310f64b46bcdd8855 | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import java.util.*;
public class cf1296D
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long a = sc.nextLong();
long b = sc.nextLong();
long k = sc.nextLong();
long hp[] = new long [n];
for (int i = 0; i < n; i++)
{
hp[i] = sc.nextLong();
if (hp[i] % (a + b) != 0)
{
hp[i] = hp[i] % (a + b);
}
else if (hp[i] / (a + b) > 0)
{
hp[i] = a + b;
}
}
long temp[]= new long [n];
long c = 0;
for (int i = 0; i < n; i++)
{
if (hp[i] == a)
{
temp[i] = 0;
}
else if (hp[i] % a == 0)
{
temp[i] = hp[i] / a - 1;
}
else
{
temp[i] = hp[i] / a;
}
}
Arrays.sort(temp);
for (int i = 0; i < n && k > 0; i++)
{
if (k - temp[i] >= 0)
{
k -= temp[i];
c++;
}
}
System.out.println(c);
}
} | Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | 8842634976682b07f811e08979f2e6be | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import java.util.*;
public class C617_PD {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int a = in.nextInt();
int b = in.nextInt();
int k = in.nextInt();
int[] arr = new int[n];
int count = 0;
int[] d = new int[n];
for(int i = 0;i<n;i++)
{
arr[i] = in.nextInt();
arr[i] --;
arr[i]%=(a+b);
arr[i]++;
arr[i]-=a;
d[i] = (arr[i]+a-1)/a;
}
//System.out.println(count);
//System.out.println(Arrays.toString(d));
count = 0;
Arrays.sort(d);
for(int i =0;i<n;i++)
{
if(d[i]<=k)
{
count++;
k-=d[i];
}
}
System.out.println(count);
}
}
| Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | cd0cfa751567ec97cba095d419a22f64 | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes |
// you can also use imports, for example:
import java.util.*;
import java.io.*;
public class Solution {
public static void main(String args[]) {
Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
int len = in.nextInt(), a = in.nextInt(), b = in.nextInt(), k = in.nextInt();
long div = (a + b);
PriorityQueue<Long> pq = new PriorityQueue<>();
long ans = 0;
for (int i = 0; i < len; i++) {
long data = in.nextInt() % div;
if (data == 0)
data += div;
if (data <= a)
ans++;
else {
long ele = (data - a) / a + ((data - a) % a == 0 ? 0 : 1);
pq.add(ele);
}
}
while (pq.size() > 0) {
long ele = pq.remove();
k -= ele;
if (k >= 0)
ans++;
else
break;
}
System.out.println(ans);
}
}
| Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | a22f14127058465d78b5d52a7c3aea57 | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
import java.util.List;
public class Main {
static int mod = (int) 1e9 + 7;
public static void main(String[] args) {
FastReader sc = new FastReader();
int n=sc.nextInt(),a=sc.nextInt(),b=sc.nextInt(),k=sc.nextInt();
int[] hp=new int[n];
for(int i=0;i<n;i++)hp[i]=sc.nextInt();
LinkedList<Integer> ll=new LinkedList<>();
int count=0;
for(int i=0;i<n;i++){
if(hp[i]<=a)count++;
else{
int temp=hp[i]%(a+b);
if(temp>0){
if(temp<=a)count++;
else{
int z=temp/a;
temp=temp-z*a;
if(temp!=0)z++;
ll.add(z-1);
}
}
else{
int z=(int)Math.ceil((double)b/a);
ll.add(z);
}
}
}
Collections.sort(ll);
for(int i:ll){
if(i<=k){
count++;
k-=i;
}
else break;
}
System.out.println(count);
}
}
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 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | eb7649e23bb92bef5edb435cd9ca3d7b | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import javax.print.attribute.standard.PrintQuality;
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
import java.util.List;
public class Main {
static int mod = (int) 1e9 + 7;
public static void main(String[] args) {
FastReader sc = new FastReader();
int n=sc.nextInt(),a=sc.nextInt(),b=sc.nextInt(),k=sc.nextInt();
StringBuilder sb=new StringBuilder();
int hp[]=new int[n];
for (int i=0;i<n;i++)hp[i]=sc.nextInt();
int arr[]=new int[n];
int z=a+b;
for (int i=0;i<n;i++){
int x=hp[i];
if (x<=a)arr[i]=0;
else {
if (x % z == 0)arr[i] = (int) Math.ceil((double) b / a);
else {
int rem = x % z;
arr[i] = (int) Math.ceil((double) rem / a)-1;
}
}
}
Arrays.sort(arr);
int ans=0;
for (int i=0;i<n;i++){
if (k-arr[i]<0)break;
k=k-arr[i];
ans++;
}
sb.append(ans);
System.out.println(sb);
}
}
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 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | 584c46b7fcdcead17e87680493f84458 | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main{
public static void main(String[] args) throws IOException {
OutputStream outputStream = System.out;
InputStream inputStream = System.in;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
Solve solver = new Solve();
solver.solve(1, in, out);
out.close();
}
static class Solve {
private static int partition(int arr[], int begin, int end) {
int pivot = arr[end];
int i = (begin-1);
for (int j = begin; j < end; j++) {
if (arr[j] <= pivot) {
i++;
int swapTemp = arr[i];
arr[i] = arr[j];
arr[j] = swapTemp;
}
}
int swapTemp = arr[i+1];
arr[i+1] = arr[end];
arr[end] = swapTemp;
return i+1;
}
public static void quickSort(int arr[], int begin, int end) {
if (begin < end) {
int partitionIndex = partition(arr, begin, end);
quickSort(arr, begin, partitionIndex-1);
quickSort(arr, partitionIndex+1, end);
}
}
public void solve(int testNumber, InputReader in, OutputWriter out) {
int n = in.nextInt();
int a = in.nextInt();
int b = in.nextInt();
int k = in.nextInt();
int div = a+b;
int[]cc = new int[n];
for(int i = 0;i<n;i++) {
int h = in.nextInt();
h%=div;
if(h==0) h+=div;
int l = (h+a-1)/a;
cc[i] = l;
}
int cont = 0;
Arrays.sort(cc);
for(int i = 0;i<cc.length;i++) {
cc[i]--;
if(k-cc[i]<0)break;
else k-=cc[i];
cont++;
}
out.println(cont);
}
}
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 println(String string) {
writer.println(string);
}
public void println(int number) {
writer.println(number);
}
public void println(long number) {
writer.println(number);
}
public void println(double number) {
writer.println(number);
}
public void println(char number) {
writer.println(number);
}
public void print(long number) {
writer.print(number);
}
public void print(int number) {
writer.print(number);
}
public void print(char number) {
writer.print(number);
}
public void print(String string) {
writer.print(string);
}
public void print(double number) {
writer.print(number);
}
}
static class InputReader {
private InputStream in;
private byte[] buffer = new byte[1024];
private int curbuf;
private int lenbuf;
public InputReader(InputStream in) {
this.in = in;
this.curbuf = this.lenbuf = 0;
}
public String nextLine() {
StringBuilder sb = new StringBuilder();
int b = readByte();
while (b!=10) {
sb.appendCodePoint(b);
b = readByte();
}
if(sb.length()==0)return "";
return sb.toString().substring(0,sb.length()-1);
}
public boolean hasNextByte() {
if (curbuf >= lenbuf) {
curbuf = 0;
try {
lenbuf = in.read(buffer);
} catch (IOException e) {
throw new InputMismatchException();
}
if (lenbuf <= 0)
return false;
}
return true;
}
private int readByte() {
if (hasNextByte())
return buffer[curbuf++];
else
return -1;
}
private boolean isSpaceChar(int c) {
return !(c >= 33 && c <= 126);
}
private void skip() {
while (hasNextByte() && isSpaceChar(buffer[curbuf]))
curbuf++;
}
public boolean hasNext() {
skip();
return hasNextByte();
}
public String next() {
if (!hasNext())
throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while (!isSpaceChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public int nextInt() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
public long nextLong() {
if (!hasNext())
throw new NoSuchElementException();
int c = readByte();
while (isSpaceChar(c))
c = readByte();
boolean minus = false;
if (c == '-') {
minus = true;
c = readByte();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res = res * 10 + c - '0';
c = readByte();
} while (!isSpaceChar(c));
return (minus) ? -res : res;
}
public double nextDouble() {
return Double.parseDouble(next());
}
public int[] nextIntArray(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public long[] nextLongArray(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public char[][] nextCharMap(int n, int m) {
char[][] map = new char[n][m];
for (int i = 0; i < n; i++)
map[i] = next().toCharArray();
return map;
}
}
} | Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | e57f3b723393594065335a34ea7456fa | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import java.util.*;
public class codefor {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int a = input.nextInt();
int b = input.nextInt();
int k = input.nextInt();
int arr[] = new int[n];
for(int i=0;i<n;i++) {
arr[i] = input.nextInt();
}
System.out.println(func(arr,n,k,a,b));
}
static int func(int arr[],int n,int k,int a,int b) {
for(int i=0;i<n;i++) {
arr[i] = arr[i]%(a+b);
if(arr[i]==0) {
arr[i]+=a+b;
}
arr[i] = ((arr[i] + a - 1) / a) - 1;
}
Arrays.sort(arr);
for(int i=1;i<n;i++) {
arr[i]+=arr[i-1];
}
int ans=0;
for(int i=0;i<n;i++) {
if(arr[i]>k) {
break;
}
ans++;
}
return ans;
}
} | Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | a57916ccfc674187da368d115874fbf4 | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import java.util.*;
import java.io.*;
public class Main{
public static void main(String[] args) throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String[] s=br.readLine().split(" ");
int n=Integer.parseInt(s[0]);
int a=Integer.parseInt(s[1]);
int b=Integer.parseInt(s[2]);
int k=Integer.parseInt(s[3]);
String[] array=br.readLine().split(" ");
int p=a+b;
ArrayList<Integer> list=new ArrayList<Integer>();
int z=(int)Math.ceil(b/(double)a);
int count = 0;
for(int i=0;i<n;i++)
{
int l=Integer.parseInt(array[i]);
if(l%p<=a && l%p!=0) count++;
else if(l%p==0)
{
list.add(z);
}
else
{
list.add((int)Math.ceil((l%p-a)/(double)a));
}
}
Collections.sort(list);
int c=0;
int m=0;
for(int i=0;i<list.size();i++)
{
if(m+list.get(i)<=k)
{
m+=list.get(i);
c++;
}
else break;
}
System.out.println(count+c);
}
} | Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | d571582e9321f21af9960fe672a12f62 | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class qD {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
long a = in.nextLong();
long b = in.nextLong();
long k = in.nextLong();
long [] h = new long [n];
for (int i = 0; i < n; i++) {
h[i] = in.nextLong();
if (h[i] % (a + b) != 0) {
h[i] = h[i] % (a + b);
} else if (h[i] / (a + b) > 0) {
h[i] = a + b;
}
}
long [] skips = new long [n];
long points = 0;
for (int i = 0; i < n; i++) {
if (h[i] == a) {
skips[i] = 0;
} else if (h[i] % a == 0) {
skips[i] = h[i] / a - 1;
} else {
skips[i] = h[i] / a;
}
}
Arrays.sort(skips);
for (int i = 0; i < n && k > 0; i++) {
if (k - skips[i] >= 0) {
k -= skips[i];
points++;
}
}
System.out.println(points);
}
}
| Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | b34a74975a7357f8430dc41196c3fb99 | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | //package power.rankings;
import java.util.*;
import java.io.*;
public class PowerRankings {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st;
public static void main(String[] args) throws IOException {
int n = readInt(), a = readInt(), b = readInt(), k = readInt(), h[] = new int[n], ans = 0;
ArrayList<Integer> list = new ArrayList();
for(int i = 0; i < n; i++){
h[i] = readInt()%(a+b);
if(h[i] != 0 && h[i]<=a){ans++;}
else{
if(h[i]==0)h[i]=h[i]+(a+b);
h[i]-=a;
int skip = h[i]/a; if(h[i]%a!=0)skip++;
list.add(skip);
}
}
Collections.sort(list);
for(int i = 0; i < list.size(); i++){
if(k >= list.get(i)){k-=list.get(i);ans++;}
else break;
}System.out.println(ans);
}
static String next() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine().trim());
}
return st.nextToken();
}
static long readLong() throws IOException {
return Long.parseLong(next());
}
static int readInt() throws IOException {
return Integer.parseInt(next());
}
static double readDouble() throws IOException {
return Double.parseDouble(next());
}
static char readCharacter() throws IOException {
return next().charAt(0);
}
static String readLine() throws IOException {
return br.readLine().trim();
}
static int upper_bound(int a[], int key) {
int lo = 0, hi = a.length - 1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (a[mid] == key) {
lo = mid + 1;
} else if (a[mid] > key) {
hi = mid - 1;
} else {
lo = mid + 1;
}
}
return hi;
}
static int lower_bound(int a[], int key) {
int lo = 0, hi = a.length - 1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (a[mid] == key) {
hi = mid - 1;
} else if (a[mid] > key) {
hi = mid - 1;
} else {
lo = mid + 1;
}
}
return lo;
}
static long gcd(long x, long y) {
return y == 0 ? x : gcd(y, x % y);
}
public static int modexponent(int x, int exp, int mod) {
if (exp == 0) {
return 1;
}
int t = modexponent(x, exp / 2, mod);
t = (t * t) % mod;
if (exp % 2 == 0) {
return t;
}
return (t * x % mod) % mod;
}
public static boolean next_permutation(char a[]) {
int n = a.length;
int p = n - 2;
int q = n - 1;
while (p >= 0 && a[p] >= a[p + 1]) {
p--;
}
if (p < 0) {
return false;
}
while (a[q] <= a[p]) {
q--;
}
char t = a[p];
a[p] = a[q];
a[q] = t;
for (int i = p + 1, j = n - 1; i < j; i++, j--) {
t = a[i];
a[i] = a[j];
a[j] = t;
}
return true;
}
static long getSubHash(long hash[], long pow[], int l, int r) {
return hash[r] - hash[l - 1] * pow[r - l + 1];
}
}
| Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | 20d6eb5cfd27a630cdc09dbbced5efd2 | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;
public class MakingString implements Runnable
{
static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
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 String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
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 double nextDouble()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.')
{
c = read();
double m = 1;
while (!isSpaceChar(c))
{
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString()
{
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c)
{
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next()
{
return readString();
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
}
// if modulo is required set value accordingly
public static long[][] matrixMultiply2dL(long t[][],long m[][])
{
long res[][]= new long[t.length][m[0].length];
for(int i=0;i<t.length;i++)
{
for(int j=0;j<m[0].length;j++)
{
res[i][j]=0;
for(int k=0;k<t[0].length;k++)
{
res[i][j]+=t[i][k]+m[k][j];
}
}
}
return res;
}
static long combination(long n,long r)
{
long ans=1;
for(long i=0;i<r;i++)
{
ans=(ans*(n-i))/(i+1);
}
return ans;
}
static int mat(String a,String b)
{
int count=0;
for(int i=0;i<a.length();i++)
{
if(a.charAt(i)!=b.charAt(i))
count++;
}
return count;
}
public static void main(String args[]) throws Exception
{
new Thread(null, new MakingString(),"MakingString",1<<27).start();
}
// **just change the name of class from Main to reuquired**
public void run()
{
InputReader sc = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
int n=sc.nextInt();
int a =sc.nextInt();
int b=sc.nextInt();
int k=sc.nextInt();
int arr[]=new int[n];
int res[]=new int[n];
for(int i=0;i<n;i++)
{
arr[i]=sc.nextInt();
res[i]=arr[i]%(a+b);
if(res[i]==0)
res[i]=a+b;
res[i]=res[i]-a;
}
int count=0;
Arrays.sort(res);
for(int i=0;i<n;i++)
{
if(res[i]<=0)
count++;
else if(Math.ceil(res[i]/a)<=k)
{
double d1=res[i];
double d2=a;
k=k-(int)Math.ceil(d1/d2);
if(k>=0)
count++;
}
}
w.println(count);
System.out.flush();
w.close();
}
} | Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | ac0b51fde94e5ddf7408ff7363a5698a | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;
public class MakingString implements Runnable
{
static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
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 String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
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 double nextDouble()
{
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.')
{
c = read();
double m = 1;
while (!isSpaceChar(c))
{
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString()
{
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do
{
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c)
{
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next()
{
return readString();
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
}
// if modulo is required set value accordingly
public static long[][] matrixMultiply2dL(long t[][],long m[][])
{
long res[][]= new long[t.length][m[0].length];
for(int i=0;i<t.length;i++)
{
for(int j=0;j<m[0].length;j++)
{
res[i][j]=0;
for(int k=0;k<t[0].length;k++)
{
res[i][j]+=t[i][k]+m[k][j];
}
}
}
return res;
}
static long combination(long n,long r)
{
long ans=1;
for(long i=0;i<r;i++)
{
ans=(ans*(n-i))/(i+1);
}
return ans;
}
static int mat(String a,String b)
{
int count=0;
for(int i=0;i<a.length();i++)
{
if(a.charAt(i)!=b.charAt(i))
count++;
}
return count;
}
public static void main(String args[]) throws Exception
{
new Thread(null, new MakingString(),"MakingString",1<<27).start();
}
// **just change the name of class from Main to reuquired**
public void run()
{
InputReader sc = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
int n=sc.nextInt();
int a =sc.nextInt();
int b=sc.nextInt();
int k=sc.nextInt();
int arr[]=new int[n];
int res[]=new int[n];
for(int i=0;i<n;i++)
{
arr[i]=sc.nextInt();
res[i]=arr[i]%(a+b);
if(res[i]==0)
res[i]=a+b;
res[i]=res[i]-a;
}
int count=0;
Arrays.sort(res);
for(int i=0;i<n;i++)
{
if(res[i]<=0)
count++;
else if(Math.ceil(res[i]/a)<=k)
{
double d1=res[i];
double d2=a;
k=k-(int)Math.ceil(d1/d2);
if(k>=0)
count++;
}
}
System.out.println(count);
System.out.flush();
w.close();
}
} | Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | 332400cb9e0a63fad0f8dd6c0bec5e66 | train_002.jsonl | 1580826900 | There are $$$n$$$ monsters standing in a row numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th monster has $$$h_i$$$ health points (hp). You have your attack power equal to $$$a$$$ hp and your opponent has his attack power equal to $$$b$$$ hp.You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monster and fight it till his death, then you and your opponent go the second monster and fight it till his death, and so on. A monster is considered dead if its hp is less than or equal to $$$0$$$.The fight with a monster happens in turns. You hit the monster by $$$a$$$ hp. If it is dead after your hit, you gain one point and you both proceed to the next monster. Your opponent hits the monster by $$$b$$$ hp. If it is dead after his hit, nobody gains a point and you both proceed to the next monster. You have some secret technique to force your opponent to skip his turn. You can use this technique at most $$$k$$$ times in total (for example, if there are two monsters and $$$k=4$$$, then you can use the technique $$$2$$$ times on the first monster and $$$1$$$ time on the second monster, but not $$$2$$$ times on the first monster and $$$3$$$ times on the second monster).Your task is to determine the maximum number of points you can gain if you use the secret technique optimally. | 256 megabytes | import java.util.*;
import java.io.*;
public class FightwithMonsters
{
public static void main(String[] args)throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String[] str=br.readLine().split(" ");
int n=Integer.parseInt(str[0]);
int a=Integer.parseInt(str[1]);
int b=Integer.parseInt(str[2]);
int k=Integer.parseInt(str[3]);
str=br.readLine().split(" ");
int[] arr=new int[n];
for(int i=0;i<n;i++)
{
int num=Integer.parseInt(str[i]);
int mod=num%(a+b);
arr[i]=(mod);
if(mod==0)
arr[i]+=a+b;
arr[i]=((arr[i]+a-1)/a)-1;
}
Arrays.sort(arr);
int ans=0;
for(int i=0;i<n;i++)
{
if(k-arr[i]<0)
break;
ans++;
k-=arr[i];
}
System.out.println(ans);
}
} | Java | ["6 2 3 3\n7 10 50 12 1 8", "1 1 100 99\n100", "7 4 2 1\n1 3 5 4 2 7 6"] | 1 second | ["5", "1", "6"] | null | Java 8 | standard input | [
"sortings",
"greedy"
] | ada28bbbd92e0e7c6381bb9a4b56e7f9 | The first line of the input contains four integers $$$n, a, b$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le a, b, k \le 10^9$$$) β the number of monsters, your attack power, the opponent's attack power and the number of times you can use the secret technique. The second line of the input contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the health points of the $$$i$$$-th monster. | 1,500 | Print one integer β the maximum number of points you can gain if you use the secret technique optimally. | standard output | |
PASSED | 66735b566c0a06bf9887c5c710111cd5 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | //take 3 (with fucking counters)
//take 4 bitches
//take 5 the counter are no counters anymore, well not so much
import java.util.Scanner;
public class foo {
static boolean isEven(int n){
if ( n % 2 == 0 ) return true;
else return false;
}
public static void main(String[] args) {
Scanner read = new Scanner(System.in);
int t = read.nextInt();
int resa = 0 , losta = 0 , resb=0 , lostb = 0;
while(true){
if(t==0) break;
int server = read.nextInt();
int rx = read.nextInt();
int lx = read.nextInt();
if (server==1){
resa+= rx;
losta+= lx;
}
else if (server==2){
resb+=rx;
lostb+=lx;
}
t--;
}
System.out.println( (resa >= losta? "LIVE" : "DEAD") );
System.out.println( (resb >= lostb? "LIVE" : "DEAD") );
}
} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | 766a66169aecc3b5b7603db5c89244a3 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
int n = in.nextInt();
int aX = 0, aY = 0;
int bX = 0, bY = 0;
while (n-- > 0){
int server = in.nextInt();
if (server == 1){
aX += in.nextInt();
aY += in.nextInt();
}
else{
bX += in.nextInt();
bY += in.nextInt();
}
}
if (aX >= (double)(aX+aY)/2) System.out.println("LIVE");
else System.out.println("DEAD");
if (bX >= (double)(bX+bY)/2) System.out.println("LIVE");
else System.out.println("DEAD");
}
}
| Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | a8085b0122ad81a8ce53490c601681ef | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
StringBuilder sb = new StringBuilder();
int n = sc.nextInt();
int cnt1 = 0 , all1 = 0 , cnt2 = 0 , all2 = 0;
for (int i = 0 ; i < n ; ++ i) {
int op = sc.nextInt();
int sent = sc.nextInt() , rec = sc.nextInt();
if (op == 1) {
cnt1 += sent;
all1 ++ ;
}
else {
cnt2 += sent;
all2 ++ ;
}
}
if (cnt1 >= all1 * 5) {
System.out.println("LIVE");
}
else {
System.out.println("DEAD");
}
if (cnt2 >= all2 * 5) {
System.out.println("LIVE");
}
else {
System.out.println("DEAD");
}
out.flush();
out.close();
}
static class Scanner {
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s) {
br = new BufferedReader(new InputStreamReader(s));
}
public String next() throws IOException {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(next());
}
public long nextLong() throws IOException {
return Long.parseLong(next());
}
public String nextLine() throws IOException {
return br.readLine();
}
public double nextDouble() throws IOException {
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if (x.charAt(0) == '-') {
neg = true;
start++;
}
for (int i = start; i < x.length(); i++)
if (x.charAt(i) == '.') {
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
} else {
sb.append(x.charAt(i));
if (dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg ? -1 : 1);
}
public boolean ready() throws IOException {
return br.ready();
}
}
} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | b33af145317e88b7197c4505679c66a7 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] to=new int[2];
int[] from=new int[2];
for(int i = 0 ; i<n;i++){
int z = sc.nextInt()-1;
to[z]+=sc.nextInt();
from[z]+=sc.nextInt();
}
for(int i = 0 ; i<from.length;i++){
if(to[i]>=from[i]){
System.out.println("LIVE");
}
else{
System.out.println("DEAD");
}
}
}
}
| Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | ecbb4bf27b98f9788dd2e387de4099cd | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes |
import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Quan
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a=0, b=0;
for (int i = 0; i < n; i++) {
int t, x, y;
t = sc.nextInt();
x = sc.nextInt();
y = sc.nextInt();
if(t==1)
a+=(x-y);
else
b+=(x-y);
}
if(a>=0)
System.out.println("LIVE");
else
System.out.println("DEAD");
if(b>=0)
System.out.println("LIVE");
else
System.out.println("DEAD");
}
}
| Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | d9e24a266f439d6a54664540820477c9 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes |
import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author anhnth37
*/
public class A_0245 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int a = 0;
int b = 0;
for (int i = 0; i < n; i++) {
int t = input.nextInt();
int x = input.nextInt();
int y = input.nextInt();
if (t == 1) {
a += x - y;
} else {
b += x - y;
}
}
if (a >= 0) {
System.out.println("LIVE");
} else {
System.out.println("DEAD");
}
if (b >= 0) {
System.out.println("LIVE");
} else {
System.out.println("DEAD");
}
}
}
| Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | 1e564cd5fe6a2cfd044f7507e2da685d | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes |
import java.util.*;
public class A {
public static void main(String[] args) {
new A().begin();
}
public void begin() {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int xa = 0, ya = 0;
int xb = 0, yb = 0;
for (int i = 1; i <= n; i++) {
int ti = scanner.nextInt();
if(ti == 1){
xa += scanner.nextInt();
ya += scanner.nextInt();
}
else{
xb += scanner.nextInt();
yb += scanner.nextInt();
}
}
if(xa >= ya) System.out.println("LIVE");
else System.out.println("DEAD");
if(xb >= yb) System.out.println("LIVE");
else System.out.println("DEAD");
}
}
| Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | 933b3148e3c6efab227e50f43aa44207 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | /******************************************************************************
Online Java Compiler.
Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.
*******************************************************************************/
import java.util.*;
public class Main
{
public static void main (String[]args)
{
Scanner sc = new Scanner (System.in);
int val = sc.nextInt();
int [] arr=new int [val*3];
int totalA=0,totalB=0,reachesA=0,reachesB=0,failsA=0,failsB=0;
int current=-5; // A is 1 B is 2
for(int i=0;i<arr.length;i++){
int temp = sc.nextInt();
arr[i]=temp;
if(i%3==0){
current=temp;
}
else{
if(current==1){
if(i%3==1){
reachesA+=temp;
}
totalA+=temp;
}
else{
if(i%3==1){
reachesB+=temp;
}
totalB+=temp;
}
}
}
float divA=(float) reachesA/totalA;
float divB=(float) reachesB/totalB;
if(divA >= 0.5){
System.out.println("LIVE");
}
else{
System.out.println("DEAD");
}
if(divB >= 0.5){
System.out.println("LIVE");
}
else{
System.out.println("DEAD");
}
}
} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | 443d443e4376e75fcd6ee6180bca4beb | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | //package main;
import java.io.*;
import java.util.*;
import java.awt.Point;
public final class Main {
BufferedReader br;
StringTokenizer stk;
public static void main(String[] args) throws Exception {
new Main().run();
}
{
stk = null;
br = new BufferedReader(new InputStreamReader(System.in));
}
long mod = 1000_000_000 + 7;
void run() throws Exception {
int n = ni();
int[][] s = new int[2][2];
while(n-- > 0) {
int svr = ni() - 1, x = ni(), y = ni();
s[svr][0] += x;
s[svr][1] += y;
}
if(s[0][0] >= s[0][1])
System.out.println("LIVE");
else
System.out.println("DEAD");
if(s[1][0] >= s[1][1])
System.out.println("LIVE");
else
System.out.println("DEAD");
}
//Reader & Writer
String nextToken() throws Exception {
if (stk == null || !stk.hasMoreTokens()) {
stk = new StringTokenizer(br.readLine(), " ");
}
return stk.nextToken();
}
String nt() throws Exception {
return nextToken();
}
int ni() throws Exception {
return Integer.parseInt(nextToken());
}
long nl() throws Exception {
return Long.parseLong(nextToken());
}
double nd() throws Exception {
return Double.parseDouble(nextToken());
}
} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | 24ff79fa2d28ce87d2a03a174fa5760d | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author Bartikraw
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
static class TaskA {
public void solve(int testNumber, Scanner in, PrintWriter out) {
int k = in.nextInt();
int pingA = 0;
int deadA = 0;
int pingB = 0;
int deadB = 0;
for (int i = 0; i < k; i++) {
int t = in.nextInt();
int x = in.nextInt();
int y = in.nextInt();
if (t == 1) {
pingA += x;
deadA += y;
} else {
pingB += x;
deadB += y;
}
}
if (pingA >= deadA) {
out.println("LIVE");
} else {
out.println("DEAD");
}
if (pingB >= deadB) {
out.println("LIVE");
} else {
out.println("DEAD");
}
}
}
}
| Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | 7037ddda824f1a01f526a18c5ff4de21 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.io.*;
import java.util.*;
public class A {
FastScanner in;
PrintWriter out;
void solve() {
int n = in.nextInt();
int sa=0,fa=0,sb=0,fb=0;
while(n-->0) {
if(in.nextInt()==1) {
sa+=in.nextInt();
fa+=in.nextInt();
}else {
sb+=in.nextInt();
fb+=in.nextInt();
}
}
out.println(sa>=fa ? "LIVE":"DEAD");
out.println(sb>=fb ? "LIVE":"DEAD");
}
public static void main(String[] args) {
new A().runIO();
}
void run() {
try {
in = new FastScanner(new File("A.in"));
out = new PrintWriter(new File("A.out"));
solve();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
void runIO() {
in = new FastScanner(System.in);
out = new PrintWriter(System.out);
solve();
out.close();
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(File f) {
try {
br = new BufferedReader(new FileReader(f));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public FastScanner(InputStream f) {
br = new BufferedReader(new InputStreamReader(f));
}
String next() {
while (st == null || !st.hasMoreTokens()) {
String s = null;
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (s == null)
return null;
st = new StringTokenizer(s);
}
return st.nextToken();
}
boolean hasMoreTokens() {
while (st == null || !st.hasMoreTokens()) {
String s = null;
try {
s = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (s == null)
return false;
st = new StringTokenizer(s);
}
return true;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | 8207337a84ee842a36b0d6fb4962c682 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.Scanner;
public class chapter {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[][]a = new int[n][3];
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
a[i][j] = sc.nextInt();
}
}
int pingA = 0;
int pingB = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
if(a[i][0]==1){
pingA+=a[i][1]-a[i][2];
}else {
pingB+=a[i][1]-a[i][2];
}
}
}
System.out.println(pingA>=0?"LIVE":"DEAD");
System.out.println(pingB>=0?"LIVE":"DEAD");
}
}
| Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | 11c2cf02ca9ca05120ef9745b19966b0 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | //package codeforces;
import java.util.Scanner;
public class SystemAdministrator {
public static void print(int pingX, int pingY) {
if (pingX >= pingY) {
System.out.println("LIVE");
}
else
System.out.println("DEAD");
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int pingAx = 0;
int pingAy = 0;
int pingBx = 0;
int pingBy = 0;
for (int i = 0; i < N; i++) {
int ping = scanner.nextInt();
if (ping == 1) {
pingAx = pingAx + scanner.nextInt();
pingAy = pingAy + scanner.nextInt();
}
else {
pingBx = pingBx + scanner.nextInt();
pingBy = pingBy + scanner.nextInt();
}
}
print(pingAx, pingAy);
print(pingBx, pingBy);
scanner.close();
}
}
| Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | e00ca96ac13a3e1d937ceec734a5a34c | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.Scanner;
public class Sample {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int cx = 0, ct = 0, dy = 0, dt = 0;
while(n-- != 0) {
int t = sc.nextInt();
int x = sc.nextInt();
int y = sc.nextInt();
if(t == 1) {
cx = cx + x;
ct = ct + x + y;
} else {
dy = dy + x;
dt = dt + x + y;
}
}
if(cx >= ct/2) {
System.out.println("LIVE");
} else {
System.out.println("DEAD");
}
if(dy >= dt/2) {
System.out.println("LIVE");
} else {
System.out.println("DEAD");
}
}
} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | 27f8629f2fe5000fa3335df9dd93f275 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static StringBuilder data=new StringBuilder();
final static FastReader in = new FastReader();
public static void main(String[] args) {
int n=in.nextInt();
String a;
String []b;
int sa=0,sb=0;
for (int i = 0; i < n; i++) {
a=in.nextLine();
b=a.split(" ");
if(b[0].equalsIgnoreCase("1")){
sa+=Integer.parseInt(b[1]);
sa-=Integer.parseInt(b[2]);
}else{
sb+=Integer.parseInt(b[1]);
sb-=Integer.parseInt(b[2]);
}
}
if(sa>=0){
System.out.println("LIVE");
}else{
System.out.println("DEAD");
}
if(sb>=0){
System.out.println("LIVE");
}else{
System.out.println("DEAD");
}
}
static void fileOut(String s) {
File out = new File("output.txt");
try {
FileWriter fw = new FileWriter(out);
fw.write(s);
fw.flush();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
public FastReader(String path) {
try {
br = new BufferedReader(new
InputStreamReader(new FileInputStream(path)));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
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());
}
float nextFloat() {
return Float.parseFloat(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | 693e8957013a9b10801def600d12697f | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.*;
public class Problem_245A {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int gooda = 0;
int bada = 0;
int goodb = 0;
int badb = 0;
for(int i = 0; i < n; i++) {
int t = in.nextInt();
if(t == 1) {
gooda += in.nextInt();
bada += in.nextInt();
}
else {
goodb += in.nextInt();
badb += in.nextInt();
}
}
if(gooda >= bada) System.out.println("LIVE");
else if(!(gooda >= bada)) System.out.println("DEAD");
if(goodb >= badb) System.out.println("LIVE");
else if(!(goodb >= badb)) System.out.println("DEAD");
}
} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | e798238ac14875c24100c269e05979d4 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int a = 0,b = 0;
while(n-->0) {
int x = sc.nextInt(),g = sc.nextInt(),l = sc.nextInt();
if(x==1) {
a+=g;
a-=l;
}
else {
b+=g;
b-=l;
}
}
if(a>=0) {
System.out.println("LIVE");
}else {
System.out.println("DEAD");
}
if(b>=0) {
System.out.println("LIVE");
}else {
System.out.println("DEAD");
}
}
}
| Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | 7c25b489121ab9ce42c7dbeec6b6dd6d | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.Scanner;
public class Servers {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a = 0;
int nota = 0;
int b = 0;
int notb = 0;
for (int i = 0; i < n; i++) {
int t = sc.nextInt();
int x = sc.nextInt();
int y = sc.nextInt();
if(t==1) {
a += x;
nota += y;
} else {
b += x;
notb += y;
}
}
if(a >= nota)
System.out.println("LIVE");
else
System.out.println("DEAD");
if(b >= notb)
System.out.println("LIVE");
else
System.out.println("DEAD");
}
}
| Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | 5dbfc2cdcb405424a9351a812a4fbbf3 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.ArrayList;
import java.util.Scanner;
public class SystemAdministrator_245A {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
ArrayList<Integer> array = new ArrayList<Integer>();
for (int i = 0; i < n; i++) {
int index = input.nextInt();
int a = input.nextInt();
int b = input.nextInt();
index--;
if (index < array.size())
array.set(index, array.get(index) + (a - b));
else
array.add(a - b);
}
for (int x : array) {
if (x < 0)
System.out.println("DEAD");
else
System.out.println("LIVE");
}
input.close();
}
}
| Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | eb8ee47170425d84ebb0ca03560dd7f7 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.Scanner;
public class Codeforces {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] sa = new int[2];
int[] sb = new int[2];
int s;
for (int i=0;i<n;i++){
s = in.nextInt();
if (s == 1){
sa[0] += in.nextInt();
sa[1] += in.nextInt();
}
else{
sb[0] += in.nextInt();
sb[1] += in.nextInt();
}
}
if (sa[0] - sa[1] >= 0)
System.out.println("LIVE");
else
System.out.println("DEAD");
System.out.println((sb[0] - sb[1] >= 0 ? "LIVE" : "DEAD"));
}
} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | fc76a5e1aacb17a213f966cdc40164ac | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author bacali
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastScanner in = new FastScanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
ASystemAdministrator solver = new ASystemAdministrator();
solver.solve(1, in, out);
out.close();
}
static class ASystemAdministrator {
public void solve(int testNumber, FastScanner in, PrintWriter out) {
int n = in.nextInt();
int xone, yone, xtwo, ytow;
xone = yone = xtwo = ytow = 0;
while (n-- > 0) {
int p = in.nextInt();
int x = in.nextInt();
int y = in.nextInt();
if (p == 1) {
xone += x;
yone += y;
} else {
xtwo += x;
ytow += y;
}
}
out.println(xone < yone ? "DEAD" : "LIVE");
out.println(xtwo < ytow ? "DEAD" : "LIVE");
}
}
static class FastScanner {
private BufferedReader br;
private StringTokenizer st;
public FastScanner(InputStream inputStream) {
br = new BufferedReader(new InputStreamReader(inputStream));
}
public 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());
}
}
}
| Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | 60bbda7b6572f403d561db98b8c34a78 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.Scanner;
public class CodeForces
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int a1 = 0;
int a2 = 0;
int b1 = 0;
int b2 = 0;
for (int i = 0; i < n; i++)
{
int t = input.nextInt();
if (t == 1)
{
a1 += input.nextInt();
a2 += input.nextInt();
} else
{
b1 += input.nextInt();
b2 += input.nextInt();
}
}
if (a1 >= a2)
{
System.out.println("LIVE");
} else
{
System.out.println("DEAD");
}
if (b1 >= b2)
{
System.out.println("LIVE");
} else
{
System.out.println("DEAD");
}
}
} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | 55dc3183cf231332c4aa2b09121c0b71 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
import java.awt.geom.*;
public class Test {
public static void main(String[] args) {
MyScanner sc = new MyScanner();
int n = sc.ni();
int apos = 0, aneg = 0, bpos = 0, bneg = 0;
for (int i = 0; i < n; i++) {
int t = sc.ni(), sent = sc.ni(), lost = sc.ni();
if (t == 1) {
apos += sent;
aneg += lost;
} else {
bpos += sent;
bneg += lost;
}
}
if (apos >= aneg)
System.out.println("LIVE");
else
System.out.println("DEAD");
if (bpos >= bneg)
System.out.println("LIVE");
else
System.out.println("DEAD");
}
/////////// TEMPLATE FROM HERE /////////////////
private static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int ni() {
return Integer.parseInt(next());
}
float nf() {
return Float.parseFloat(next());
}
long nl() {
return Long.parseLong(next());
}
double nd() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | c0577857c4abf17e39bf95607ece0b6d | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.*;
public class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a = 0;
int b = 0;
for (int i = 0; i < n; i++) {
int ping = sc.nextInt();
int success;
int lost;
if (ping == 1) {
success = sc.nextInt();
lost = sc.nextInt();
a += success - lost;
} else {
success = sc.nextInt();
lost = sc.nextInt();
b += success - lost;
}
}
sc.close();
if (0 <= a) {
System.out.println("LIVE");
} else {
System.out.println("DEAD");
}
if (0 <= b) {
System.out.println("LIVE");
} else {
System.out.println("DEAD");
}
}
} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | 4f9fb3964752731fbf8cc56b9dc657f8 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.*;
import java.lang.*;;
import java.io.*;
public class Codechef
{
public static void main (String[] args)
{
java.util.Scanner s=new java.util.Scanner(System.in);
// int t=s.nextInt();
int n=s.nextInt();
int S1=0,T1=0,S2=0,T2=0;
while(n-->0)
{
int t=s.nextInt();
int x=s.nextInt();
int y=s.nextInt();
if(t==1)
{
S1+=x;
T1+=x+y;
}
if(t==2)
{
S2+=x;
T2+=x+y;
}
}
if(S1>=T1/2)
{
System.out.println("LIVE");
}else
System.out.println("DEAD");
if(S2>=T2/2)
{
System.out.println("LIVE");
}else
System.out.println("DEAD");
}} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | 74e4f53bcd0a114ffd564a0004051b5e | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.Scanner;
public class Code245A {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int s=sc.nextInt();
int a=0,b=0;
for(int i=0;i<s;i++){
int l=sc.nextInt();
int m=sc.nextInt();
int n=sc.nextInt();
if(l==1)
a=a+(m-n);
else
b=b+(m-n);
}
if(a>=0)
System.out.println("LIVE");
else
System.out.println("DEAD");
if(b>=0)
System.out.println("LIVE");
else
System.out.println("DEAD");
}
} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | acc1a0b177fee1bf680ed38d068cfdd2 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.Scanner;
public class SystemAdministrator {
public static void main(String[] args) {
Scanner sin = new Scanner(System.in);
int bing = sin.nextInt();
int server, aCount = 0, bCount = 0, a = 0, b = 0, noth = 0;
for(int i = 0; i < bing; i++)
{
server = sin.nextInt();
if(server == 1)
{
aCount += sin.nextInt();
noth = sin.nextInt();
a++;
}
else
{
bCount += sin.nextInt();
noth = sin.nextInt();
b++;
}
}
if(10 * a / 2 <= aCount)
System.out.println("LIVE");
else
System.out.println("DEAD");
if(10 * b / 2 <= bCount)
System.out.println("LIVE");
else
System.out.println("DEAD");
}
} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | 3aede3fce16fb23377aabe78493b4984 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.Scanner;
public class Codeforces
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int totalA = 0, totalB = 0, packageA = 0, packageB = 0, t = 0, x = 0, y = 0;
for (int i = 0 ;i< n ; i++)
{
t = scan.nextInt();
x= scan.nextInt();
y= scan.nextInt();
if(t == 1)
{
totalA = totalA + 10;
packageA = packageA + x;
}
else
{
totalB = totalB + 10;
packageB = packageB+x;
}
}
if(packageA>=totalA/2)
{
System.out.print("LIVE\n");
}
else
{
System.out.print("DEAD\n");
}
if (packageB>=totalB/2)
{
System.out.print("LIVE\n");
}
else
{
System.out.print("DEAD\n");
}
}
} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | 9b1333c546073347805c69b79f7db057 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.Scanner;
public class ASystemAdministrator {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
long sum=0,sum1=0,sum2=0,sum3=0;
for(int i=0;i<n;i++) {
int t=sc.nextInt();
int x=sc.nextInt();
int y=sc.nextInt();
if(t==1) {
sum=sum+x;
sum1=sum1+x+y;
}
else {
sum2=sum2+x;
sum3=sum3+x+y;
}
}
long p=sum1/2;
long q=sum3/2;
if(sum>=p) {
System.out.println("LIVE");
}
else {
System.out.println("DEAD");
}
if(sum2>=q) {
System.out.println("LIVE");
}
else {
System.out.println("DEAD");
}
sc.close();
}
}
| Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | d0c10322375530cd9166699b21710fee | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.Scanner;
public class SystemniyAdministrator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int sumAok = 0;
int sumAfail = 0;
int sumBok = 0;
int sumBfail = 0;
for (int i = 0; i < n; i++) {
int serv = scanner.nextInt();
if (serv == 1) {
sumAok += scanner.nextInt();
sumAfail += scanner.nextInt();
} else {
sumBok += scanner.nextInt();
sumBfail += scanner.nextInt();
}
}
if (sumAok >= sumAfail) {
System.out.println("LIVE");
} else {
System.out.println("DEAD");
}
if (sumBok >= sumBfail) {
System.out.println("LIVE");
} else {
System.out.println("DEAD");
}
}
}
| Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | 9c4005ba4368c3dd2ce0876e2d24c324 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.Scanner;
public class SystAdmin{
public static void main(String arg[]){
Scanner sc=new Scanner(System.in);
int s=sc.nextInt();
int a=0,b=0;
for(int i=0;i<s;i++){
int l=sc.nextInt();
int m=sc.nextInt();
int n=sc.nextInt();
if(l==1)
a=a+(m-n);
else
b=b+(m-n);
}
if(a>=0)
System.out.println("LIVE");
else
System.out.println("DEAD");
if(b>=0)
System.out.println("LIVE");
else
System.out.println("DEAD");
}
} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | bee4c6548a92dddf9789b0a78e50532b | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class test2 {
public static void main(String[] args) throws IOException {
int numA=0;
int sumAX=0;
int sumBX=0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
for(int i=0; i<n; i++){
StringTokenizer st = new StringTokenizer(br.readLine());
int p = Integer.parseInt(st.nextToken());
int x = Integer.parseInt(st.nextToken());
if(p==1){
numA=numA+1;
sumAX+=x;
} else {
sumBX+=x;
}
}
if(sumAX>=(numA*5)){
System.out.println("LIVE");
} else {
System.out.println("DEAD");
}
if(sumBX>=(n-numA)*5){
System.out.println("LIVE");
}else {
System.out.println("DEAD");
}
}
}
| Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | c6a1393464e1d83cbe5ba6566ee9e6df | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.io.*;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(System.in);
short n = in.nextShort();
byte t;
short a = 0,
b = 0;
int suma = 0,
sumb = 0;
while (n-- != 0){
if (in.nextShort() == 1){
a++;
suma += in.nextShort();
in.nextShort();
}else{
b++;
sumb += in.nextShort();
in.nextShort();
}
}
System.out.println(suma >= a*5 ? "LIVE" : "DEAD");
System.out.println(sumb >= b*5 ? "LIVE" : "DEAD");
}
}
| Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | f73a10108503df54986419addf164df1 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.Scanner;
public class A0245_System {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int counta = 0, suma = 0;
int countb = 0, sumb = 0;
for (int i = 0; i < n; i++) {
int t = scan.nextInt();
int x = scan.nextInt(), y = scan.nextInt();
if (t == 1) {
counta += x;
suma += x + y;
} else {
countb += x;
sumb += x + y;
}
}
System.out.println(counta * 2 >= suma ? "LIVE" : "DEAD");
System.out.println(countb * 2 >= sumb ? "LIVE" : "DEAD");
}
}
| Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | 7a10c5a01a238eb4bd5d6055f5c04dbf | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String... args) {
Scanner in = new Scanner(System.in);
StringBuilder sb = new StringBuilder();
int n = in.nextInt();
int x1=0,y1=0,x2=0,y2=0;
while(n--!=0){
int s = in.nextInt();
if(s==1){
x1+= in.nextInt();
y1+= in.nextInt();
}
else{
x2+= in.nextInt();
y2+= in.nextInt();
}
}
if(x1 >= (x1+y1)/2) sb.append("LIVE \n");
else sb.append("DEAD \n");
if(x2 >= (x2+y2)/2) sb.append("LIVE \n");
else sb.append("DEAD \n");
System.out.println(sb);
}
} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | c0ecd3cf8288acb2648638123abfac59 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.*;
import java.io.*;
public class CF254A
{
public static void main(String[] args) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int x1 = 0;
int y1 = 0;
int x2 = 0;
int y2 = 0;
while(n-- > 0)
{
StringTokenizer st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
if(a == 1)
{
x1 += Integer.parseInt(st.nextToken());
y1 += Integer.parseInt(st.nextToken());
}
if(a == 2)
{
x2 += Integer.parseInt(st.nextToken());
y2 += Integer.parseInt(st.nextToken());
}
}
String s1 = "";
String s2 = "";
if(x1 >= y1) s1 = "LIVE";
else s1 = "DEAD";
if(x2 >= y2) s2 = "LIVE";
else s2 = "DEAD";
System.out.println(s1);
System.out.println(s2);
}
} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | a3a94b57efad558749ab09c9708c5fe9 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.Scanner;
import java.util.stream.Stream;
public class SystemAdministrator {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
sc.nextLine();
int ax=0,ay=0,bx=0,by=0;
for (int i = 0; i < n; i++) {
int[] line= Stream.of(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
if(line[0]==1){ax+=line[1];ay+=line[2];}
else{bx+=line[1];by+=line[2];}
}
if(ax>=ay) System.out.println("LIVE");
else System.out.println("DEAD");
if(bx>=by) System.out.println("LIVE");
else System.out.println("DEAD");
}
} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | 1c45237f84eebf4b5b34a386c540e10e | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes |
import java.util.*;
public class P245A {
public static void main(String [] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int [] results = new int[2];
for (int i = 0; i < n; i++) {
int t = in.nextInt();
int x = in.nextInt();
int y = in.nextInt();
results[t-1] += x - y;
}
for (int i = 0; i < 2; i++) {
if (results[i] >= 0) System.out.println("LIVE");
else System.out.println("DEAD");
}
in.close();
}
} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | 8fcaff9df0ceb81537e25381b7bdb42c | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.*;
public class shapes {
public static void main(String[]args) {
Scanner a=new Scanner(System.in);
int x=a.nextInt();
int[][]arr=new int[x][3];
for(int i=0;i<x;i++) {
for(int j=0;j<3;j++) {
arr[i][j]=a.nextInt();
}
}
int a1=0;
int valid1=0;
int b1=0;
int valid2=0;
for(int i=0;i<x;i++) {
if(arr[i][0]==1) {
a1+=10;
valid1+=arr[i][1];
}
if(arr[i][0]==2) {
b1+=10;
valid2+=arr[i][1];
}
}
if(a1/(double)valid1<=2)
System.out.println("LIVE");
else
System.out.println("DEAD");
if(b1/(double)valid2<=2)
System.out.println("LIVE");
else
System.out.println("DEAD");
}
}
| Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | d2d3482baf096837de372b4f0376b3b7 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.*;
public class Solution
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int ax=0,ay=0,bx=0,by=0;
for(int i=0;i<n;i++)
{
int server=sc.nextInt();
if(server==1)
{
ax+=sc.nextInt();
ay+=sc.nextInt();
}
else
{
bx+=sc.nextInt();
by+=sc.nextInt();
}
}
if(ax>=ay)
System.out.println("LIVE");
else
System.out.println("DEAD");
if(bx>=by)
System.out.println("LIVE");
else
System.out.println("DEAD");
}
} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | 349cc257720d0de2ca5b540d81a4160a | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.Scanner;
public class A245 {
int N, A, B, x, y;
void go(Scanner s) {
N = s.nextInt();
while(N --> 0) {
if(s.nextInt() == 1) {
A += 10; x += s.nextInt(); s.next();
} else {
B += 10; y += s.nextInt(); s.next();
}
}
System.out.println(2 * x >= A ? "LIVE" : "DEAD");
System.out.println(2 * y >= B ? "LIVE" : "DEAD");
}
public static void main(String[] args) { new A245().go(new Scanner(System.in)); }
}
| Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | a6490e97eead788dab0c39cb92a15495 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.io.IOException;
import java.util.Scanner;
public class Solutions {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int xa = 0;
int xb = 0;
int cnta = 0;
int cntb = 0;
for (int i = 0; i < n; i++) {
int t = sc.nextInt();
int x = sc.nextInt();
int y = sc.nextInt();
if(t == 1) {
xa += x;
cnta++;
}else {
xb += x;
cntb++;
}
}
if(xa * 2 >= cnta * 10) {
System.out.println("LIVE");
}else {
System.out.println("DEAD");
}
if(xb * 2 >= cntb * 10) {
System.out.println("LIVE");
}else {
System.out.println("DEAD");
}
sc.close();
}
}
| Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | 6bdb637e6da1f1d67e8a805064a6d1d1 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.io.*;
public class Trans {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(bf.readLine());
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int aa=0;
int ad=0;
int ba=0;
int bd=0;
for (int i = 0; i < n; i++) {
String []arr=bf.readLine().split(" ");
int server=Integer.parseInt(arr[0]);
int suc=Integer.parseInt(arr[1]);
int ded=Integer.parseInt(arr[2]);
if(server==1){
aa+=suc;
ad+=ded;
}
else if(server==2){
ba+=suc;
bd+=ded;
}
}
pw.write((aa>=ad?"LIVE":"DEAD")+"\n");
pw.write((ba>=bd?"LIVE":"DEAD")+"\n");
pw.flush();
}
} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | 32107fd9c0372ba336690ded525bcd2d | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.*;
public class SystemAdministrator{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int ra = 0;
int rb = 0;
int la = 0;
int lb=0;
for(int i =0;i<n;i++){
int count = 0;
int t= sc.nextInt();
int a = sc.nextInt();
int b = sc.nextInt();
if(t==1){
ra+=a;
la+=b;
}
else{
rb+=a;
lb+=b;
}
}
if(ra>=la){
System.out.println("LIVE");
}
else{
System.out.println("DEAD");
}
if(rb>=lb){
System.out.println("LIVE");
}
else{
System.out.println("DEAD");
}
}
} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | e24ae3b033d45198ac388fb517f73ec9 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.io.IOException;
import java.util.Scanner;
public class jakb {
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(System.in);
int n=scanner.nextInt();
int [] aa=new int[2];
int counta=0;
int countb=0;
int [] bb=new int[2];
for (int i = 0; i < n; i++) {
int b=scanner.nextInt();
if(b==1){
aa[0]+=scanner.nextInt();
aa[1]+=scanner.nextInt();
}
if(b==2){
bb[0]+=scanner.nextInt();
bb[1]+=scanner.nextInt();
}
}
if(aa[0]>=aa[1])
System.out.println("LIVE");
else System.out.println("DEAD");
if(bb[0]>=bb[1])
System.out.println("LIVE");
else System.out.println("DEAD");
}
} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | ecbdc2b41eef516e2bc70adffa87c392 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.*;
public class Prog245A{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
short n=sc.nextShort();
int ax=0;
int bx=0;
int ay=0;
int by=0;
for (short i=1;i<=n;i++){
int t=sc.nextInt();
if(t==1){
ax=ax+sc.nextInt();
ay=ay+sc.nextInt();
}
else if(t==2){
bx=bx+sc.nextInt();
by=by+sc.nextInt();
}
}
if(ax>=ay){
System.out.println("LIVE");
}
else{
System.out.println("DEAD");
}
if(bx>=by){
System.out.println("LIVE");
}
else{
System.out.println("DEAD");
}
}
} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | c12f6ad81658f6f0f37e71be6849463d | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class Abood2C {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = sc.nextInt();
int aR = 0;
int aL = 0;
int bR = 0;
int bL = 0;
for (int i = 0; i < n; i++) {
if(sc.nextInt() == 1) {
aR += sc.nextInt();
aL += sc.nextInt();
}else {
bR += sc.nextInt();
bL += sc.nextInt();
}
}
System.out.println(aR >= aL ? "LIVE" : "DEAD");
System.out.println(bR >= bL ? "LIVE" : "DEAD");
out.flush();
}
static class Scanner
{
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));}
public String next() throws IOException
{
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {return Integer.parseInt(next());}
public long nextLong() throws IOException {return Long.parseLong(next());}
public String nextLine() throws IOException {return br.readLine();}
public double nextDouble() throws IOException
{
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if(x.charAt(0) == '-')
{
neg = true;
start++;
}
for(int i = start; i < x.length(); i++)
if(x.charAt(i) == '.')
{
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
}
else
{
sb.append(x.charAt(i));
if(dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg?-1:1);
}
public boolean ready() throws IOException {return br.ready();}
}
} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output | |
PASSED | 5694130b15f9b585950bb5191d824552 | train_002.jsonl | 1353339000 | Polycarpus is a system administrator. There are two servers under his strict guidance β a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (xβ+βyβ=β10;Β x,βyββ₯β0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. | 256 megabytes | import java.util.*;
public class SystemAdministrator{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
double s1 = 0;
double r1 = 0;
double s2 = 0;
double r2 = 0;
for(int i=0; i<n; i++){
int s = scan.nextInt();
if(s==1){
s1 += scan.nextDouble();
r1 += scan.nextDouble();
}else{
s2 += scan.nextDouble();
r2 += scan.nextDouble();
}
}
System.out.println(s1/(s1+r1)>=0.5?"LIVE":"DEAD");
System.out.println(s2/(s2+r2)>=0.5?"LIVE":"DEAD");
scan.close();
}
} | Java | ["2\n1 5 5\n2 6 4", "3\n1 0 10\n2 0 10\n1 10 0"] | 2 seconds | ["LIVE\nLIVE", "LIVE\nDEAD"] | NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network. | Java 8 | standard input | [
"implementation"
] | 1d8870a705036b9820227309d74dd1e8 | The first line contains a single integer n (2ββ€βnββ€β1000) β the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers β the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1ββ€βtiββ€β2;Β xi,βyiββ₯β0;Β xiβ+βyiβ=β10). If tiβ=β1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. | 800 | In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server b in the similar format. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.