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 | cb9821750b0471e5fbd6693a81c54e30 | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes | import java.util.Scanner;
public class main{
public static void main(String[] args){
Scanner leer1 = new Scanner(System.in);
int n = leer1.nextInt();
String number = leer1.next();
if(n%2==0){
for(int i=0;i<n;i++){
System.out.print(number.charAt(i));
if(i%2!=0 && i!=n-1){
System.out.print('-');
}
}
System.out.print('\n');
}
else {
for(int i=0;i<n-3;i++){
System.out.print(number.charAt(i));
if(i%2!=0){
System.out.print('-');
}
}
for(int i=n-3;i<n;i++){
System.out.print(number.charAt(i));
}
System.out.print('\n');
}
}
}
| Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | 6209f0b36a92305d72da2b7ce2a32935 | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.StringTokenizer;
public class MartesD
{
static class Scanner
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public String nextLine()
{
try
{
return br.readLine();
}
catch(Exception e)
{
throw(new RuntimeException());
}
}
public String next()
{
while(!st.hasMoreTokens())
{
String l = nextLine();
if(l == null)
return null;
st = new StringTokenizer(l);
}
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 int[] nextIntArray(int n)
{
int[] res = new int[n];
for(int i = 0; i < res.length; i++)
res[i] = nextInt();
return res;
}
public long[] nextLongArray(int n)
{
long[] res = new long[n];
for(int i = 0; i < res.length; i++)
res[i] = nextLong();
return res;
}
public double[] nextDoubleArray(int n)
{
double[] res = new double[n];
for(int i = 0; i < res.length; i++)
res[i] = nextDouble();
return res;
}
public void sortIntArray(int[] array)
{
Integer[] vals = new Integer[array.length];
for(int i = 0; i < array.length; i++)
vals[i] = array[i];
Arrays.sort(vals);
for(int i = 0; i < array.length; i++)
array[i] = vals[i];
}
public void sortLongArray(long[] array)
{
Long[] vals = new Long[array.length];
for(int i = 0; i < array.length; i++)
vals[i] = array[i];
Arrays.sort(vals);
for(int i = 0; i < array.length; i++)
array[i] = vals[i];
}
public void sortDoubleArray(double[] array)
{
Double[] vals = new Double[array.length];
for(int i = 0; i < array.length; i++)
vals[i] = array[i];
Arrays.sort(vals);
for(int i = 0; i < array.length; i++)
array[i] = vals[i];
}
public String[] nextStringArray(int n)
{
String[] vals = new String[n];
for(int i = 0; i < n; i++)
vals[i] = next();
return vals;
}
public Integer nextInteger()
{
String s = next();
if(s == null)
return null;
return Integer.parseInt(s);
}
public int[][] nextIntMatrix(int n, int m)
{
int[][] ans = new int[n][];
for(int i = 0; i < n; i++)
ans[i] = nextIntArray(m);
return ans;
}
public char[][] nextGrid(int r)
{
char[][] grid = new char[r][];
for(int i = 0; i < r; i++)
grid[i] = next().toCharArray();
return grid;
}
public static <T> T fill(T arreglo, int val)
{
if(arreglo instanceof Object[])
{
Object[] a = (Object[]) arreglo;
for(Object x : a)
fill(x, val);
}
else if(arreglo instanceof int[])
Arrays.fill((int[]) arreglo, val);
else if(arreglo instanceof double[])
Arrays.fill((double[]) arreglo, val);
else if(arreglo instanceof long[])
Arrays.fill((long[]) arreglo, val);
return arreglo;
}
<T> T[] nextObjectArray(Class <T> clazz, int size)
{
@SuppressWarnings("unchecked")
T[] result = (T[]) java.lang.reflect.Array.newInstance(clazz, size);
for(int c = 0; c < 3; c++)
{
Constructor <T> constructor;
try
{
if(c == 0)
constructor = clazz.getDeclaredConstructor(Scanner.class, Integer.TYPE);
else if(c == 1)
constructor = clazz.getDeclaredConstructor(Scanner.class);
else
constructor = clazz.getDeclaredConstructor();
}
catch(Exception e)
{
continue;
}
try
{
for(int i = 0; i < result.length; i++)
{
if(c == 0)
result[i] = constructor.newInstance(this, i);
else if(c == 1)
result[i] = constructor.newInstance(this);
else
result[i] = constructor.newInstance();
}
}
catch(Exception e)
{
throw new RuntimeException(e);
}
return result;
}
throw new RuntimeException("Constructor not found");
}
public void printLine(int... vals)
{
if(vals.length == 0)
System.out.println();
else
{
System.out.print(vals[0]);
for(int i = 1; i < vals.length; i++)
System.out.print(" ".concat(String.valueOf(vals[i])));
System.out.println();
}
}
public void printLine(long... vals)
{
if(vals.length == 0)
System.out.println();
else
{
System.out.print(vals[0]);
for(int i = 1; i < vals.length; i++)
System.out.print(" ".concat(String.valueOf(vals[i])));
System.out.println();
}
}
public void printLine(double... vals)
{
if(vals.length == 0)
System.out.println();
else
{
System.out.print(vals[0]);
for(int i = 1; i < vals.length; i++)
System.out.print(" ".concat(String.valueOf(vals[i])));
System.out.println();
}
}
public void printLine(int prec, double... vals)
{
if(vals.length == 0)
System.out.println();
else
{
System.out.printf("%." + prec + "f", vals[0]);
for(int i = 1; i < vals.length; i++)
System.out.printf(" %." + prec + "f", vals[i]);
System.out.println();
}
}
public Collection <Integer> wrap(int[] as)
{
ArrayList <Integer> ans = new ArrayList <Integer> ();
for(int i : as)
ans.add(i);
return ans;
}
public int[] unwrap(Collection <Integer> collection)
{
int[] vals = new int[collection.size()];
int index = 0;
for(int i : collection) vals[index++] = i;
return vals;
}
}
public static void main(String[] args)
{
Scanner sc = new Scanner();
int n = sc.nextInt();
String entrada = sc.next();
String ans = "";
if(n == 2)
System.out.println(new String(entrada));
else
{
while(n > 4)
{
if(ans.length() != 0)
ans += "-";
ans += entrada.substring(0, 3);
entrada = entrada.substring(3);
n -= 3;
}
if(n == 4)
{
if(ans.length() != 0)
ans += "-";
ans += entrada.substring(0, 2);
ans += "-";
ans += entrada.substring(2, 4);
n = 0;
}
if(n > 0)
{
if(ans.length() != 0)
ans += "-";
ans += entrada;
}
System.out.println(ans);
}
}
} | Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | ee0bb6eb5d001effdbb1cd100c991339 | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = in.nextInt();
in.nextLine();
String phone = in.nextLine();
StringBuffer buff = new StringBuffer();
int count = 0;
for (int i = 0; i < n; ++i) {
if (count == 2 && i != n-1) {
buff.append('-');
count = 0;
}
buff.append(phone.charAt(i));
count++;
}
out.print(buff.toString());
out.flush();
}
}
| Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | 87ad433e77fa3b92d3b4ab255d41b4ff | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main
{
public static void main (String[] args) throws IOException
{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(isr);
int n=Integer.parseInt(in.readLine());
String s=in.readLine();
in.close();
if(n>3) {
if(n%2==0) {
System.out.println(numbEr(s));
return ;
}
else {
System.out.println(numbOr(s));
return ;
}
}
else System.out.println(s);
}
static String numbEr(String a) {
String S="";
int c=a.length()/2-1;
for(int i=0;i<a.length();i++) {
if(i!=0&&i%2!=0) {
S+=a.charAt(i);
if(c!=0) {
S+='-';
c--;
}
}
else S+=a.charAt(i);
}
return S;
}
static String numbOr(String a) {
String S=a.substring(0,2)+'-';
int c=(a.length()-3)/2-1;
for(int i=2;i<a.length();i++) {
if(i%2!=0) {
S+=a.charAt(i);
if(c!=0) {
S+='-';
c--;
}
}
else S+=a.charAt(i);
}
return S;
}
} | Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | 5dfd18e4b4755e8d23d49abfead296ab | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes | import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Stack;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt(), k = 0;
scanner.nextLine();
char [] values = scanner.nextLine().toCharArray();
boolean trueorfalse = true;
if(n%2!=0)
trueorfalse = false;
String ans = "";
if(!trueorfalse){
ans = values[0]+""+values[1]+""+values[2]+"-";
k = 3;
}
for(int i = k; i < n; i ++){
ans += values[i];
i++;
ans += values[i];
ans = ans.concat("-");
}
System.out.println(ans.substring(0, ans.length()-1));
}
} | Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | 992bd4e88097619d66c10f3a40f114ee | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes | import java.util.Scanner;
public class PhoneNumber {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int i=0, a=0;
int number=input.nextInt();
String phnumber=input.next();
if(number%2==0)
{
System.out.print( phnumber.substring(0, 2));
i=2;
}
else
{
System.out.printf( phnumber.substring(0, 3));
i=3;
}
for(;i<number;i+=2)
{
System.out.printf( "-"+phnumber.substring(i, i+2));
}
System.out.println();
}
} | Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | eb465b27ec14fde18cda67f1837f2762 | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class PhoneNumbers {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String currentline;
String[] lines = new String[2];
int n = 0;
while (((currentline = br.readLine()) != null)) {
lines[n++] = currentline;
}
n = Integer.parseInt(lines[0]);
String nums = lines[1];
// n = 549871;
// String nums = "1198733";
StringBuilder sb = new StringBuilder();
int count = 0;
if(nums.length()<4){
System.out.println(nums);
return;
}
for(int x = 0; x<nums.length();x++){
if(count++==2){
sb.append("-");
count = 0;
if(nums.length()-x-1==3)
count = 1;
}
sb.append(nums.charAt(x));
}
System.out.println(sb.toString());
}
}
| Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | ebe2e0fdb4586581d68bdc8e74effd14 | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Test3 {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
in.readLine();
String phoneNumber = in.readLine();
System.out.println(getDashedForm(phoneNumber));
}
public static String getDashedForm(String phoneNumber) {
if (phoneNumber.length() <= 3) {
return phoneNumber;
} else if (phoneNumber.length() % 2 == 0) {
String fst = phoneNumber.substring(0, 2);
return fst + "-" + getDashedForm(phoneNumber.substring(2));
} else {
String fst = phoneNumber.substring(0, 3);
return fst + "-" + getDashedForm(phoneNumber.substring(3));
}
}
} | Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | 9bdec0441ac0c47112e7d02d19a035b1 | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main (String args []){
Scanner input = new Scanner (System.in);
int n ;
String s ;
boolean flag = false ;
int counter = 0 ;
String s1 ="";
n = input.nextInt();
s = input.next();
if(n % 2 != 0){
int n1 = n-3 ;
while ( n1 / 2 != 0){
counter ++;
n1 = n1 -2 ;
}
if(counter % 2 != 0){
flag = true ;
}
n1 = n ;
for(int i = 0 ; i< n ; i++){
if( (i == n/2 - 1 || flag ) && n1 % 2 != 0){
for(int j = 0 ; j < 3 ; j++){
if(i < n ){
char c = s.charAt(i);
flag = false ;
n1 = n1 - 3 ;
s1 = s1 + c;
}
if(j == 2){
}
else{
i++;
}
}
}
else{
for(int j = 0 ; j < 2 ; j++){
if(i < n){
char c = s.charAt(i);
s1 = s1 + c;
}
if(j == 1 ){
}
else{
i++;
}
}
}
if(i == n-1 || i >= n){
}
else{
s1 = s1 + '-';
}
}
}
else if ( n % 2 == 0){
for(int i = 0 ; i< n ; i++){
for(int j = 0 ; j < 2 ; j++){
if( i < n){
char c = s.charAt(i);
s1 = s1 + c;
}
if(j == 1 ){
}
else{
i++;
}
}
if(i == n-1 || i >= n){
}
else{
s1 = s1 + '-';
}
}
}
System.out.println(s1);
}
} | Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | 4004c2ff4e06863e5531b255cf117994 | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes | import java.util.Scanner;
//problem3
public class Main {
public static void main (String args []){
Scanner input = new Scanner (System.in);
int n ;
String s ;
boolean flag = false ;
int counter = 0 ;
String s1 ="";
n = input.nextInt();
s = input.next();
if(n % 2 != 0){
int n1 = n-3 ;
while ( n1 / 2 != 0){
counter ++;
n1 = n1 -2 ;
}
if(counter % 2 != 0){
flag = true ;
}
n1 = n ;
for(int i = 0 ; i< n ; i++){
if( (i == n/2 - 1 || flag ) && n1 % 2 != 0){
for(int j = 0 ; j < 3 ; j++){
if(i < n ){
char c = s.charAt(i);
flag = false ;
n1 = n1 - 3 ;
s1 = s1 + c;
}
if(j == 2){
}
else{
i++;
}
}
}
else{
for(int j = 0 ; j < 2 ; j++){
if(i < n){
char c = s.charAt(i);
s1 = s1 + c;
}
if(j == 1 ){
}
else{
i++;
}
}
}
if(i == n-1 || i >= n){
}
else{
s1 = s1 + '-';
}
}
}
else if ( n % 2 == 0){
for(int i = 0 ; i< n ; i++){
for(int j = 0 ; j < 2 ; j++){
if( i < n){
char c = s.charAt(i);
s1 = s1 + c;
}
if(j == 1 ){
}
else{
i++;
}
}
if(i == n-1 || i >= n){
}
else{
s1 = s1 + '-';
}
}
}
System.out.println(s1);
}
} | Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | b03f3eb94c64cf35735b4a0ee34dc400 | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes | import java.util.Scanner;
public class B {
public static void main(String[] args) throws Exception{
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
String s = scan.next();
int a = s.length() % 2 < 1 ? 2 : 3;
for(int i = 0; i < s.length() - a; i+=2){
System.out.print(s.substring(i,i+2)+"-");
}
System.out.println(s.substring(s.length()-a,s.length()));
}
} | Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | 666b49591a3e909be9859a0d267b161f | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes |
import java.util.Scanner;
public class B25 {
public static void main (String args[]){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
char[] t =in.next().toCharArray();
StringBuffer sb = new StringBuffer("");
if(n%2==0){
for(int i = 0 ; i < n ;i+=2){
sb.append(t[i]+"");
sb.append(t[i+1]+"");
sb.append('-');
}
System.out.println(sb.substring(0,sb.length()-1));
}
else {
for(int i = 0 ; i < n-1 ;i+=2){
sb.append(t[i]+"");
sb.append(t[i+1]+"");
sb.append('-');
}
sb.replace(sb.length()-1, sb.length(), t[n-1]+"");
System.out.println(sb.toString());
}
}
}
| Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | ee185fa58c0d6f218fd761f9902c3572 | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes | import java.util.Scanner;
public class Phone_numbers {
public static void main(String args[]){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
String a = in.next();
if(n%2==0){
for(int i=0;i<n-1;i+=2){
System.out.print(a.charAt(i)+""+a.charAt(i+1));
if(i!=n-2)
System.out.print('-');
}
}else{
for(int i = 0 ; i < n-1 ; i+=2){
if(i/2+1!=n/2)
System.out.print(a.charAt(i)+""+a.charAt(i+1));
else{
System.out.println(a.charAt(i)+""+a.charAt(i+1)+""+a.charAt(i+2));
i++;
}
if(i!=n-2)
System.out.print('-');
}
}
}
}
| Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | baf759360d2c43db7bdbbc79a15d99c2 | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes | import java.io.*;
import java.util.*;
public class PhoneNumbers2 {
public static void main(String[] args) throws IOException {
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(f.readLine());
String str = f.readLine();
for (int i = 0; i < n/2-1; i++)
System.out.print(str.substring(2*i,2*i+2)+"-");
System.out.print(str.substring(2*(n/2-1),n));
}
} | Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | acb22ecd813a04794e51ae647894a3fe | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes | import java.util.*;
public class Solution {
static void parse(String num, int n) {
int begin = 0;
while (begin < n) {
System.out.print(num.substring(begin, begin + 2));
begin += 2;
if (begin != n)
System.out.print("-");
}
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
String num = scan.next();
if (n == 2 || n == 3)
System.out.print(num);
else {
if (n % 2 == 0)
parse(num, n);
else {
int begin = 0;
System.out.print(num.substring(begin, begin + 3) + "-");
num = num.substring(begin + 3);
n -= 3;
parse(num, n);
}
}
}
} | Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | 6c0e56f665f599992b5e323e752dfce8 | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes | import java.util.Scanner;
public class phones {
public static void main(String[] args) {
Scanner inp = new Scanner(System.in);
int len = inp.nextInt();
String num = inp.nextLine();
num = inp.nextLine();
if(num.length() % 2 ==0){
for(int i = 0 ; i < num.length() ;i+=2){
System.out.print(num.charAt(i)); System.out.print(num.charAt(i+1));
if(i != num.length() - 2 )System.out.print("-");
}
}
else {
System.out.print(num.charAt(0)); System.out.print(num.charAt(1)); System.out.print(num.charAt(2));
for(int i = 3 ; i < num.length() ; i+=2){
System.out.print("-");
System.out.print(num.charAt(i)); System.out.print(num.charAt(i+1));
}
}
}
} | Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | a3069cbe9aa8e7bfa638e93df50ad5a3 | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int n = input.nextInt();
String[] m = input.next().split("(?!^)");
for(int i = 0; i < n;i++){
System.out.print(m[i]);
if(i%2 == 1 && i < (n - (n%2) - 2)){
System.out.print("-");
}
}
}
} | Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | f8769ac6a9de717d8d805d4ddb4a722f | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes | import java.util.Scanner;
public class Phone_Numbers {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input=new Scanner(System.in);
int x=input.nextInt();
String number=input.next();
String s="";
while(number.length()>3){
s=s+number.substring(0, 2)+"-";
number=number.substring(2);
}
s=s+number;
System.out.println(s);
input.close();
}//main
}//class
| Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | ea4f7cdc982840305de2f7467be7430c | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes |
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[]args){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
String num = in.next();
if(n % 2 == 0){
for(int i=0 ; i<num.length() ; i+=2)
if(i == num.length()-2)
System.out.println(num.substring(i , i+2));
else
System.out.print(num.substring(i, i+2) + "-");
}
else{
if(num.length() == 3)
System.out.print(num.substring(0 , 3));
else
System.out.print(num.substring(0, 3) + "-");
for(int i=3 ; i<num.length() ; i+=2)
if(i == num.length()-2)
System.out.println(num.substring(i , i+2));
else
System.out.print(num.substring(i, i+2) + "-");
}
}
} | Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | 55c7fe73897f7f58711ff4807f05a886 | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes | import java.util.Scanner;
public class PhoneNumber {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
int n = scanner.nextInt();
String phoneNumber = scanner.next();
String dividedPhoneNumber = "";
if (n % 2 == 0) {
for (int i = 0; i < n; i++) {
dividedPhoneNumber += phoneNumber.charAt(i);
if (i % 2 != 0 && i != n - 1) {
dividedPhoneNumber += "-";
}
}
} else {
for (int i = 0; i < n - 3; i++) {
dividedPhoneNumber += phoneNumber.charAt(i);
if (i % 2 != 0 && i != n - 1) {
dividedPhoneNumber += "-";
}
}
dividedPhoneNumber += phoneNumber.charAt(n - 3)
+""+ phoneNumber.charAt(n - 2) +""+ phoneNumber.charAt(n - 1);
}
System.out.println(dividedPhoneNumber);
}
}
}
| Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | d20aad7e3dba4380c87f335cd912d9e6 | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
/**
*
* @author Ammar.Eliwat
*/
public class TEST {
public static void main(String[] args) throws IOException {
Scanner input = new Scanner(System.in);
// BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
// String str;
// while((str=buffer.readLine())!=null){
int n=input.nextInt();
String A=input.next();
if(n%2==0){
for(int i=0;i<A.length();i++){
System.out.print(A.charAt(i));
if(i%2!=0 && i!=A.length()-1){
System.out.print("-");
}
}
}
else{
for(int i=0;i<A.length()-3;i++){
System.out.print(A.charAt(i));
if(i%2!=0 && i!=A.length()-1){
System.out.print("-");
}
}
System.out.print(A.charAt(A.length()-3));
System.out.print(A.charAt(A.length()-2));
System.out.print(A.charAt(A.length()-1));
}
System.out.println();
}
} | Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | 1c00ac32784fbf4facd4d9863ffd13bd | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes |
import java.util.Scanner;
/**
** Created by Alik on 10/25/2015.
*/
public class Problem_25B {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int length = in.nextInt();
String dummy = in.nextLine();
String input = in.nextLine();
String result="";
if (length % 2 == 0){
for (int i = 0; i < length; i+=2) {
result += input.substring(i, i + 2) + "-";
}
}
else{
result += input.substring(0, 3) + "-";
for (int i = 3; i < length; i+=2) {
result += input.substring(i, i + 2) + "-";
}
}
System.out.print(result.substring(0,result.length()-1));
}
}
| Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | 63ee73e589dfa2e63c3f59655ec55afa | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes | import java.util.Scanner;
public class Main25B {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
String s = scanner.next();
String r = "";
if (n%2!=0)
n--;
for (int i = 0;i<n;i++){
r+=s.charAt(i);
if (i!=0&&i!=n-1&&i%2!=0)
r+='-';
}
for (int i=n;i<s.length();i++){
r+=s.charAt(i);
}
System.out.println(r);
}
}
| Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | c374eec71625a1b0fe4e5705dadfeb24 | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes | import java.util.*;
public class PhoneNumbers2{
public static void main(String[] Args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String s = sc.next();
for(int k = 0;k+3<n;k+=2){
System.out.print(s.substring(k,k+2)+"-");
}
System.out.println(s.substring(n-2-(n%2),n));
}
}
| Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | c263cb01367f1bb8a7ff28992e10f0bc | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes | //package codeforces;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Scanner;
public class Codeforces {
private void run() throws IOException {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String s = sc.next();
int a = 3;
if (n % 2 == 0) {
a = 2;
}
for (int i = 0; i < a; i++) {
System.out.print(s.charAt(i));
}
n -= a;
for (int i = 0; i < n / 2; i++) {
System.out.print("-");
for (int j = 0; j < 2; j++) {
System.out.print(s.charAt(a + 2 * i + j));
}
}
}
public static void main(String[] args) throws IOException {
Codeforces cf = new Codeforces();
cf.run();
}
}
class MyScanner {
private StreamTokenizer st;
public MyScanner(InputStream is) {
st = new StreamTokenizer(new BufferedReader(new InputStreamReader(is)));
}
public int nextInt() throws IOException {
st.nextToken();
return ((int) st.nval);
}
public String next() throws IOException {
st.nextToken();
return (st.sval);
}
}
| Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | eeb9b0d2f4ca0d2845067c623246e241 | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
public class Main4 {
public static void main(String args[]) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// Scanner in = new Scanner(System.in);
br.readLine();
String in = br.readLine();
for(int i = 0;i<in.length();i++){
System.out.print(in.charAt(i));
if(i+1<in.length() && (i+1)%2==0 && in.length()-i-1>1)
System.out.print("-");
}
}
} | Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | 77b87c070fee5a91b4b2529a238f13f6 | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes |
import java.util.*;
public class Practica_1 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
String ln = in.next();
int dos = 0;
String cdn = "";
if ((n & 1) > 0) {
int pos = -1;
while (true) {
if (n - 2 >= 2) {
n -= 2;
pos = n;
dos++;
} else {
break;
}
}
int rest = 0;
if (pos == -1) {
rest = 0;
} else {
rest = ln.length() - pos;
}
for (int i = 0; i < rest; i++) {
cdn += ln.charAt(i);
if ((i & 1) > 0) {
cdn += " ";
}
}
for (int i = rest; i < ln.length(); i++) {
cdn += ln.charAt(i);
}
} else {
for (int i = 0; i < ln.length(); i++) {
cdn += ln.charAt(i);
if ((i & 1) > 0) {
cdn += " ";
}
}
}
cdn = cdn.trim().replace(' ', '-');
System.out.println(cdn);
}
}
| Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | 622380bda63700bf4cf82806a836f3af | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
/**
*
* @author Ammar.Eliwat
*/
public class TEST {
public static void main(String[] args) throws IOException {
Scanner input = new Scanner(System.in);
// BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
// String str;
// while((str=buffer.readLine())!=null){
int n=input.nextInt();
String A=input.next();
if(n%2==0){
for(int i=0;i<A.length();i++){
System.out.print(A.charAt(i));
if(i%2!=0 && i!=A.length()-1){
System.out.print("-");
}
}
}
else{
for(int i=0;i<A.length()-3;i++){
System.out.print(A.charAt(i));
if(i%2!=0 && i!=A.length()-1){
System.out.print("-");
}
}
System.out.print(A.charAt(A.length()-3));
System.out.print(A.charAt(A.length()-2));
System.out.print(A.charAt(A.length()-1));
}
System.out.println();
}
} | Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | 22b1cbd180ef00477a0cc3b255d3fadd | train_001.jsonl | 1280761200 | Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits. | 256 megabytes | import java.io.*;
import java.util.*;
public class p25b
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println();
int n = sc.nextInt();
String str = sc.next();
String s = "";
String s1 = "-";
if(n%2==0)
{
int i;
for(i=0;i<n-2;i=i+2)
{
s += Character.toString(str.charAt(i));
s += Character.toString(str.charAt(i+1));
s += s1;
}
s += Character.toString(str.charAt(i));
s += Character.toString(str.charAt(i+1));
System.out.println(s);
}
else
{
int i;
for(i=0;i<n-3;i=i+2)
{
s += Character.toString(str.charAt(i));
s += Character.toString(str.charAt(i+1));
s += s1;
}
s += Character.toString(str.charAt(i));
s += Character.toString(str.charAt(i+1));
s += Character.toString(str.charAt(i+2));
System.out.println(s);
}
}
} | Java | ["6\n549871", "7\n1198733"] | 2 seconds | ["54-98-71", "11-987-33"] | null | Java 7 | standard input | [
"implementation"
] | 6f6859aabc1c9cbb9ee0d910064d87c2 | The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups. | 1,100 | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | standard output | |
PASSED | 4dbfe69b3cb56898e5fa6dea8570fc77 | train_001.jsonl | 1402673400 | The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the floor of the house, its mass is mi. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most x centimeter high jumps. When Om Nom eats a candy of mass y, he gets stronger and the height of his jump increases by y centimeters.What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.StringTokenizer;
public class Solution {
static InputReader in = new InputReader(System.in);
@SuppressWarnings("unchecked")
public static void main(String[] args) {
int n = in.nextInt();
int x = in.nextInt();
ArrayList<Candy> first = new ArrayList<Candy>();
ArrayList<Candy> second = new ArrayList<Candy>();
for (int i = 0; i < n; i++) {
if (in.nextInt() == 0) {
first.add(new Candy(in.nextInt(), in.nextInt()));
} else {
second.add(new Candy(in.nextInt(), in.nextInt()));
}
}
Collections.sort(first, new CandyComp());
Collections.sort(second, new CandyComp());
int res1 = solve((ArrayList<Candy>) first.clone(),
(ArrayList<Candy>) second.clone(), x, 0);
int res2 = solve((ArrayList<Candy>) first.clone(),
(ArrayList<Candy>) second.clone(), x, 1);
System.out.println(Math.max(res1, res2));
}
private static int solve(ArrayList<Candy> first, ArrayList<Candy> second,
int x, int start) {
int count = 0;
int jump = x;
while (true) {
if (start == 0) {
int maxMass = Integer.MIN_VALUE;
int maxIndex = -1;
boolean found = false;
for (int i = 0; i < first.size(); i++) {
if (first.get(i).height <= jump) {
if (first.get(i).mass > maxMass) {
maxMass = first.get(i).mass;
maxIndex = i;
found = true;
}
}
}
if (found) {
start = 1;
jump += maxMass;
count++;
first.remove(maxIndex);
} else {
break;
}
} else {
int maxMass = Integer.MIN_VALUE;
int maxIndex = -1;
boolean found = false;
for (int i = 0; i < second.size(); i++) {
if (second.get(i).height <= jump) {
if (second.get(i).mass > maxMass) {
maxMass = second.get(i).mass;
maxIndex = i;
found = true;
}
}
}
if (found) {
start = 0;
jump += maxMass;
count++;
second.remove(maxIndex);
} else {
break;
}
}
}
return count;
}
}
class CandyComp implements Comparator<Candy> {
@Override
public int compare(Candy s1, Candy s2) {
if (s1.mass > s2.mass) {
return -1;
} else if (s1.mass == s2.mass) {
return 0;
} else {
return 1;
}
}
}
class Candy {
int height, mass;
public Candy(int height, int mass) {
this.height = height;
this.mass = mass;
}
@Override
public String toString() {
return "[height=" + height + ", mass=" + mass + "]";
}
}
class InputReader {
private BufferedReader reader;
private StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public String readLine() {
try {
return reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public float nextFloat() {
return Float.parseFloat(next());
}
} | Java | ["5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5"] | 2 seconds | ["4"] | NoteOne of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4. | Java 7 | standard input | [
"greedy"
] | 6253f6217c58a66573b1ddc6962c372c | The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop. | 1,500 | Print a single integer — the maximum number of candies Om Nom can eat. | standard output | |
PASSED | af665b80c3efb98a7b1687bdcf734dd5 | train_001.jsonl | 1402673400 | The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the floor of the house, its mass is mi. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most x centimeter high jumps. When Om Nom eats a candy of mass y, he gets stronger and the height of his jump increases by y centimeters.What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)? | 256 megabytes |
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class TestA {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int x = in.nextInt();
ArrayList<Integer> arrT = new ArrayList<Integer>();
ArrayList<Integer> arrH = new ArrayList<Integer>();
ArrayList<Integer> arrM = new ArrayList<Integer>();
int count0 = 0;
int count1 = 0;
for(int i = 0; i < n; i++)
{
int t = in.nextInt();
if(t == 0)
{
count0++;
}
else
{
count1++;
}
arrT.add(t);
arrH.add(in.nextInt());
arrM.add(in.nextInt());
}
int startT;
if(count0 > count1)
{
startT = 0;
}
else
{
startT = 1;
}
int answer0 = checker((ArrayList<Integer>) arrT.clone(),(ArrayList<Integer>) arrH.clone(),(ArrayList<Integer>) arrM.clone(), x , n, 0);
int answer1 = checker((ArrayList<Integer>) arrT.clone(),(ArrayList<Integer>) arrH.clone(),(ArrayList<Integer>) arrM.clone(), x , n, 1);
System.out.println(answer0 > answer1 ? answer0 : answer1);
}
//из тех конфет которые Ом Ном может съесть масса у них должна быть максимальная
public static int checker(ArrayList<Integer> arrT , ArrayList<Integer> arrH, ArrayList<Integer> arrM, int x, int n, int startT)
{
boolean isChecked = true;
int answer = 0;
int maxM = 0;
int curMaxIndex = 0;
while(isChecked)
{
maxM = 0;
curMaxIndex = 0;
for(int i = 0; i < n; i++)
{
if(arrT.get(i) == startT)
{
if(arrH.get(i) <= x)
{
if(maxM < arrM.get(i))
{
maxM = arrM.get(i);
curMaxIndex = i;
}
}
}
}
if(maxM == 0)
{
isChecked = false;
break;
}
else
{
x += arrM.get(curMaxIndex);
n--;
arrT.remove(curMaxIndex);
arrH.remove(curMaxIndex);
arrM.remove(curMaxIndex);
answer++;
if(startT == 0)
{
startT = 1;
}
else
{
startT = 0;
}
}
}
return answer;
}
} | Java | ["5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5"] | 2 seconds | ["4"] | NoteOne of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4. | Java 7 | standard input | [
"greedy"
] | 6253f6217c58a66573b1ddc6962c372c | The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop. | 1,500 | Print a single integer — the maximum number of candies Om Nom can eat. | standard output | |
PASSED | 84ae7291a1d71e62d9990f2814afb494 | train_001.jsonl | 1402673400 | The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the floor of the house, its mass is mi. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most x centimeter high jumps. When Om Nom eats a candy of mass y, he gets stronger and the height of his jump increases by y centimeters.What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)? | 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.Stack;
import java.util.StringTokenizer;
public class Candy implements Comparable {
int height; int type; int mass;
public Candy(int t, int h, int m) {
height = h;
type = t;
mass = m;
}
public int compareTo(Object o) {
Candy cc = (Candy) o;
return height - cc.height;
}
static int n;
static int []t = new int[2001];
static int []h = new int[2001];
static int []m = new int [2001];
static Candy []c;
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
n = Integer.parseInt(st.nextToken());
int x = Integer.parseInt(st.nextToken());
c = new Candy[n];
for(int i = 0; i < n; i++) {
st = new StringTokenizer(br.readLine());
t[i] = Integer.parseInt(st.nextToken());
h[i] = Integer.parseInt(st.nextToken());
m[i] = Integer.parseInt(st.nextToken());
Candy z = new Candy(t[i], h[i], m[i]);
c[i] = z;
}
Arrays.sort(c);
Stack<Candy> candies = new Stack();
Stack<Candy> candies2 = new Stack();
for(int i = n-1; i >= 0; i--) {
candies.push(c[i]);
candies2.push(c[i]);
}
int o = x;
int type = 0;
int number = 0;
int number2 = 0;
int best = 0;
while(true) {
Stack<Candy> temp = new Stack();
best = 0;
Candy bestc = null;
while(!candies.isEmpty()) {
if(candies.peek().type==type)
temp.push(candies.pop());
else {
if (candies.peek().height<=x && candies.peek().mass>best) {
if(bestc!=null)
temp.push(bestc);
bestc = candies.pop();
best = bestc.mass;
}
else
temp.push(candies.pop());
}
}
while(!temp.isEmpty()) {
candies.push(temp.pop());
}
if(bestc!=null) {
number++;
x+=best;
type = bestc.type;
}
else
break;
}
type = 1;
x = o;
while(true) {
Stack<Candy> temp = new Stack();
best = 0;
Candy bestc = null;
while(!candies2.isEmpty()) {
if(candies2.peek().type==type)
temp.push(candies2.pop());
else {
if (candies2.peek().height<=x && candies2.peek().mass>best) {
if(bestc!=null)
temp.push(bestc);
bestc = candies2.pop();
best = bestc.mass;
}
else
temp.push(candies2.pop());
}
}
while(!temp.isEmpty()) {
candies2.push(temp.pop());
}
if(bestc!=null) {
number2++;
x+=best;
type = bestc.type;
}
else
break;
}
System.out.println(Math.max(number, number2));
}
}
| Java | ["5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5"] | 2 seconds | ["4"] | NoteOne of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4. | Java 7 | standard input | [
"greedy"
] | 6253f6217c58a66573b1ddc6962c372c | The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop. | 1,500 | Print a single integer — the maximum number of candies Om Nom can eat. | standard output | |
PASSED | 4c8818707e3912108921a6da1b092468 | train_001.jsonl | 1402673400 | The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the floor of the house, its mass is mi. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most x centimeter high jumps. When Om Nom eats a candy of mass y, he gets stronger and the height of his jump increases by y centimeters.What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class A {
BufferedReader reader;
StringTokenizer tokenizer;
PrintWriter out;
public void solve() throws IOException {
int N = nextInt();
int X = nextInt();
final ArrayList<int[]> C1 = new ArrayList<int[]>();
final ArrayList<int[]> C2 = new ArrayList<int[]>();
for (int i = 0; i < N; i++) {
int T = nextInt();
int H = nextInt();
int M = nextInt();
if (T == 0) {
C1.add(new int[] {H, M});
} else {
C2.add(new int[] {H, M});
}
}
Comparator<int[]> cmp = new Comparator<int[]>() {
@Override
public int compare(int[] a, int[] b) {
return a[0] - b[0];
}
};
Collections.sort(C1, cmp);
Collections.sort(C2, cmp);
int ans1 = go(1, X, C1, C2);
int ans2 = go(2, X, C1, C2);
out.println(Math.max(ans1, ans2));
}
public int go(int last, int X, ArrayList<int[]> C1, ArrayList<int[]> C2) {
int cur1 = 0;
int cur2 = 0;
boolean[] ate1 = new boolean[C1.size()];
boolean[] ate2 = new boolean[C2.size()];
int ans = 0;
while (true) {
while (cur1 < C1.size() && C1.get(cur1)[0] <= X) cur1++;
while (cur2 < C2.size() && C2.get(cur2)[0] <= X) cur2++;
int best_c = -1;
int best_m = -1;
int best_i = -1;
if (last != 1) {
for (int i = 0; i < cur1; i++) {
if (ate1[i]) continue;
if (C1.get(i)[1] > best_m) {
best_c = 1;
best_i = i;
best_m = C1.get(i)[1];
}
}
}
if (last != 2) {
for (int i = 0; i < cur2; i++) {
if (ate2[i]) continue;
if (C2.get(i)[1] > best_m) {
best_c = 2;
best_i = i;
best_m = C2.get(i)[1];
}
}
}
if (best_c == -1) break;
if (best_c == 1) {
ate1[best_i] = true;
last = 1;
X += C1.get(best_i)[1];
} else if (best_c == 2) {
ate2[best_i] = true;
last = 2;
X += C2.get(best_i)[1];
}
ans++;
}
return ans;
}
/**
* @param args
*/
public static void main(String[] args) {
new A().run();
}
public void run() {
try {
reader = new BufferedReader(new InputStreamReader(System.in));
tokenizer = null;
out = new PrintWriter(System.out);
solve();
reader.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
}
| Java | ["5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5"] | 2 seconds | ["4"] | NoteOne of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4. | Java 7 | standard input | [
"greedy"
] | 6253f6217c58a66573b1ddc6962c372c | The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop. | 1,500 | Print a single integer — the maximum number of candies Om Nom can eat. | standard output | |
PASSED | ee286f5da0edfa83917b3f18e69022d3 | train_001.jsonl | 1402673400 | The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the floor of the house, its mass is mi. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most x centimeter high jumps. When Om Nom eats a candy of mass y, he gets stronger and the height of his jump increases by y centimeters.What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)? | 256 megabytes | import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;
//import java.util.Set;
public class A436 {
static int type[] = new int[2000];
static int height[] = new int[2000];
static int mass[] = new int[2000];
static int lines;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
lines = sc.nextInt();
int reach = sc.nextInt();
for(int i = 0; i<lines; i++){
type[i] = sc.nextInt();
height[i] = sc.nextInt();
mass[i]= sc.nextInt();
}
int candies = Math.max(eat(1, reach), eat(0, reach));
System.out.println(candies);
}
public static int eat(int t, int reach){
int weight = 0;
int position=0;
for(int i = 0; i<lines; i++){
if(type[i] == t && height[i] <= reach && weight < mass[i]){
weight = mass[i];
position = i;
}
}
if(weight == 0){
return 0;
}
mass[position]= 0;
int newType;
if(t == 0){
newType = 1;
}else {
newType = 0;
}
int answer = eat(newType, reach + weight);
mass[position]= weight; //So it doesn't change the actual array
return answer + 1;
}
}
| Java | ["5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5"] | 2 seconds | ["4"] | NoteOne of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4. | Java 7 | standard input | [
"greedy"
] | 6253f6217c58a66573b1ddc6962c372c | The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop. | 1,500 | Print a single integer — the maximum number of candies Om Nom can eat. | standard output | |
PASSED | b8dd5e21c22ade0861ba1632c43ed753 | train_001.jsonl | 1402673400 | The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the floor of the house, its mass is mi. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most x centimeter high jumps. When Om Nom eats a candy of mass y, he gets stronger and the height of his jump increases by y centimeters.What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)? | 256 megabytes | import java.util.*;
public class ProblemA
{
static int n;
static int start_height;
static int t[];
static int h[];
static int m[];
static int table[][];
public static void readInput()
{
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
start_height = sc.nextInt();
t = new int[n];
h = new int[n];
m = new int[n];
table = new int[n][3];
for (int i = 0; i < n; i++)
{
t[i] = sc.nextInt();
h[i] = sc.nextInt();
m[i] = sc.nextInt();
table[i][0] = t[i];
table[i][1] = h[i];
table[i][2] = m[i];
}
sc.close();
Arrays.sort(table, new Comparator<int[]>() {
@Override
public int compare(final int[] entry1, final int[] entry2) {
return entry2[2] - entry1[2];
}
});
}
public static int greedy(int start_type)
{
boolean seen[] = new boolean[n];
int height = start_height;
boolean changed = true;
int count = 0;
int type = start_type;
while (changed)
{
changed = false;
for (int i = 0; i < n; i++)
{
if (!seen[i] && type == table[i][0] && height >= table[i][1])
{
count++;
height += table[i][2];
changed = true;
seen[i] = true;
if (type == 0)
{
type = 1;
}
else
{
type = 0;
}
break;
}
}
}
return count;
}
/* Psuedo code
*
* Question - assuming without types:
* Eat candy from lowest to highest
*
* Question with types:
*
* Run algorithm starting with 0.
* Eat candy with highest mass with suitable height
*
* Run algorithm starting from 1.
* Eat candy with highest mass with suitable height
* */
public static void main(String[] args)
{
readInput();
// for (int i = 0; i < n; i++)
// {
// System.out.printf("%d %d %d\n", table[i][0], table[i][1], table[i][2]);
// }
int start0 = greedy(0);
int start1 = greedy(1);
if (start0 > start1)
{
System.out.println(start0);
}
else
{
System.out.println(start1);
}
}
}
| Java | ["5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5"] | 2 seconds | ["4"] | NoteOne of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4. | Java 7 | standard input | [
"greedy"
] | 6253f6217c58a66573b1ddc6962c372c | The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop. | 1,500 | Print a single integer — the maximum number of candies Om Nom can eat. | standard output | |
PASSED | d1a99568492489332b96963996161dd0 | train_001.jsonl | 1402673400 | The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the floor of the house, its mass is mi. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most x centimeter high jumps. When Om Nom eats a candy of mass y, he gets stronger and the height of his jump increases by y centimeters.What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)? | 256 megabytes | import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Vadim
*/
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);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
}
class TaskA {
class Candy {
int t;
int h;
int m;
boolean eaten;
Candy(int t, int h, int m) {
this.t = t;
this.h = h;
this.m = m;
}
}
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.ni();
int x = in.ni();
Candy c [] = new Candy[n];
for (int i = 0; i < n; i++) {
int t = in.ni();
int h = in.ni();
int m = in.ni();
c[i] = new Candy(t, h, m);
}
Arrays.sort(c, new Comparator<Candy>() {
@Override
public int compare(Candy o1, Candy o2) {
if(o1.m == o2.m) {
return o1.h - o2.h;
}
return o2.m-o1.m;
}
});
int ans = calcCandies(c, x, 0);
for (Candy candy : c) {
candy.eaten = false;
}
ans = Math.max(ans, calcCandies(c, x, 1));
out.println(ans);
}
private int calcCandies(Candy[] c, int xx, int tt) {
int ans = 0;
while(true) {
boolean found = false;
for (Candy candy : c) {
if(!candy.eaten && candy.t == tt && candy.h <= xx) {
tt = (tt==0)?1:0;
xx += candy.m;
candy.eaten = true;
found = true;
ans ++;
break;
}
}
if(!found) {
break;
}
}
return ans;
}
}
class InputReader extends BufferedReader {
public InputReader(InputStream st) {
super(new InputStreamReader(st));
}
public int nextInt() {
try {
int c = read();
while (isWhiteSpace(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int ret = 0;
while (c >= 0 && !isWhiteSpace(c)) {
if (c < '0' || c > '9') {
throw new RuntimeException();
}
ret = ret * 10 + c - '0';
c = read();
}
return ret * sgn;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public int ni() {
return nextInt();
}
public String readLine() {
try {
return super.readLine();
} catch (IOException e) {
return null;
}
}
static boolean isWhiteSpace(int c) {
return c >= 0 && c <= 32;
}
}
| Java | ["5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5"] | 2 seconds | ["4"] | NoteOne of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4. | Java 7 | standard input | [
"greedy"
] | 6253f6217c58a66573b1ddc6962c372c | The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop. | 1,500 | Print a single integer — the maximum number of candies Om Nom can eat. | standard output | |
PASSED | e11419682e6c5372ac48fa6fe41e7fb8 | train_001.jsonl | 1402673400 | The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the floor of the house, its mass is mi. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most x centimeter high jumps. When Om Nom eats a candy of mass y, he gets stronger and the height of his jump increases by y centimeters.What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)? | 256 megabytes | import java.io.*;
import java.util.*;
public class FeedWithCandy4 {
static public class FastScanner {
java.io.BufferedReader br;
StringTokenizer st;
public FastScanner() {
init();
}
public FastScanner(String name) {
init(name);
}
public FastScanner(boolean isOnlineJudge) {
if (!isOnlineJudge || System.getProperty("ONLINE_JUDGE") != null) {
init();
} else {
init("input.txt");
}
}
private void init() {
br = new java.io.BufferedReader(new java.io.InputStreamReader(
System.in));
}
private void init(String name) {
try {
br = new java.io.BufferedReader(new java.io.FileReader(name));
} catch (java.io.FileNotFoundException e) {
e.printStackTrace();
}
}
public String nextToken() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (java.io.IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(nextToken());
}
public long nextLong() {
return Long.parseLong(nextToken());
}
public double nextDouble() {
return Double.parseDouble(nextToken());
}
}
static class Candy{
int t;
int h;
int m;
public Candy(int t, int h, int m) {
super();
this.t = t;
this.h = h;
this.m = m;
}
@Override
public String toString() {
return "Candy [t=" + t + ", h=" + h + ", m=" + m + "]";
}
}
static Comparator<Candy> comparator = new Comparator<FeedWithCandy4.Candy>() {
@Override
public int compare(Candy c1, Candy c2) {
int diff = c2.m - c1.m;
if(diff == 0){
return c1.h - c2.h;
}
return diff;
}
};
public static void main(String[] args) throws IOException {
// FastScanner s = new FastScanner("input.txt");
FastScanner s = new FastScanner();
int N = s.nextInt();
int X = s.nextInt();
List<Candy> list = new ArrayList<FeedWithCandy4.Candy>();
for (int i = 0; i < N; i++) {
list.add(new Candy(s.nextInt(),s.nextInt(),s.nextInt()));
}
Collections.sort(list,comparator);
// _(list);
int ans = 0;
for (int t = 0; t <= 1; t++) {
int step = 0;
List<Candy> tmp = new ArrayList<Candy>(list);
int H = X;
int curT = t;
while(!tmp.isEmpty()){
int size = tmp.size();
boolean b = false;
for (int i = 0; i < size; i++) {
Candy c = tmp.get(i);
if(c.h <= H && curT != c.t){
H += c.m;
step++;
tmp.remove(i);
curT = c.t;
b = true;
break;
}
}
if(!b){
break;
}
}
// _("step",step);
ans = Math.max(ans, step);
}
System.out.println(ans);
}
static void _(Object... objs) {
System.err.println(Arrays.deepToString(objs));
}
}
| Java | ["5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5"] | 2 seconds | ["4"] | NoteOne of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4. | Java 7 | standard input | [
"greedy"
] | 6253f6217c58a66573b1ddc6962c372c | The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop. | 1,500 | Print a single integer — the maximum number of candies Om Nom can eat. | standard output | |
PASSED | df499832ad7b7cc61ea04c0f6f89cec6 | train_001.jsonl | 1402673400 | The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the floor of the house, its mass is mi. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most x centimeter high jumps. When Om Nom eats a candy of mass y, he gets stronger and the height of his jump increases by y centimeters.What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)? | 256 megabytes | import java.util.*;
import java.io.*;
public class Main implements Runnable {
public void solve() throws IOException {
int N = nextInt();
int W = nextInt();
int[] t = new int[N];
int[] h = new int[N];
int[] w = new int[N];
for(int i = 0; i < N; i++){
t[i] = nextInt();
h[i] = nextInt();
w[i] = nextInt();
}
int answer = 0;
for(int start = 0; start < 2; start++){
int power = W;
int now = start;
boolean[] was = new boolean[N];
int count = 0;
while(true){
int besti = -1;
for(int i = 0; i < N; i++){
if(!was[i] && t[i] == now && h[i] <= power && (besti == -1 || w[besti] < w[i])){
besti = i;
}
}
if(besti == -1) break;
power += w[besti];
was[besti] = true;
now = 1 - now;
count++;
}
answer = Math.max(answer, count);
}
System.out.println(answer);
}
//-----------------------------------------------------------
public static void main(String[] args) {
new Main().run();
}
public void print1Int(int[] a){
for(int i = 0; i < a.length; i++)
System.out.print(a[i] + " ");
System.out.println();
}
public void print2Int(int[][] a){
for(int i = 0; i < a.length; i++){
for(int j = 0; j < a[0].length; j++){
System.out.print(a[i][j] + " ");
}
System.out.println();
}
}
public void run() {
try {
in = new BufferedReader(new InputStreamReader(System.in));
tok = null;
solve();
in.close();
} catch (IOException e) {
System.exit(0);
}
}
public String nextToken() throws IOException {
while (tok == null || !tok.hasMoreTokens()) {
tok = new StringTokenizer(in.readLine());
}
return tok.nextToken();
}
public int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
public long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
public double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
BufferedReader in;
StringTokenizer tok;
} | Java | ["5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5"] | 2 seconds | ["4"] | NoteOne of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4. | Java 7 | standard input | [
"greedy"
] | 6253f6217c58a66573b1ddc6962c372c | The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop. | 1,500 | Print a single integer — the maximum number of candies Om Nom can eat. | standard output | |
PASSED | b82a515807b0975401624cd025d0b02c | train_001.jsonl | 1402673400 | The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the floor of the house, its mass is mi. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most x centimeter high jumps. When Om Nom eats a candy of mass y, he gets stronger and the height of his jump increases by y centimeters.What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)? | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.*;
public class Asecond implements Runnable {
void solve() {
int n = nextInt(), x = nextInt();
int[] t = new int[n], h = new int[n], m = new int[n];
for (int i = 0; i < n; i++) {
t[i] = nextInt();
h[i] = nextInt();
m[i] = nextInt();
}
int ans = 0;
for (int s = 0; s <= 1; s++) {
int type = s, cur = x, cnt = 0;
boolean[] used = new boolean[n];
while (true) {
int max = -1;
for (int i = 0; i < n; i++)
if (t[i] == type && h[i] <= cur && !used[i]) {
if (max == -1 || m[max] < m[i])
max = i;
}
if (max == -1)
break;
used[max] = true;
cur += m[max];
cnt++;
type = 1 - type;
}
ans = Math.max(ans, cnt);
}
print(ans);
}
public static void main(String[] args) throws IOException {
new Asecond().run();
}
Asecond() {
this.stream = System.in;
this.writer = new PrintWriter(System.out);
}
Asecond(String input, String output) throws IOException {
File inputFile = new File(input);
inputFile.createNewFile();
stream = new FileInputStream(inputFile);
File outputFile = new File(output);
outputFile.createNewFile();
writer = new PrintWriter(outputFile);
}
public void run() {
solve();
writer.close();
}
void halt() {
writer.close();
System.exit(0);
}
PrintWriter writer;;
void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
void println(Object... objects) {
print(objects);
writer.println();
}
void printArray(int[] array) {
for (int i = 0; i < array.length; i++) {
if (i != 0) writer.print(' ');
writer.print(array[i]);
}
writer.println();
}
void printArray(long[] array) {
for (int i = 0; i < array.length; i++) {
if (i != 0) writer.print(' ');
writer.print(array[i]);
}
writer.println();
}
void printMatrix(int[][] matrix) {
for (int i = 0; i < matrix.length; i++)
printArray(matrix[i]);
}
void printMatrix(long[][] matrix) {
for (int i = 0; i < matrix.length; i++)
printArray(matrix[i]);
}
/**
* Pure Egor's code is straight ahead.
*/
InputStream stream;
byte[] buf = new byte[1024];
int curChar, numChars;
int nextInt() {
int c = next();
while (isWhitespace(c))
c = next();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = next();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = next();
} while (!isWhitespace(c));
return res * sgn;
}
long nextLong() {
int c = next();
while (isWhitespace(c))
c = next();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = next();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = next();
} while (!isWhitespace(c));
return res * sgn;
}
double nextDouble() {
int c = next();
while (isWhitespace(c))
c = next();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = next();
}
double res = 0;
while (!isWhitespace(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 = next();
}
if (c == '.') {
c = next();
double m = 1;
while (!isWhitespace(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 = next();
}
}
return res * sgn;
}
BigInteger nextBigInteger() {
try {
return new BigInteger(nextString());
} catch (NumberFormatException e) {
throw new InputMismatchException();
}
}
int next() {
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++];
}
String nextString() {
int c = next();
while (isWhitespace(c))
c = next();
StringBuilder res = new StringBuilder();
do {
if (Character.isValidCodePoint(c))
res.appendCodePoint(c);
c = next();
} while (!isWhitespace(c));
return res.toString();
}
String nextLine() {
StringBuilder buf = new StringBuilder();
int c = next();
while (c != '\n' && c != -1) {
if (c != '\r')
buf.appendCodePoint(c);
c = next();
}
return buf.toString();
}
boolean EOF() {
int value;
while (isWhitespace(value = peek()) && value != -1)
next();
return value == -1;
}
int peek() {
if (numChars == -1)
return -1;
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
return -1;
}
if (numChars <= 0)
return -1;
}
return buf[curChar];
}
boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
} | Java | ["5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5"] | 2 seconds | ["4"] | NoteOne of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4. | Java 7 | standard input | [
"greedy"
] | 6253f6217c58a66573b1ddc6962c372c | The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop. | 1,500 | Print a single integer — the maximum number of candies Om Nom can eat. | standard output | |
PASSED | 4949f1d16ff97bc82e49bcdb0609674f | train_001.jsonl | 1402673400 | The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the floor of the house, its mass is mi. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most x centimeter high jumps. When Om Nom eats a candy of mass y, he gets stronger and the height of his jump increases by y centimeters.What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)? | 256 megabytes | import java.util.*;
import java.io.*;
public class A {
FastScanner in;
PrintWriter out;
int n;
int[] t, h, m;
int sol(int type, int x) {
boolean[] was = new boolean[n];
int res = 0;
for (int i = 0; i < n;) {
int maxi = -1;
for (int j = 0; j < n; j++)
if (!was[j] && t[j] == type && h[j] <= x) {
if (maxi == -1 || m[maxi] < m[j])
maxi = j;
}
if (maxi == -1)
break;
res++;
x += m[maxi];
was[maxi] = true;
type = 1 - type;
}
return res;
}
public void solve() throws IOException {
n = in.nextInt();
int x = in.nextInt();
t = new int[n];
h = new int[n];
m = new int[n];
for (int i = 0; i < n; i++) {
t[i] = in.nextInt();
h[i] = in.nextInt();
m[i] = in.nextInt();
}
int res = Math.max(sol(0, x), sol(1, x));
out.println(res);
}
public void run() {
try {
in = new FastScanner();
out = new PrintWriter(System.out);
solve();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
}
public static void main(String[] arg) {
new A().run();
}
} | Java | ["5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5"] | 2 seconds | ["4"] | NoteOne of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4. | Java 7 | standard input | [
"greedy"
] | 6253f6217c58a66573b1ddc6962c372c | The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop. | 1,500 | Print a single integer — the maximum number of candies Om Nom can eat. | standard output | |
PASSED | ac7bd782c772d4aea27a83ed441c713c | train_001.jsonl | 1402673400 | The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the floor of the house, its mass is mi. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most x centimeter high jumps. When Om Nom eats a candy of mass y, he gets stronger and the height of his jump increases by y centimeters.What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)? | 256 megabytes | import java.io.*;
import java.util.*;
public class Main implements Runnable {
BufferedReader in;
PrintWriter out;
StringTokenizer st;
String nextToken() throws IOException {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(in.readLine());
}
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException{
return Long.parseLong(nextToken());
}
class A {
int h, m, n;
A(int q, int w, int e) {
h = q; m = w;
n = e;
}
}
int sol(List<A> a1, List<A> a2, int x) {
List<A>[] a = new List[2];
a[0] = new LinkedList<A>();
a[1] = new LinkedList<A>();
for (A i : a1) a[0].add(i);
for (A i : a2) a[1].add(i);
int q = 0;
TreeSet<A>[] tm = new TreeSet[2];
tm[0] = new TreeSet<A>(new Comparator<A>() {
@Override
public int compare(A o1, A o2) {
if (o1.m == o2.m) return o1.n - o2.n;
return o1.m - o2.m;
}
});
tm[1] = new TreeSet<A>(new Comparator<A>() {
@Override
public int compare(A o1, A o2) {
if (o1.m == o2.m) return o1.n - o2.n;
return o1.m - o2.m;
}
});
int ans = 0;
while (true) {
while (!a[0].isEmpty() && a[0].get(0).h <= x) {
tm[0].add(a[0].get(0));
a[0].remove(0);
}
while (!a[1].isEmpty() && a[1].get(0).h <= x) {
tm[1].add(a[1].get(0));
a[1].remove(0);
}
if (tm[q].isEmpty()) break;
x += tm[q].pollLast().m;
ans++;
q ^= 1;
}
return ans;
}
void solve() throws IOException {
int n = nextInt();
int x = nextInt();
List<A> a1 = new LinkedList<A>();
List<A> a2 = new LinkedList<A>();
for (int i = 0; i < n; i++) {
int t = nextInt();
int h = nextInt();
int m = nextInt();
if (t == 0) {
a1.add(new A(h, m, i));
} else {
a2.add(new A(h, m, i));
}
}
Collections.sort(a1, new Comparator<A>() {
@Override
public int compare(A o1, A o2) {
return o1.h - o2.h;
}
});
Collections.sort(a2, new Comparator<A>() {
@Override
public int compare(A o1, A o2) {
return o1.h - o2.h;
}
});
out.println(Math.max(sol(a1, a2, x), sol(a2, a1, x)));
}
public void run() {
try {
// in = new BufferedReader(new FileReader("input.txt"));
// out = new PrintWriter("output.txt");
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
Locale.setDefault(Locale.UK);
solve();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
} finally {
out.close();
}
}
public static void main(String Args[]) {
new Thread(null, new Main(), "1", 1 << 28).start();
}
} | Java | ["5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5"] | 2 seconds | ["4"] | NoteOne of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4. | Java 7 | standard input | [
"greedy"
] | 6253f6217c58a66573b1ddc6962c372c | The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop. | 1,500 | Print a single integer — the maximum number of candies Om Nom can eat. | standard output | |
PASSED | 33ad6aee580c20b38883a9d00a178fe6 | train_001.jsonl | 1402673400 | The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the floor of the house, its mass is mi. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most x centimeter high jumps. When Om Nom eats a candy of mass y, he gets stronger and the height of his jump increases by y centimeters.What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)? | 256 megabytes | import java.util.Scanner;
/**
*
* @author Mbt
*/
public class A {
public static void main(String[] args) {
new Solver().solve();
}
}
class Solver{
final int MAXN= 2001;
Candy[] candies= new Candy[MAXN];
int n, x;
void solve(){
Scanner reader= new Scanner(System.in);
n= reader.nextInt();
x= reader.nextInt();
for (int i = 0; i < n; i++)
candies[i]= new Candy(reader.nextInt(), reader.nextInt(), reader.nextInt());
int sumFirst0=0, x0=x;
for (int i = 0; i < n; i++) {
int index= findMaxPossibleMass(x0, i%2);
if (index==-1) break;
sumFirst0++;
x0 += candies[index].mass;
candies[index].used= true;
}
for (int i = 0; i < n; i++)
candies[i].used=false;
int sumFirst1=0, x1=x;
for (int i = 0; i < n; i++) {
int index= findMaxPossibleMass(x1, (i+1)%2);
if (index==-1) break;
sumFirst1++;
x1 += candies[index].mass;
candies[index].used= true;
}
System.out.println(Math.max(sumFirst0, sumFirst1));
}
int findMaxPossibleMass(int x, int type){
int maxMass=-1, maxIndex=-1;
for (int i = 0; i < n; i++) {
if (!candies[i].used && candies[i].type==type && candies[i].height<=x && candies[i].mass>=maxMass){
maxMass= candies[i].mass;
maxIndex=i;
}
}
return maxIndex;
}
}
class Candy{
public int type, height, mass;
public boolean used;
public Candy(int t, int h, int m){
type= t; height= h; mass= m;
}
} | Java | ["5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5"] | 2 seconds | ["4"] | NoteOne of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4. | Java 7 | standard input | [
"greedy"
] | 6253f6217c58a66573b1ddc6962c372c | The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop. | 1,500 | Print a single integer — the maximum number of candies Om Nom can eat. | standard output | |
PASSED | 14c8b346eaf3afc250722ec841f12281 | train_001.jsonl | 1402673400 | The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the floor of the house, its mass is mi. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most x centimeter high jumps. When Om Nom eats a candy of mass y, he gets stronger and the height of his jump increases by y centimeters.What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)? | 256 megabytes | import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class OmNom {
/**
* @param args
*/
static int h;
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int heightt=sc.nextInt();
h=heightt;
ArrayList<candy>f=new ArrayList<candy>();
ArrayList<candy>c=new ArrayList<candy>();
for(int i=0;i<n;i++){
int x=sc.nextInt();
int y=sc.nextInt();
int z=sc.nextInt();
if(x==0){
f.add(new candy(y,z));
}
else
c.add(new candy(y,z));
}
int n1=f.size();
int n2=c.size();
candy[]fruits=new candy[f.size()];
candy[]caramel=new candy[c.size()];
for(int i=0;i<n1;i++){
fruits[i]=f.remove(0);
}
for(int i=0;i<n2;i++){
caramel[i]=c.remove(0);
}
Arrays.sort(fruits);
Arrays.sort(caramel);
boolean[]visited1=new boolean[n1];
boolean []visited2=new boolean[n2];
//System.out.println(fruits[0].mass);
int ans1=startBy(0,visited1,visited2,fruits,caramel);
Arrays.fill(visited1,false);
Arrays.fill(visited2,false);
h=heightt;
int ans2=startBy(1,visited1,visited2,fruits,caramel);
System.out.println(Math.max(ans1,ans2));
}
private static int startBy(int i, boolean[] visited1, boolean[] visited2,
candy[] fruits, candy[] caramel) {
if(i==0){
return getFirst(visited1,visited2,fruits,caramel,0);
}
else
return getSecond(visited1,visited2,fruits,caramel,0);
}
private static int getSecond(boolean[] visited1, boolean[] visited2,
candy[] fruits, candy[] caramel, int cnt) {
boolean flag=false;
for(int i=0;i<caramel.length;i++){
if(visited2[i]){
continue;
}
else {
if(caramel[i].height<=h){
visited2[i]=true;
h+=caramel[i].mass;
cnt++;
flag=true;
//System.out.println(caramel[i].height);
break;
}
}
}
if(flag)
return getFirst(visited1,visited2,fruits,caramel,cnt);
else
return cnt;
}
private static int getFirst(boolean[] visited1, boolean[] visited2,
candy[] fruits, candy[] caramel,int cnt) {
boolean flag=false;
for(int i=0;i<fruits.length;i++){
if(visited1[i]){
continue;
}
else {
if(fruits[i].height<=h){
visited1[i]=true;
h+=fruits[i].mass;
cnt++;
flag=true;
// System.out.println(fruits[i].height);
break;
}
}
}
if(flag)
return getSecond(visited1,visited2,fruits,caramel,cnt);
else
return cnt;
}
static class candy implements Comparable{
int height;
int mass;
public candy(int h,int m){
this.height=h;
this.mass=m;
}
@Override
public int compareTo(Object a) {
candy c=(candy)a;
if(this.mass<c.mass)
return 1;
else
if(this.mass>c.mass)
return -1;
else return 0;
}
}
}
| Java | ["5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5"] | 2 seconds | ["4"] | NoteOne of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4. | Java 7 | standard input | [
"greedy"
] | 6253f6217c58a66573b1ddc6962c372c | The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop. | 1,500 | Print a single integer — the maximum number of candies Om Nom can eat. | standard output | |
PASSED | 95de09cdd4b3e2c9aa20b4e181f05d30 | train_001.jsonl | 1402673400 | The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the floor of the house, its mass is mi. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most x centimeter high jumps. When Om Nom eats a candy of mass y, he gets stronger and the height of his jump increases by y centimeters.What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)? | 256 megabytes |
import java.util.*;
public class A {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
int n = reader.nextInt();
int x = reader.nextInt();
ArrayList<Integer> height1 = new ArrayList<Integer>();
ArrayList<Integer> mass1 = new ArrayList<Integer>();
ArrayList<Integer> height2 = new ArrayList<Integer>();
ArrayList<Integer> mass2 = new ArrayList<Integer>();
for( int i = 0; i < n; i++) {
if (reader.nextInt() == 0) {
height1.add(reader.nextInt());
mass1.add(reader.nextInt());
}
else {
height2.add(reader.nextInt());
mass2.add(reader.nextInt());
}
}
sort(height1, mass1);
sort(height2, mass2);
ArrayList<Integer> height1b = new ArrayList<Integer>(height1);
ArrayList<Integer> mass1b = new ArrayList<Integer>(mass1);
ArrayList<Integer> height2b = new ArrayList<Integer>(height2);
ArrayList<Integer> mass2b = new ArrayList<Integer>(mass2);
int xb = x;
int k = 0;
int j = 0;
//if (height1.size() < height2.size())
// k = 1;
boolean isStopped = false;
while(!isStopped) {
k++;
if (k % 2 == 0) {
if ((height2.size() == 0) && (j != 0))
isStopped = true;
for (int i = 0; i < height2.size(); i++) {
if (x >= height2.get(i)) {
x += mass2.get(i);
mass2.remove(i);
height2.remove(i);
break;
}
if ((i == height2.size() - 1) && (j != 0))
isStopped = true;
}
}
else {
if ((height1.size() == 0) && (j != 0))
isStopped = true;
for (int i = 0; i < height1.size(); i++) {
if (x >= height1.get(i)) {
x += mass1.get(i);
mass1.remove(i);
height1.remove(i);
break;
}
if ((i == height1.size() - 1) && (j != 0))
isStopped = true;
}
}
j++;
}
k = 1;
j = 0;
x = xb;
//if (height1.size() < height2.size())
// k = 1;
isStopped = false;
while(!isStopped) {
k++;
if (k % 2 == 0) {
if ((height2b.size() == 0) && (j != 0))
isStopped = true;
for (int i = 0; i < height2b.size(); i++) {
if (x >= height2b.get(i)) {
x += mass2b.get(i);
mass2b.remove(i);
height2b.remove(i);
break;
}
if ((i == height2b.size() - 1) && (j != 0))
isStopped = true;
}
}
else {
if ((height1b.size() == 0) && (j != 0))
isStopped = true;
for (int i = 0; i < height1b.size(); i++) {
if (x >= height1b.get(i)) {
x += mass1b.get(i);
mass1b.remove(i);
height1b.remove(i);
break;
}
if ((i == height1b.size() - 1) && (j != 0))
isStopped = true;
}
}
j++;
}
int res1 = n - height1.size() - height2.size();
int res2 = n - height1b.size() - height2b.size();
System.out.println(res1 > res2 ? res1 : res2);
}
public static void sort (ArrayList<Integer> height, ArrayList<Integer> mass) {
for (int i = 0; i < mass.size(); i++) {
for (int j = i+1; j < mass.size(); j++) {
if (mass.get(i) < mass.get(j)) {
int temp = mass.get(i);
mass.set(i, mass.get(j));
mass.set(j, temp);
temp = height.get(i);
height.set(i, height.get(j));
height.set(j, temp);
}
}
}
}
}
| Java | ["5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5"] | 2 seconds | ["4"] | NoteOne of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4. | Java 7 | standard input | [
"greedy"
] | 6253f6217c58a66573b1ddc6962c372c | The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop. | 1,500 | Print a single integer — the maximum number of candies Om Nom can eat. | standard output | |
PASSED | 0e9000e6a090869994ef3a58917a9505 | train_001.jsonl | 1402673400 | The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the floor of the house, its mass is mi. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most x centimeter high jumps. When Om Nom eats a candy of mass y, he gets stronger and the height of his jump increases by y centimeters.What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)? | 256 megabytes | import java.awt.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;
public class pa62 {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int x=sc.nextInt();
int count=0;
ArrayList<food> list=new ArrayList<food>();
ArrayList<food> list1=new ArrayList<food>();
food f;
for(int i=0;i<n;i++){
f=new food();
f.t=sc.nextInt();
f.h=sc.nextInt();
f.m=sc.nextInt();
if(f.t==0){
list.add(f);
}
else{
list1.add(f);
}
}
Collections.sort(list);
Collections.sort(list1);
// print(list);
// print(list1);
ArrayList<food> temp=(ArrayList<food>) list.clone();
ArrayList<food> temp1=(ArrayList<food>) list1.clone();
int c1=returncnt(list,list1,x);
int c2=returncnt(temp1,temp,x);
count=c1>c2?c1:c2;
System.out.println(count);
}
public static int returncnt(ArrayList<food> l,ArrayList<food> l1,int x){
int count=0;
boolean next=true;
while(next){
boolean found=false;
boolean found1=false;
for(int i=l.size()-1;i>=0;i--){
if(l.get(i).h<=x){
x+=l.get(i).m;
l.remove(i);
count++;
found=true;
break;
}
}
for(int i=l1.size()-1;i>=0 && found;i--){
if(l1.get(i).h<=x){
x+=l1.get(i).m;
l1.remove(i);
count++;
found1=true;
break;
}
}
next=found1;
}
//System.out.println(count);
return count;
}
public static void print(ArrayList<food> list){
for(int i=0;i<list.size();i++){
System.out.println(list.get(i).t+" "+list.get(i).h+" "+list.get(i).m);
}
}
}
class food implements Comparable<Object>{
public int t=-1;
public int h;
public int m;
@Override
public int compareTo(Object o) {
// TODO Auto-generated method stub
food of=(food) o;
if(this.m==of.m){
return 0;
}else if(this.m>of.m){
return 1;
}else{
return -1;
}
}
} | Java | ["5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5"] | 2 seconds | ["4"] | NoteOne of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4. | Java 7 | standard input | [
"greedy"
] | 6253f6217c58a66573b1ddc6962c372c | The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop. | 1,500 | Print a single integer — the maximum number of candies Om Nom can eat. | standard output | |
PASSED | 327c28b7c23b7ab4f195ad8989e5afa9 | train_001.jsonl | 1402673400 | The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the floor of the house, its mass is mi. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most x centimeter high jumps. When Om Nom eats a candy of mass y, he gets stronger and the height of his jump increases by y centimeters.What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)? | 256 megabytes | import java.io.IOException;
import java.util.Arrays;
import java.io.FilterInputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedInputStream;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Zyflair Griffane
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
JoltyScanner in = new JoltyScanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
}
class TaskA {
public void solve(int testNumber, JoltyScanner in, PrintWriter out) {
// Basic parameters
int candies = in.nextInt();
int initialHeight = in.nextInt();
// Get candies
Candy[] arr = new Candy[candies];
for (int i = 0; i < candies; i++) {
arr[i] = new Candy(in.nextInt(), in.nextInt(), in.nextInt());
}
// Sort candies
Arrays.sort(arr);
// The answer
int answer = 0;
// Try different starting types
for (int startingType = 0; startingType < 2; startingType++) {
// All candies are not used from the start
for (int i = 0; i < candies; i++) {
arr[i].used = false;
}
// The current height we can jump
int height = initialHeight;
// The current type to eat
int type = startingType;
// How much we ate
int ate = 0;
// Eating time!
Eating: while (true) {
// Find the first candy that's the correct type and is low enough
for (int i = 0; i < candies; i++) {
// If it's good, eat it!
if (arr[i].type == type && arr[i].height <= height && !arr[i].used) {
arr[i].used = true;
height += arr[i].mass;
type ^= 1;
ate++;
// Continue eating
continue Eating;
}
}
// Otherwise, we're done eating
answer = Math.max(answer, ate);
break;
}
}
// Output answer
out.println(answer);
}
public class Candy implements Comparable<Candy> {
int height;
int mass;
int type;
boolean used;
public Candy(int type, int height, int mass) {
this.height = height;
this.mass = mass;
this.type = type;
}
// Sorting by descending mass
public int compareTo(Candy o) {
return o.mass - mass;
}
}
}
class JoltyScanner {
public static final int BUFFER_SIZE = 1 << 16;
public static final char NULL_CHAR = (char) -1;
byte[] buffer = new byte[BUFFER_SIZE];
boolean EOF_FLAG = false;
int bufferIdx = 0, size = 0;
char c = (char) -1;
BufferedInputStream in = new BufferedInputStream(System.in, BUFFER_SIZE);
public JoltyScanner(InputStream in) {
this.in = new BufferedInputStream(in);
}
public int nextInt() {
long x = nextLong();
if (x > Integer.MAX_VALUE || x < Integer.MIN_VALUE) {
throw new ArithmeticException("Scanned value overflows integer");
}
return (int) x;
}
public long nextLong() {
boolean negative = false;
if (c == NULL_CHAR) {
c = nextChar();
}
while (!EOF_FLAG && (c < '0' || c > '9')) {
if (c == '-') {
negative = true;
}
c = nextChar();
}
if (EOF_FLAG) {
throw new EndOfFileException();
}
long res = 0;
while (c >= '0' && c <= '9') {
res = (res << 3) + (res << 1) + c - '0';
c = nextChar();
}
return negative ? -res : res;
}
public char nextChar() {
if (EOF_FLAG) {
return NULL_CHAR;
}
while (bufferIdx == size) {
try {
size = in.read(buffer);
if (size == -1) {
throw new Exception();
}
}
catch (Exception e) {
EOF_FLAG = true;
return (char) -1;
}
if (size == -1) {
size = BUFFER_SIZE;
}
bufferIdx = 0;
}
return (char) buffer[bufferIdx++];
}
public class EndOfFileException extends RuntimeException {}
}
| Java | ["5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5"] | 2 seconds | ["4"] | NoteOne of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4. | Java 7 | standard input | [
"greedy"
] | 6253f6217c58a66573b1ddc6962c372c | The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop. | 1,500 | Print a single integer — the maximum number of candies Om Nom can eat. | standard output | |
PASSED | fd2f75b7b2c51a9034345b902ca57350 | train_001.jsonl | 1402673400 | The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the floor of the house, its mass is mi. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most x centimeter high jumps. When Om Nom eats a candy of mass y, he gets stronger and the height of his jump increases by y centimeters.What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)? | 256 megabytes |
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class ZeptoA {
static class Sweet implements Comparable<Sweet>{
int height; int mass;
public Sweet(int height, int mass){
this.height = height;
this.mass = mass;
}
public int compareTo(Sweet other){
return other.mass-this.mass;
}
}
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int x = Integer.parseInt(st.nextToken());
ArrayList<Sweet>[] a = new ArrayList[2];
a[0] = new ArrayList<Sweet>();
a[1] = new ArrayList<Sweet>();
for(int i=0; i<n; i++){
st = new StringTokenizer(br.readLine());
int type = Integer.parseInt(st.nextToken());
a[type].add(new Sweet(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken())));
}
for(int i=0; i<2; i++){
Collections.sort(a[i], new Comparator<Sweet>() {
@Override
public int compare(Sweet o1, Sweet o2) {
return o1.height-o2.height;
}
});
}
int result=0;
for(int i=0; i<2; i++){
int jump=x;
PriorityQueue<Sweet>[] queues = new PriorityQueue[2];
queues[0] = new PriorityQueue<Sweet>();
queues[1] = new PriorityQueue<Sweet>();
int[] index = new int[2];
int j=i;
while(true){
while(index[j]<a[j].size() && jump>=a[j].get(index[j]).height){
queues[j].add(a[j].get(index[j]));
index[j]++;
}
if(queues[j].isEmpty()) break;
jump+=queues[j].poll().mass;
j=1-j;
}
if(index[i]>index[1-i])
result=Math.max(result, index[1-i]*2+1);
else
result=Math.max(result, index[i]*2);
}
System.out.println(result);
}
}
| Java | ["5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5"] | 2 seconds | ["4"] | NoteOne of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4. | Java 7 | standard input | [
"greedy"
] | 6253f6217c58a66573b1ddc6962c372c | The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop. | 1,500 | Print a single integer — the maximum number of candies Om Nom can eat. | standard output | |
PASSED | 3cbff4bd82f798597f06f0f64189d78e | train_001.jsonl | 1402673400 | The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the floor of the house, its mass is mi. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most x centimeter high jumps. When Om Nom eats a candy of mass y, he gets stronger and the height of his jump increases by y centimeters.What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)? | 256 megabytes | import java.awt.GradientPaint;
import java.awt.geom.Line2D;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.concurrent.LinkedBlockingDeque;
public class a {
public static class node {
int type;
int h;
int mass;
node(int index, int val, int m) {
type = index;
h = val;
mass = m;
}
}
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringBuilder q = new StringBuilder();
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
String y[] = in.readLine().split(" ");
int n = Integer.parseInt(y[0]);
int max = Integer.parseInt(y[1]);
node a[] = new node[n];
boolean vis[] = new boolean[n];
int one = 0;
int two = 0;
for (int i = 0; i < n; i++) {
y = in.readLine().split(" ");
a[i] = new node(Integer.parseInt(y[0]), Integer.parseInt(y[1]),
Integer.parseInt(y[2]));
int k = a[i].type;
if (k == 0)
one++;
else
two++;
}
int index = -1;
int maxmass = -1;
int type = -1;
int max1=max;
int c = 0;
for (int i = 0; i < n; i++) {
index = -1;
maxmass = -1;
for (int j = 0; j < n; j++) {
if (!vis[j] && a[j].h <= max1 && a[j].type != type
&& a[j].mass > maxmass) {
index = j;
maxmass = a[j].mass;
}
}
if (index == -1)
break;
c++;
vis[index] = true;
max1 += maxmass;
type = a[index].type;
}
//..........................................
vis=new boolean[n];
int c2=0;
type=1;
int max2=max;
for (int i = 0; i < n; i++) {
index = -1;
maxmass = -1;
for (int j = 0; j < n; j++) {
if (!vis[j] && a[j].h <= max2 && a[j].type != type
&& a[j].mass > maxmass) {
index = j;
maxmass = a[j].mass;
}
}
if (index == -1)
break;
c2++;
vis[index] = true;
max2 += maxmass;
type = a[index].type;
}
//......................................................
vis=new boolean[n];
int c3=0;
type=0;
int max3=max;
for (int i = 0; i < n; i++) {
index = -1;
maxmass = -1;
for (int j = 0; j < n; j++) {
if (!vis[j] && a[j].h <= max3 && a[j].type != type
&& a[j].mass > maxmass) {
index = j;
maxmass = a[j].mass;
}
}
if (index == -1)
break;
c3++;
vis[index] = true;
max3 += maxmass;
type = a[index].type;
}
System.out.println(Math.max(c, Math.max(c2, c3)));
out.close();
}
} | Java | ["5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5"] | 2 seconds | ["4"] | NoteOne of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4. | Java 7 | standard input | [
"greedy"
] | 6253f6217c58a66573b1ddc6962c372c | The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop. | 1,500 | Print a single integer — the maximum number of candies Om Nom can eat. | standard output | |
PASSED | 6cb4cf32b74cda4b8919b602723fdbf3 | train_001.jsonl | 1402673400 | The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the floor of the house, its mass is mi. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most x centimeter high jumps. When Om Nom eats a candy of mass y, he gets stronger and the height of his jump increases by y centimeters.What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)? | 256 megabytes | import java.util.List;
import java.util.Scanner;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Collections;
import java.util.Comparator;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author ocozalp
*/
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();
}
}
class TaskA {
public void solve(int testNumber, Scanner in, PrintWriter out) {
int n = in.nextInt();
int x = in.nextInt();
ArrayList<Candy>[] candies = new ArrayList[2];
candies[0] = new ArrayList<Candy>();
candies[1] = new ArrayList<Candy>();
for(int i = 0; i<n; i++) {
int t = in.nextInt();
int h = in.nextInt();
int m = in.nextInt();
Candy c = new Candy();
c.h = h;
c.m = m;
candies[t].add(c);
}
Collections.sort(candies[0], new Comparator<Candy>() {
@Override
public int compare(Candy o1, Candy o2) {
return o1.h - o2.h;
}
});
Collections.sort(candies[1], new Comparator<Candy>() {
@Override
public int compare(Candy o1, Candy o2) {
return o1.h - o2.h;
}
});
int result = solve(candies, 0, x);
result = Math.max(result, solve(candies, 1, x));
out.println(result);
}
private int solve(ArrayList<Candy>[] candies, int current, int x) {
int result = 0;
boolean [][] control = new boolean[2][2001];
int maxind = -1;
while(true) {
maxind = getMax(candies, current, x, control);
if(maxind == -1) break;
control[current][maxind] = true;
Candy candy = candies[current].get(maxind);
x += candy.m;
current = (current + 1) % 2;
result++;
}
return result;
}
private int getMax(ArrayList<Candy>[] candies, int current, int x, boolean [][] control) {
int max = -1;
int maxind = -1;
for(int i = 0; i<candies[current].size(); i++) {
if(candies[current].get(i).h <= x) {
if(max < candies[current].get(i).m && !control[current][i]) {
max = candies[current].get(i).m;
maxind = i;
}
}else break;
}
return maxind;
}
private static class Candy {
int h;
int m;
}
}
| Java | ["5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5"] | 2 seconds | ["4"] | NoteOne of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4. | Java 7 | standard input | [
"greedy"
] | 6253f6217c58a66573b1ddc6962c372c | The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop. | 1,500 | Print a single integer — the maximum number of candies Om Nom can eat. | standard output | |
PASSED | f3936b6bd851efbbf9ea56b7b0518fa5 | train_001.jsonl | 1402673400 | The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the floor of the house, its mass is mi. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most x centimeter high jumps. When Om Nom eats a candy of mass y, he gets stronger and the height of his jump increases by y centimeters.What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)? | 256 megabytes | import java.io.*;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Zepto {
public static void main(String[] args) {
Zepto z = new Zepto();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
ArrayList<candy> candy0 = new ArrayList<candy>();
ArrayList<candy> candy1 = new ArrayList<candy>();
int n;
int x0 =0,x1=0;
int noofeatencandies0=0, noofeatencandies1 = 0;
try {
//read input
String s = br.readLine();
//initialize n,x
String[] arr1 = s.split(" ");
n = Integer.parseInt(arr1[0]);
x0 = Integer.parseInt(arr1[1]);
x1 = Integer.parseInt(arr1[1]);
int count = 1;
while(count<=n){
String r = br.readLine();
if(r!=null) {String[] arr2 = r.split(" ");
candy c = new candy(Integer.parseInt(arr2[0]),Integer.parseInt(arr2[1]),Integer.parseInt(arr2[2]));
candy0.add(c);
candy1.add(c);
}
count++;
}
} catch (IOException ex) { }
//System.out.println("check point 1");
//assume that first omnom eats candy type 0
ArrayList<candy> candytype0 = new ArrayList<candy>();
for(int i =0; i<candy0.size();i++){
if(candy0.get(i).type==0){
candytype0.add(candy0.get(i));
}
}
//System.out.println("check point 1.1");
candy c = z.findFirstCandy(candytype0,x0);
if(c!=null){
x0 = x0 + c.mass;
candy0.remove(c);
noofeatencandies0++;
//System.out.println("checkpoint 1.2");
noofeatencandies0 = noofeatencandies0 + z.findEatenCandies(0,candy0,x0);
//System.out.println("checkpoint 1.3");
}
//System.out.println("check point 2");
//assume that first omnom eats candy type 1
ArrayList<candy> candytype1 = new ArrayList<candy>();
for(int i =0; i<candy1.size();i++){
if(candy1.get(i).type==1){
candytype1.add(candy1.get(i));
}
}
candy c1 = z.findFirstCandy(candytype1,x1);
if(c1!=null){
x1 = x1 + c1.mass;
candy1.remove(c1);
noofeatencandies1++;
noofeatencandies1 = noofeatencandies1 + z.findEatenCandies(1,candy1,x1);
}
if(noofeatencandies0>noofeatencandies1) System.out.println(noofeatencandies0);
else System.out.println(noofeatencandies1);
}
candy findFirstCandy(ArrayList<candy> arrayl, int x){
candy can = null;
ArrayList<candy> reachable = new ArrayList<candy>();
for(int i =0; i< arrayl.size();i++){
if(arrayl.get(i).height<=x){
reachable.add(arrayl.get(i));
}
}
int maxm = 0;
ArrayList<candy> maxmass = new ArrayList<candy>();
for(int i =0; i<reachable.size();i++){
if(maxm<reachable.get(i).mass){
maxm = reachable.get(i).mass;
}
}
for(int i =0; i<reachable.size();i++){
if(maxm==reachable.get(i).mass){
maxmass.add(reachable.get(i));
}
}
if(!maxmass.isEmpty()) can = maxmass.get(0);
return can;
}
int findEatenCandies(int typeoffirstcandy,ArrayList<candy> arrayl,int x){
int previoustype = typeoffirstcandy;
boolean canJump = false;
ArrayList<candy> reachable = new ArrayList<candy>();
ArrayList<candy> diftype = new ArrayList<candy>();
ArrayList<candy> maxmass = new ArrayList<candy>();
int maxm =0;
//System.out.println(arrayl.size());
for(int i =0; i< arrayl.size();i++){
if(arrayl.get(i).height<=x){
reachable.add(arrayl.get(i));
}
}
if(!reachable.isEmpty()) canJump = true;
int eatencandies = 0;
while(canJump ==true){
//System.out.println("checkpoint 1.2.1 " + reachable.size());
for(int i =0; i<reachable.size();i++){
if(previoustype != reachable.get(i).type){
diftype.add(reachable.get(i));
}
}
//System.out.println("checkpoint 1.2.2 " + diftype.size() );
for(int i =0; i<diftype.size();i++){
if(maxm<diftype.get(i).mass){
maxm = diftype.get(i).mass;
}
}
for(int i =0; i<diftype.size();i++){
if(maxm==diftype.get(i).mass){
maxmass.add(diftype.get(i));
}
}
//System.out.println("checkpoint 1.2.3 " + maxmass.size() );
if(!maxmass.isEmpty()){
candy c = maxmass.get(0);
x = x + c.mass;
previoustype = c.type;
arrayl.remove(c);
eatencandies++;
}
//System.out.println("checkpoint 1.2.4 " + arrayl.size() );
canJump = false;
reachable = new ArrayList<candy>();
diftype = new ArrayList<candy>();
maxmass = new ArrayList<candy>();
maxm = 0;
for(int i =0; i< arrayl.size();i++){
if(arrayl.get(i).height<=x && arrayl.get(i).type != previoustype){
reachable.add(arrayl.get(i));
}
}
if(!reachable.isEmpty()) canJump = true;
}
return eatencandies;
}
}
class candy{
int type;
int height;
int mass;
candy(int t, int h, int m){
type = t;
height = h;
mass = m;
}
} | Java | ["5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5"] | 2 seconds | ["4"] | NoteOne of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4. | Java 7 | standard input | [
"greedy"
] | 6253f6217c58a66573b1ddc6962c372c | The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop. | 1,500 | Print a single integer — the maximum number of candies Om Nom can eat. | standard output | |
PASSED | 36b9db7d63d2c832fccdde05d90c56e8 | train_001.jsonl | 1402673400 | The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. One day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the height of hi centimeters above the floor of the house, its mass is mi. Om Nom wants to eat as many candies as possible. At the beginning Om Nom can make at most x centimeter high jumps. When Om Nom eats a candy of mass y, he gets stronger and the height of his jump increases by y centimeters.What maximum number of candies can Om Nom eat if he never eats two candies of the same type in a row (Om Nom finds it too boring)? | 256 megabytes | import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Nguyen Trung Hieu - vuondenthanhcong11@gmail.com
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
}
class TaskA {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int count = in.readInt();
int initHeight = in.readInt();
int[] type = new int[count];
int[] height = new int[count];
int[] points = new int[count];
IOUtils.readIntArrays(in, type, height, points);
int[] answer = new int[2];
for (int initType = 0; initType < 2; initType++) {
boolean[] visited = new boolean[count];
answer[initType] = 0;
int curHeight = initHeight;
int curType = initType;
for (int i = 0; i < count; i++) {
int idx = -1;
for (int j = 0; j < count; j++) {
if (!visited[j] && curType == type[j] && height[j] <= curHeight && (idx == -1 || points[j] > points[idx]))
idx = j;
}
if (idx >= 0) {
answer[initType]++;
curHeight += points[idx];
visited[idx] = true;
curType = (curType + 1) % 2;
}
else
break;
}
}
out.printLine(Math.max(answer[0], answer[1]));
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object...objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object...objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
}
class IOUtils {
public static void readIntArrays(InputReader in, int[]... arrays) {
for (int i = 0; i < arrays[0].length; i++) {
for (int j = 0; j < arrays.length; j++)
arrays[j][i] = in.readInt();
}
}
}
| Java | ["5 3\n0 2 4\n1 3 1\n0 8 3\n0 20 10\n1 5 5"] | 2 seconds | ["4"] | NoteOne of the possible ways to eat 4 candies is to eat them in the order: 1, 5, 3, 2. Let's assume the following scenario: Initially, the height of Om Nom's jump equals 3. He can reach candies 1 and 2. Let's assume that he eats candy 1. As the mass of this candy equals 4, the height of his jump will rise to 3 + 4 = 7. Now Om Nom can reach candies 2 and 5. Let's assume that he eats candy 5. Then the height of his jump will be 7 + 5 = 12. At this moment, Om Nom can reach two candies, 2 and 3. He won't eat candy 2 as its type matches the type of the previously eaten candy. Om Nom eats candy 3, the height of his jump is 12 + 3 = 15. Om Nom eats candy 2, the height of his jump is 15 + 1 = 16. He cannot reach candy 4. | Java 7 | standard input | [
"greedy"
] | 6253f6217c58a66573b1ddc6962c372c | The first line contains two integers, n and x (1 ≤ n, x ≤ 2000) — the number of sweets Evan has and the initial height of Om Nom's jump. Each of the following n lines contains three integers ti, hi, mi (0 ≤ ti ≤ 1; 1 ≤ hi, mi ≤ 2000) — the type, height and the mass of the i-th candy. If number ti equals 0, then the current candy is a caramel drop, otherwise it is a fruit drop. | 1,500 | Print a single integer — the maximum number of candies Om Nom can eat. | standard output | |
PASSED | 9b76fae2798d8fae5a92727fe5685766 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes |
import java.io.*;
import java.util.*;
import java.util.Queue;
import java.awt.*;
import java.math.*;
public class Main {
static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st = new StringTokenizer("");
static String next() {
try {
while (!st.hasMoreTokens()) {
String s = br.readLine();
if (s == null) {
return null;
}
st = new StringTokenizer(s);
}
return st.nextToken();
} catch(Exception e) {
return null;
}
}
public static void main(String[] args) {
int N = Integer.parseInt( next() );
long minX, minY, maxX, maxY;
minX = minY = 1L << 40;
maxX = maxY = -(1L << 40);
while (N-- > 0) {
long x = Integer.parseInt( next() );
long y = Integer.parseInt( next() );
minX = Math.min(minX, x); maxX = Math.max(maxX, x);
minY = Math.min(minY, y); maxY = Math.max(maxY, y);
}
long area = Math.max(maxY - minY, maxX - minX);
area*= area;
out.println( Math.max( 1, area ) );
out.flush();
}
}
| Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | dff11ca269c44c4fb01795ab8246aec7 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes |
import java.util.Scanner;
import java.util.TreeSet;
public class B {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
TreeSet<Long>x=new TreeSet<Long>();
TreeSet<Long>y=new TreeSet<Long>();
for (int i =1; i <=n; i++) {
x.add(sc.nextLong());
y.add(sc.nextLong());
}
long h=x.last()-x.first();
long w=y.last()-y.first();
if(h>w){
System.out.println(h*h);
}else{
System.out.println(w*w);
}
}
} | Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | b61ece4753ded94824c793f7d595e0d7 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.util.Scanner;
public class Life {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int h=in.nextInt();
int[] x=new int[h]; int []y=new int[h];int c=0,g=0;
for(int i=0;i<h;i++){
y[i]+=in.nextInt();
x[i]+=in.nextInt();
}
for(int n=0;n<y.length;n++)
for(int j=n+1;j<y.length;j++){
if (y[n] < y[j])
{
c = y[n];
y[n] = y[j];
y[j] = c;
}}
for(int n=0;n<x.length;n++)
for(int j=n+1;j<x.length;j++){
if (x[n] < x[j])
{
g = x[n];
x[n] = x[j];
x[j] = g;
}}
long f=Math.abs(y[0]-y[y.length-1]);
long s=Math.abs(x[0]-x[x.length-1]);
if(f>s)
System.out.println(Math.abs(f*f));
else
System.out.println(Math.abs(s*s));
}
} | Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | 27c7b7b6af18ebbbb2a21f73ac60aa17 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner sin = new Scanner(System.in);
long xmax = -999999999999999999l, xmin = 999999999999999999l, ymax = -999999999999999999l, ymin = 999999999999999999l, x, y, result, n = sin.nextInt();
if(n == 1)
{
System.out.println(1);
return;
}
for(int i = 0; i < n; i++)
{
x = sin.nextInt();
if(xmax < x)
xmax = x;
if(xmin > x)
xmin = x;
y = sin.nextInt();
if(ymax < y)
ymax = y;
if(ymin > y)
ymin = y;
}
xmax = xmax - xmin;
ymax = ymax - ymin;
result = Math.max(xmax, ymax);
System.out.println(result*result);
// System.out.println(ymin);
}
} | Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | cce3ac583a45093d75d3a7bbbbcbb1a4 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.util.*;import java.lang.Math;public class Valuable{public static void findArea(long n,Scanner in){long bigX,smallX,bigY,smallY;bigX=smallX=in.nextLong();bigY=smallY=in.nextLong();for(int i=0;i<n-1;i++){long nextX=in.nextLong();long nextY=in.nextLong();if(nextX>bigX){bigX=nextX;}else if(nextX<smallX){smallX=nextX;}
if(nextY>bigY){bigY=nextY;}else if(nextY<smallY){smallY=nextY;}}
long xDiff=bigX-smallX;long yDiff=bigY-smallY;if(Math.abs(xDiff)>=Math.abs(yDiff)){System.out.println(xDiff*xDiff);}else{System.out.println(yDiff*yDiff);}}
public static void main(String[]args){Scanner in=new Scanner(System.in);long n=in.nextLong();findArea(n,in);}} | Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | 98cd7678fac51a1a47babd3db29cb49d | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.util.*;
import java.lang.Math;
public class Valuable{
public static void findArea(long n, Scanner in){
long bigX, smallX, bigY, smallY;
bigX = smallX = in.nextLong();
bigY = smallY = in.nextLong();
for(int i=0; i<n-1; i++){
long nextX = in.nextLong();
long nextY = in.nextLong();
if(nextX > bigX){
bigX = nextX;
}else if(nextX < smallX){
smallX = nextX;
}
if(nextY > bigY){
bigY = nextY;
}else if(nextY < smallY){
smallY = nextY;
}
}
long xDiff = bigX - smallX;
long yDiff = bigY - smallY;
if(Math.abs(xDiff) >= Math.abs(yDiff)){
System.out.println(xDiff*xDiff);
}else{
System.out.println(yDiff*yDiff);
}
}
public static void main(String[] args){
Scanner in = new Scanner(System.in);
long n = in.nextLong();
findArea(n, in);
}
} | Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | ee210b58b35bac11a4b1be038180436b | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.util.*;
import java.lang.Math;
public class Valuable{
public static void findArea(long n, Scanner in){
long bigX = in.nextLong();
long smallX = bigX;
long bigY = in.nextLong();
long smallY = bigY;
for(int i=0; i<n-1; i++){
long nextX = in.nextLong();
long nextY = in.nextLong();
//System.out.println(next);
if(nextX > bigX){
bigX = nextX;
}else if(nextX < smallX){
smallX = nextX;
}
if(nextY > bigY){
bigY = nextY;
}else if(nextY < smallY){
smallY = nextY;
}
}
long xDiff = bigX - smallX;
//System.out.println(xDiff);
long yDiff = bigY - smallY;
//System.out.println(yDiff);
if(Math.abs(xDiff) >= Math.abs(yDiff)){
System.out.println(xDiff*xDiff);
}else{
System.out.println(yDiff*yDiff);
}
}
public static void main(String[] args){
Scanner in = new Scanner(System.in);
long n = in.nextLong();
findArea(n, in);
}
} | Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | e43cddfa142d73ebc3b7b76b8ab910e7 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.util.*;
import java.lang.Math;
public class Valuable{
public static void findArea(long n, Scanner in){
long bigX = in.nextLong();
long smallX = bigX;
long bigY = in.nextLong();
long smallY = bigY;
for(int i=0; i<n-1; i++){
long nextX = in.nextLong();
long nextY = in.nextLong();
if(nextX > bigX){
bigX = nextX;
}else if(nextX < smallX){
smallX = nextX;
}
if(nextY > bigY){
bigY = nextY;
}else if(nextY < smallY){
smallY = nextY;
}
}
long xDiff = bigX - smallX;
long yDiff = bigY - smallY;
if(Math.abs(xDiff) >= Math.abs(yDiff)){
System.out.println(xDiff*xDiff);
}else{
System.out.println(yDiff*yDiff);
}
}
public static void main(String[] args){
Scanner in = new Scanner(System.in);
long n = in.nextLong();
findArea(n, in);
}
} | Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | 06f3ddeb0d10a7515964298282c6e971 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public final class ValuesResourcesCF {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(br.readLine());
int minX=Integer.MAX_VALUE,minY=Integer.MAX_VALUE;
int maxX=Integer.MIN_VALUE,maxY=Integer.MIN_VALUE;
for(int i=0;i<n;i++){
String s[]=br.readLine().split(" ");
int x=Integer.parseInt(s[0]);
int y=Integer.parseInt(s[1]);
minX=Math.min(minX,x);
maxY=Math.max(maxY,y);
maxX=Math.max(maxX,x);
minY=Math.min(minY,y);
}
/*System.out.println(minX+" "+maxY);
System.out.println(maxX+" "+minY);*/
long l=maxX-minX;
long b=maxY-minY;
long side=Math.max(l,b);
System.out.println(side*side);
}
}
| Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | adb770fb5ad54d54b6a66a22d01a5602 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 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.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
import java.util.TreeMap;
public class zizo {
public static void main(String[]args) throws IOException {
Scanner zizo=new Scanner(System.in);
PrintWriter wr=new PrintWriter(System.out);
int n=zizo.nextInt();
int a=zizo.nextInt();
int b=zizo.nextInt();
int c=zizo.nextInt();
int d=zizo.nextInt();
int x1=Math.min(a,c);
int x2=Math.max(a,c);
int y1=Math.min(d, b);
int y2=Math.max(d, b);
for(int i=0;i<n-2;i++) {
int x=zizo.nextInt();int y=zizo.nextInt();
if(x<x1)x1=x;
if(x>x2)x2=x;
if(y<y1)y1=y;
if(y>y2)y2=y;
}
// System.out.println(x1+" "+x2+" "+y1+" "+y2);
// System.out.println(Math.max(Math.abs(x1-x2),Math.abs(y1-y2)));
wr.println((long)(Math.max(x2-x1,y2-y1))*(Math.max(x2-x1,y2-y1)));
wr.close();
}
}
class edge implements Comparable<edge>{
int v,n;
edge(int a,int b){
v=a;n=b;
}
@Override
public int compareTo(edge o) {
// TODO Auto-generated method stub
return v-o.v;
}
}
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 boolean ready() throws IOException {return br.ready();}
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);
}
}
| Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | 1f3a3425545b8bb8769d307688e71186 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
public class B {
public B()
{
Scanner s = new Scanner();
long n = s.nextLong();
long xMin = Integer.MAX_VALUE;
long xMax = Integer.MIN_VALUE;
long yMin = Integer.MAX_VALUE;
long yMax = Integer.MIN_VALUE;
for (int i = 0; i < n; i++)
{
int x = s.nextInt();
int y = s.nextInt();
if (x > xMax)
xMax = x;
if (x < xMin)
xMin = x;
if (y > yMax)
yMax = y;
if (y < yMin)
yMin = y;
}
long max = Long.max(xMax - xMin, yMax - yMin);
System.out.println(max * max);
}
public static void main(String[] args) {
new B();
}
public static class Scanner {
BufferedReader br;
StringTokenizer st;
public Scanner(Reader in) {
br = new BufferedReader(in);
}
public Scanner() {
this(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());
}
// Slightly different from java.util.Scanner.nextLine(),
// which returns any remaining characters in current line,
// if any.
String readNextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
public int[] readNextLineInts(int numberOfInts) {
int[] ints = new int[numberOfInts];
for (int i = 0; i < numberOfInts; i++)
ints[i] = nextInt();
return ints;
}
public double[] readNextLineDoubles(int numberOfDoubles) {
double[] doubles = new double[numberOfDoubles];
for (int i = 0; i < numberOfDoubles; i++)
doubles[i] = nextDouble();
return doubles;
}
// --------------------------------------------------------
}
public boolean isPrime(int n)
{
for (int i = 2; i <= Math.sqrt(n);i++)
{
if (n % i == 0)
{
return false;
}
}
return true;
}
/**
* Precondition: n is at least 0
* Note: it is many times more efficient to use isPrime(int n)
* for a single or a few numbers. This method is just for a large number of
* primes and is more efficient at exactly what it does.
*
* It utilizes all previous primes to calculate all the next few primes.
* Suprisingly, isPrime is not called here due to the difference.
*
* @param n The number of primes you want.
* If n=0, an empty array is returned
* @return An array of the first n primes
*/
public ArrayList<Integer> firstNPrimes(int n)
{
ArrayList<Integer> primes = new ArrayList<Integer>();
int numToTest = 2;
while (primes.size() < n)
{
boolean prime = true;
for (int i = 0; i < primes.size() && primes.get(i) <= Math.sqrt(numToTest); i++)
{
if (numToTest % primes.get(i) == 0)
prime = false;
}
if (prime)
{
primes.add(numToTest);
System.out.println(numToTest);
}
numToTest++;
}
return primes;
}
public class Loc implements Comparable<Loc>, Cloneable
{
public int x, y;
public Loc(int x, int y)
{
this.x = x;
this.y = y;
}
public int compareTo(Loc other) {
return this.x - other.x;
}
public boolean equals(Object other)
{
return other instanceof Loc && ((Loc)other).x == this.x
&& ((Loc)other).y == this.y;
}
public Loc clone()
{
return new Loc(this.x, this.y);
}
public String toString()
{
return x + " " + y;
}
}
// public int[] largestIncreasingSubSequence()
// {
//
// }
/**
* ArrayList is NOT modified
* @param ints
* @return
*/
public ArrayList<Integer> firstIncreasingSequence(ArrayList<Integer> ints)
{
ArrayList<Integer> toReturn = new ArrayList<Integer>();
if (ints.size() == 0)
return toReturn;
toReturn.add(ints.get(0));
for (int i = 1; i < ints.size(); i++)
if (ints.get(i) > ints.get(i - 1))
toReturn.add(ints.get(i));
else
break;
return toReturn;
}
/**
* ArrayList is NOT modified
* @param ints
* @return
*/
public ArrayList<Integer> lastDecreasingSequence(ArrayList<Integer> ints)
{
ArrayList<Integer> toReturn = new ArrayList<Integer>();
if (ints.size() == 0)
return toReturn;
toReturn.add(0, ints.get(ints.size() - 1));
for (int i = ints.size() - 2; i >= 0; i--)
{
if (ints.get(i) > ints.get(i + 1))
{
toReturn.add(0, ints.get(i));
}
else
break;
}
return toReturn;
}
/**
* ArrayList is NOT modified
* @param ints
* @return
*/
public ArrayList<Integer> firstIncreasingOrEqualSequence(ArrayList<Integer> ints)
{
ArrayList<Integer> toReturn = new ArrayList<Integer>();
if (ints.size() == 0)
return toReturn;
toReturn.add(ints.get(0));
for (int i = 1; i < ints.size(); i++)
if (ints.get(i) >= ints.get(i - 1))
toReturn.add(ints.get(i));
else
break;
return toReturn;
}
public ArrayList<Integer> lastDecreasingOrEqualSequence(ArrayList<Integer> ints)
{
ArrayList<Integer> toReturn = new ArrayList<Integer>();
if (ints.size() == 0)
return toReturn;
toReturn.add(0, ints.get(ints.size() - 1));
for (int i = ints.size() - 2; i >= 0; i--)
{
if (ints.get(i) >= ints.get(i + 1))
{
toReturn.add(0, ints.get(i));
}
else
break;
}
return toReturn;
}
public class BST<T extends Comparable<? super T>>
{
class BinaryNode
{
T element; // the data in the node
BinaryNode left; // pointer to the left child
BinaryNode right; // pointer to the right child
// Initialize a childless binary node.
// Pre: elem is not null
// Post: (in the new node)
// element == elem
// left == right == null
public BinaryNode( T elem )
{
this.element = elem;
this.left = null;
this.right = null;
}
// Initialize a binary node with children.
// Pre: elem is not null
// Post: (in the new node)
// element == elem
// left == lt, right == rt
public BinaryNode( T elem, BinaryNode lt, BinaryNode rt )
{
this.element = elem;
this.left = lt;
this.right = rt;
}
/**
* Helper method to delete this node's left node, and reform left subtree according to
* project spec's description of deletion. Handles all three deletion cases:
* 1. Left node has no children: just remove it.
* 2. Left node has 1 child: replace left node with child.
* 3. Left node has 2 children: replace left node with minimum node in right subtree of left node
* Precondition, left is not null.
*/
private void removeLeft()
{
BinaryNode newLeft = null;//default; used if left has no children
if (left.right != null && left.left == null)
//left has only one (right) child or
//right.right is the leftmost node in right's right subtree
//this second case is to prevent snatchLeftMostNode from receiving
//a node for which that nodes left is null
{
newLeft = left.right;
}
else if (left.left != null && left.right == null)//left has only one (left) child
{
newLeft = left.left;
}
else if (left.left != null && left.right != null)//left has two children
{
//prevents call to .snatchLeftMostNode() from having no value in the node's left subtree
//in order to satisfy its precondition.
if (left.right.left == null)
{
newLeft = left.right;
newLeft.left = left.left;
}
else
{
newLeft = left.right.snatchLeftMostNode();
newLeft.left = left.left;
newLeft.right = left.right;
}
}
left.recycleIfAble();//regardless, attempt to recycle left
left = newLeft;//reassign pointer to point to the newLeft
//Note that this will assign null if both children of left were empty
}
/**
* Helper method to delete this node's right node, and reform right subtree according to
* project spec's description of deletion. Handles all three deletion cases:
* 1. right node has no children: just remove it.
* 2. right node has 1 child: replace right node with child.
* 3. right node has 2 children: replace right node with minimum node in right subtree of right node
* Precondition, right is not null.
*/
private void removeRight()
{
BinaryNode newRight = null;//default; used if right has no children
if (right.right != null && right.left == null)
//right has only one (right) child or
//right.right is the leftmost node in right's right subtree
{
newRight = right.right;
}
else if (right.left != null && right.right == null)//right has only one (left) child
{
newRight = right.left;
}
else if (right.right != null && right.left != null)
//right has two children
{
//prevents call to .snatchLeftMostNode() from having no value in the node's left subtree
//in order to satisfy its precondition.
if (right.right.left == null)
{
newRight = right.right;
newRight.left = right.left;
}
else//replace with minimum node in right node's subtree.
{
newRight = right.right.snatchLeftMostNode();
newRight.left = right.left;
newRight.right = right.right;
}
}
right.recycleIfAble();//regardless, attempt to recycle right
right = newRight;//reassign pointer to point to the new right node
//Note that this will assign null if both children of right were empty
}
/**
* Precondition: Node has a left child.
* Finds the minimum value Node in the left subtree of this one, removes it,
* and returns it.
* @return The removed node as described above.
*/
private BinaryNode snatchLeftMostNode()
{
if (left.left == null)//if left node has no left subtree
{
BinaryNode leftRef = left;//get a copy of reference to left
left = left.right; //works even if left.right is null.
return leftRef;
}
return left.snatchLeftMostNode();//not yet reached the end
}
/**
* This checks to see if there's room in the node pool and adds the node
* to the pool.
* Also, performs cleanup on the node by setting applicable fields to null
*/
private void recycleIfAble()
{
left = null;
element = null;
if (current_pSize < pSize)//add removed node to the node pool if there's room
{
right = pool;
pool = this;
current_pSize++;//increment node count in pool
}
else
{
right = null;
}
}
}
BinaryNode root; // pointer to root node, if present
BinaryNode pool; // pointer to first node in the pool
int pSize; // size limit for node pool
private int current_pSize; //how many nodes are currently in the node pool (added by Nathaniel Lahn)
// Initialize empty BST with no node pool.
// Pre: none
// Post: (in the new tree)
// root == null, pool == null, pSize = 0
public BST( )
{
root = null;
pool = null;
pSize = 0;
this.current_pSize = 0;
}
// Initialize empty BST with a node pool of up to pSize nodes.
// Pre: none
// Post: (in the new tree)
// root == null, pool = null, pSize == Sz
public BST( int Sz )
{
root = null;
pool = null;
pSize = Sz;
this.current_pSize = 0;
}
// Return true iff BST contains no nodes.
// Pre: none
// Post: the binary tree is unchanged
public boolean isEmpty( )
{
return root == null;
}
// Return pointer to matching data element, or null if no matching
// element exists in the BST. "Matching" should be tested using the
// data object's compareTo() method.
// Pre: x is null or points to a valid object of type T
// Post: the binary tree is unchanged
public T find( T x )
{
return this.findHelper(x, root);//call recursive method that actually does heavy lifting
}
/*
* Recursively finds node containing x
*/
private T findHelper(T x, BinaryNode current)
{
if (current == null)//reached end of tree. x is not in tree
return null;
int result = x.compareTo(current.element);
if (result < 0)//x is to the left
return findHelper(x, current.left);
else if (result > 0)//x is to the right
return findHelper(x, current.right);
else//found x
return current.element;
}
// Insert element x into BST, unless it is already stored. Return true
// if insertion is performed and false otherwise.
// Pre: x is null or points to a valid object of type T
// Post: the binary tree contains x
public boolean insert( T x )
{
//handle empty tree case separately to make recursion simpler
if (root == null)
root = getNewNode(x);
return insertHelper(x, root, null);//recursively solve
}
private boolean insertHelper(T x, BinaryNode current, BinaryNode previous)
{
int result = x.compareTo(current.element);
if (result < 0)//need to insert this somewhere to the left
{
if (current.left == null)//insert it left here since left subtree is empty
{
current.left = getNewNode(x);
return true;
}
else//still not reached end; search farther down for insertion point
{
return insertHelper(x, current.left, current);
}
}
else if (result > 0)//in
{
if (current.right == null)//insert it to the right here since right subtree is empty
{
current.right = getNewNode(x);
return true;
}
else//still not at end of tree; insert it farther down
{
return insertHelper(x, current.right, current);
}
}
else // result == 0; x is already in BST; no change is made
return false;
}
/**
* This will return a new, initialized BinaryNode, borrowing from the node pool if possible.
* @param x Data to store into the new node's element field.
* @return A valid BinaryNode object with right and left pointers null and element = x
*/
private BinaryNode getNewNode(T x)
{
BinaryNode current;
if (this.pool != null)
{
current = pool;//take current node from node pool
pool = pool.right;//set front of pool to next node.
current.right = null;//make current.right no longer point to other node pool nodes
current.element = x;
current_pSize--;
}
else //no node pool nodes to borrow from, just make a new one
{
current = new BinaryNode(x);
}
return current;
}
// Delete element matching x from the BST, if present. Return true if
// matching element is removed from the tree and false otherwise.
// Pre: x is null or points to a valid object of type T
// Post: the binary tree does not contain x
public boolean remove( T x )
{
if (root == null)//handle empty tree case; x is not here
return false;
int compareRes = x.compareTo(root.element);
if (compareRes == 0)//root node is to be removed
{
BinaryNode top = new BinaryNode(null);
top.left = root; //create temporary node above root
top.removeLeft();//remove root
root = top.left;//node that replaced old root is new root
top.left = null;//set pool back to original state
return true;
/*
* I would use the below code as it attempts to borrow the top node
* from the node pool and put it back in later, but this can create
* an extra node and screw up the node pool for the curator tests.
* Therefore, i just used the above code.
*/
// BinaryNode top = this.getNewNode(null);
// top.left = root; //create temporary node above root
// top.removeLeft();//remove root
// root = top.left;//node that replaced old root is new root
// top.left = null;//set pool back to original state
// top.recycleIfAble();
// return true;
}
return removeHelper(x, root);//the node to remove is somewhere lower than root
}
/**
* Recursively removes the node containing x and reorganizes the tree accordingly.
* Looks 2 nodes ahead for a null or a node containing x so that restructuring goes smoothly.
* @param x Data to look for.
* @param parent Parent of what is potentially the node to remove. Should never house x.
* @return whether or not an element was removed.
*/
private boolean removeHelper(T x, BinaryNode parent)
{
//parent should never be null
int result = x.compareTo(parent.element);
if (result < 0)//the goal is in the left subtree
{
if (parent.left == null)
return false; //x doesn't exist in tree
if (x.compareTo(parent.left.element) == 0)//the node to the left is the one to remove
{
parent.removeLeft();
return true;
}
return removeHelper(x, parent.left);//node to be removed is farther down
}
else if (result > 0)//goal is in right subtree
{
if (parent.right == null)
return false; //x doesn't exist in tree
if (x.compareTo(parent.right.element) == 0)//the node to the right is the one to remove
{
parent.removeRight();//parent's right node is the one to be removed
return true;
}
return removeHelper(x, parent.right);//it's somewhere farther down
}
/*
* just to satisfy compiler; should never have to run since parent should've been checked
* for equality during last iteration
*/
return false;
}
// Remove from the tree all values y such that y > x, according to
// compareTo().
// Pre: x is null or points to a valid object of type T
// Post: if the tree contains no value y such that compareTo()
// indicates y > x
public void cap( T x )
{
root = capHelper(x, root);//call recursive helper method to house more args
}
/**
* Recursively removes elements as described in cap()
* @param x Removal threshold as described in cap()
* @param current current node to check for threshold
* @return The new root of current's subtree after removals have been made.
*/
private BinaryNode capHelper( T x, BinaryNode current)
{
if (current == null)//reached end of tree
return null;
int result = current.element.compareTo(x);
/*
* if the borderline is somewhere in the left subtree,
* remove all nodes in right subtree since they are all greater than the threshold
* and proceed down left.
* current is removed too, so root of subtree changes.
* The node it changes to is returned down.
*/
if (result > 0)
{
return capHelper(x, current.left);
}
else// if current node stays, then some in right subtree might still be greater than x
{
current.right = capHelper(x, current.right);
return current;
}
}
// Return the tree to an empty state.
// Pre: none
// Post: the binary tree contains no elements
public void clear( )
{
root = null;//automagically garbage collected
}
// Return true iff other is a BST that has the same physical structure
// and stores equal data values in corresponding nodes. "Equal" should
// be tested using the data object's equals() method.
// Pre: other is null or points to a valid BST<> object, instantiated
// on the same data type as the tree on which equals() is invoked
// Post: both binary trees are unchanged
@SuppressWarnings("unchecked")
public boolean equals(Object other)
{
if (other == null)//the fact that this method is running means "this" is not null
return false;
/*
* check to make sure it's the same class
* doesn't use instanceof because it doesn't necessarily work with generics
*/
if (!this.getClass().equals(other.getClass()))
return false;
return equalsHelper(this.root, ((BST<T>)other).root);//recursively check all nodes
}
/**
* Recursively checks all nodes in tree for equality
* @param current1 Reference to node in tree one
* @param current2 Reference to node in tree two in same relative location
* @return Whether or not subtrees are equal
*/
private boolean equalsHelper(BinaryNode current1, BinaryNode current2)
{
if (current1 == null && current2 == null)//reached end of branch on both trees
return true;
//if current nodes not equal in elements, return false
if ((current1 == null && current2 != null) ||
(current1 != null && current2 == null) ||
!current1.element.equals(current2.element))
return false;
return equalsHelper(current1.left, current2.left) && //if current nodes are equal, check children
equalsHelper(current1.right, current2.right);
}
// Return number of levels in the tree. (An empty tree has 0 levels.)
// Pre: tree is a valid BST<> object
// Post: the binary tree is unchanged
public int levels()
{
return levelsHelper(root);
}
/**
* Recursively calculates number of levels in subtree of current.
* @param current
* @return
*/
private int levelsHelper(BinaryNode current)
{
if (current == null)//base case, depth of this subtree is 0
return 0;
//return maximum length of the two subtrees and add one for the current node
return Integer.max(levelsHelper(current.left), levelsHelper(current.right)) + 1;
}
}}
| Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | 2aaef2985f223b8f3b62966119f006c9 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.util.*;
public class B {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int xmin = Integer.MAX_VALUE, ymin = Integer.MAX_VALUE,
xmax = Integer.MIN_VALUE, ymax = Integer.MIN_VALUE;
for (int i=1;i<=n;i++) {
int x = in.nextInt(), y = in.nextInt();
xmin = Math.min(xmin,x);
xmax = Math.max(xmax,x);
ymin = Math.min(ymin,y);
ymax = Math.max(ymax,y);
}
long ans = Math.max(xmax-xmin,ymax-ymin);
System.out.println(ans*ans);
}
}
| Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | b0ff06a813059fd19d0ac2a097fddd86 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes |
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
public class Main {
static class FastScanner{
BufferedReader s;
StringTokenizer st;
public FastScanner(){
st = new StringTokenizer("");
s = new BufferedReader(new InputStreamReader(System.in));
}
public FastScanner(File f) throws FileNotFoundException{
st = new StringTokenizer("");
s = new BufferedReader (new FileReader(f));
}
public int nextInt() throws IOException{
if(st.hasMoreTokens())
return Integer.parseInt(st.nextToken());
else{
st = new StringTokenizer(s.readLine());
return nextInt();
}
}
public double nextDouble() throws IOException{
if(st.hasMoreTokens())
return Double.parseDouble(st.nextToken());
else{
st = new StringTokenizer(s.readLine());
return nextDouble();
}
}
public long nextLong() throws IOException{
if(st.hasMoreTokens())
return Long.parseLong(st.nextToken());
else{
st = new StringTokenizer(s.readLine());
return nextLong();
}
}
public String nextString() throws IOException{
if(st.hasMoreTokens())
return st.nextToken();
else{
st = new StringTokenizer(s.readLine());
return nextString();
}
}
public String readLine() throws IOException{
return s.readLine();
}
public void close() throws IOException{
s.close();
}
}
private static FastScanner s = new FastScanner();
private static PrintWriter ww = new PrintWriter(new OutputStreamWriter(System.out));
static int count=0;
public static void main(String[] args) throws IOException
{
TreeSet<Integer> hmx = new TreeSet<Integer>();
TreeSet<Integer> hmy = new TreeSet<Integer>();
int n= s.nextInt();
for(int i=0;i<n;i++)
{
hmx.add(s.nextInt()); hmy.add(s.nextInt());
}
long y1 = Long.parseLong(Collections.max(hmy).toString());
long y2 = Long.parseLong(Collections.min(hmy).toString());
long x1 = Long.parseLong(Collections.max(hmx).toString());
long x2 = Long.parseLong(Collections.min(hmx).toString());
long diff =(Math.max(x1-x2, y1-y2));
long area =(diff*diff);
//ww.println(" max x is "+x1+" min x is "+x2);
//ww.println(" max y is "+y1+" min y is "+y2);
ww.println(area);
s.close();
ww.close();
}
public static int gcd(int a, int b){
return b == 0 ? a : gcd(b,a%b);
}
}
/*zabardast swappimng of sorting
/*
for(int h=0;h<n;h++)
{ int temp,temp1,temp2;
for(int y=h+1;y<n;y++)
{
if(a[y][2]>=a[h][2])
{
temp=a[y][2]; //////sorting
a[y][2]=a[h][2];
a[h][2]=temp;
temp1=a[y][0];
a[y][0]=a[h][0];
a[h][0]=temp1;
temp2=a[y][1];
a[y][1]=a[h][1];
a[h][1]=temp2;
}
}
}
*/
/*
static final Point getMinMax(int[] array) {
int min = array[0];
int max = array[0];
for (int index = 0, size = array.length; index < size; ++index, ++index) {
int value = array[index];
if (index == size - 1) {
min = min(min, value);
max = max(max, value);
} else {
int otherValue = array[index + 1];
if (value <= otherValue) {
min = min(min, value);
max = max(max, otherValue);
} else {
min = min(min, otherValue);
max = max(max, value);
}
}
}
return new Point(min, max);
}
*/
/*
/// Demonstrate several Is... methods.
class IsDemo {
public static void main(String args[]) {
char a[] = {'a', 'b', '5', '?', 'A', ' '};
for(int i=0; i<a.length; i++) {
if(Character.isDigit(a[i])) ///check if digit is present in string
System.out.println(a[i] + " is a digit.");
if(Character.isLetter(a[i]))
System.out.println(num + " in binary: " +
Integer.toBinaryString(num));
System.out.println(num + " in octal: " +
Integer.toOctalString(num));
System.out.println(num + " in hexadecimal: " +
Integer.toHexString(num));
}
}
*/ | Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | 60974e2bd140f78953f5229c423c805c | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.awt.Point;
import java.io.BufferedOutputStream;
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.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.SortedSet;
import java.util.StringTokenizer;
import java.util.TreeSet;
/**
* @author Jens Staahl
*/
public class Prac {
// some local config
// static boolean test = false ;
private boolean test = System.getProperty("ONLINE_JUDGE") == null;
static String testDataFile = "testdata.txt";
// static String testDataFile = "testdata.txt";
private static String ENDL = "\n";
// Just solves the acutal kattis-problem
ZKattio io;
private void solve() throws Throwable {
io = new ZKattio(stream);
int n = io.getInt();
long minx = 1 << 62, miny = 1 << 62, maxx = Long.MIN_VALUE, maxy = Long.MIN_VALUE;
for (int i = 0; i < n; i++) {
long x = io.getInt(), y = io.getInt();
minx = Math.min(x, minx);
maxx = Math.max(x, maxx);
miny = Math.min(y, miny);
maxy = Math.max(y, maxy);
}
System.out.println(Math.max((maxx - minx)*(maxx - minx), (maxy - miny) * (maxy - miny)));
}
public static void main(String[] args) throws Throwable {
new Prac().solve();
}
public Prac() throws Throwable {
if (test) {
stream = new FileInputStream(testDataFile);
}
}
InputStream stream = System.in;
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));// outStream
public class ZKattio extends PrintWriter {
public ZKattio(InputStream i) {
super(new BufferedOutputStream(System.out));
r = new BufferedReader(new InputStreamReader(i));
}
public ZKattio(InputStream i, OutputStream o) {
super(new BufferedOutputStream(o));
r = new BufferedReader(new InputStreamReader(i));
}
public boolean hasMoreTokens() {
return peekToken() != null;
}
public int getInt() {
return Integer.parseInt(nextToken());
}
public double getDouble() {
return Double.parseDouble(nextToken());
}
public long getLong() {
return Long.parseLong(nextToken());
}
public String getWord() {
return nextToken();
}
private BufferedReader r;
private String line;
private StringTokenizer st;
private String token;
private String peekToken() {
if (token == null)
try {
while (st == null || !st.hasMoreTokens()) {
line = r.readLine();
if (line == null)
return null;
st = new StringTokenizer(line);
}
token = st.nextToken();
} catch (IOException e) {
}
return token;
}
private String nextToken() {
String ans = peekToken();
token = null;
return ans;
}
}
// System.out;
} | Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | f2345d8a0a4ed3ffc2f5cd9bc4aa4460 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.util.*;
public class name{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
TreeSet<Long> x = new TreeSet<Long>();
TreeSet<Long> y = new TreeSet<Long>();
for (int i=1; i<=n; i++) {
x.add(scan.nextLong());
y.add(scan.nextLong());
}
long height=x.last()-x.first();
long width=y.last()-y.first();
if(height>width)
{
System.out.println(height*height);
}
else
{
System.out.println(width*width);
}
}
} | Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | 04e0a8a7ee71f1e4eb3b8b8cc05a4518 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
MyScanner sc = new MyScanner();
int n = sc.nextInt();
long[] x = new long[n];
long[] y = new long[n];
for (int i = 0; i < n; i++) {
x[i] = sc.nextLong();
y[i] = sc.nextLong();
}
long min_x = 10000000001L;
long min_y = 10000000001L;
long max_x = -10000000001L;
long max_y = -10000000001L;
long area = 0;
for (int i = 0; i < n; i++) {
if (x[i] < min_x) min_x = x[i];
if (y[i] < min_y) min_y = y[i];
if (x[i] > max_x) max_x = x[i];
if (y[i] > max_y) max_y = y[i];
}
if ((max_x - min_x) > (max_y - min_y)) area = (max_x - min_x)*(max_x - min_x);
else area = (max_y - min_y) * (max_y - min_y);
System.out.println(area);
}
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
String nextLine() {
String str = "";
try { str = br.readLine(); }
catch (IOException e) { e.printStackTrace(); }
return str;
}
}
} | Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | dc769c86d57097073abb397213ed2820 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
long l = 0, r = 0, t = 0, b = 0;
for(int i = 0; i < n; ++i) {
long x = in.nextLong();
long y = in.nextLong();
if(i == 0) {
l = x;
r = x;
t = y;
b = y;
}
else {
if(y < b) b = y;
if(y > t) t = y;
if(x < l) l = x;
if(x > r) r = x;
}
}
long width = r - l;
long height = t - b;
long s = (width < height) ? (height * height) : (width * width);
System.out.println(s);
}
} | Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | a8daea68fa2566d459be36031a8e6d41 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class ValuableResources {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
long maxx = Long.MIN_VALUE;
long maxy=Long.MIN_VALUE;
long minx=Long.MAX_VALUE;
long miny=Long.MAX_VALUE;
for (int i = 0; i < n; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
long x = Long.parseLong(st.nextToken());
long y= Long.parseLong(st.nextToken());
maxx = Math.max(x, maxx);
maxy = Math.max(y, maxy);
minx = Math.min(x, minx);
miny = Math.min(y, miny);
}
long res =(long)Math.max(maxx-minx, maxy-miny);
System.out.println((long)res*(long)res);
}
}
| Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | 9c167fc1eba44408c7d8ae6839ae2f64 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 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.StringTokenizer;
public class CF485B {
public static void main(String[] args) {
FastReader input = new FastReader();
PrintWriter pw = new PrintWriter(System.out);
int n = input.nextInt();
long minX = Integer.MAX_VALUE;
long maxX = Integer.MIN_VALUE;
long minY = Integer.MAX_VALUE;
long maxY = Integer.MIN_VALUE;
for(int i = 0;i < n;i++){
long x = input.nextLong();
long y = input.nextLong();
minX = Math.min(minX,x);
maxX = Math.max(maxX,x);
minY = Math.min(minY,y);
maxY = Math.max(maxY,y);
}
long max = Math.max((maxX - minX),(maxY - minY));
pw.println(max * max);
pw.flush();
pw.close();
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}
| Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | 70724c65dee82f3b15cecf01d79ca532 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class Valuable_Resources {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
long area = 0;
int n = in.nextInt();
int arrX[] = new int[n];
int arrY[] = new int[n];
for (int i = 0; i < n; i++) {
arrX[i] = in.nextInt();
arrY[i] = in.nextInt();
}
Arrays.sort(arrX);
Arrays.sort(arrY);
area = Math.max(Math.abs(arrX[0]-arrX[n-1]),
Math.abs(arrY[0]-arrY[n-1]));
System.out.println(area*area);
}
}
| Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | 9e859d284af17990a9beea7cc0568a82 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.util.*;
public class MyClass {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=1;
while(t-->0) {
long n=sc.nextInt();
long minx=Long.MAX_VALUE;
long maxx=Long.MIN_VALUE;
long miny=Long.MAX_VALUE;
long maxy=Long.MIN_VALUE;
long ans;
for(int i=1;i<=n;i++) {
long x=sc.nextInt();
long y=sc.nextInt();
minx=Math.min(minx, x);
miny=Math.min(miny, y);
maxx=Math.max(maxx, x);
maxy=Math.max(maxy, y);
}
ans=Math.max(maxx-minx, maxy-miny);
System.out.println((long)ans*ans);
}
}
}
| Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | 75e5a1486678c43642721623d3d35c92 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 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 Codeforces;
/**
*
* @author Administrator
*/
import java.util.Scanner;
public class c485B {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
long maxx = -1000000001,minx = 1000000001,maxy = -1000000001, miny = 1000000001;
long x,y;
for (int i = 1; i <= n; i++) {
x = in.nextLong();
y = in.nextLong();
maxx = Math.max(maxx, x);
minx = Math.min(minx, x);
maxy = Math.max(maxy, y);
miny = Math.min(miny, y);
}
System.out.println(Math.max((maxx-minx)*(maxx-minx),(maxy-miny)*(maxy-miny)));
}
}
| Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | f95c98aefd00a12fcf43aa03d59938f7 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.StringTokenizer;
public class SRM {
static class Point {
long x, y;
Point(long x, long y){
this.x = x;
this.y = y;
}
}
public static void main(String[] args) throws IOException {
MyScanner sc = new MyScanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
StringTokenizer st;
int n = sc.nextInt();
Point pos [] = new Point[n];
for(int i = 0;i < n;++i){
pos[i] = new Point(sc.nextLong(), sc.nextLong());
}
long maxX = Integer.MIN_VALUE;
long maxY = Integer.MIN_VALUE;
long minX = Integer.MAX_VALUE;
long minY = Integer.MAX_VALUE;
for(int i = 0;i < pos.length;i++){
if (maxX < pos[i].x)
maxX = pos[i].x;
if (minX > pos[i].x)
minX = pos[i].x;
if (maxY < pos[i].y)
maxY = pos[i].y;
if (minY > pos[i].y)
minY = pos[i].y;
}
//pw.println("Max X " + maxX);
//pw.println("Min X " + minX);
//pw.println("Max Y " + maxY);
//pw.println("Min Y " + minY);
long ans = Math.max(maxX - minX, maxY - minY);
ans = ans * ans;
pw.println(ans);
/*boolean hasNeg = false;
for(int i = 0;i < pos.length;++i){
if (maxX < Math.abs(pos[i].x))
maxX = Math.abs(pos[i].x);
if (maxY < Math.abs(pos[i].y))
maxY = Math.abs(pos[i].y);
if (pos[i].x < 0 || pos[i].y < 0)
hasNeg = true;
}
BigInteger max = BigInteger.valueOf(Math.max(maxX, maxY));
if (hasNeg)
max = max.multiply(BigInteger.valueOf(2));
BigInteger ans = max.multiply(max);
pw.println(ans);*/
pw.close();
}
static class MyScanner {
StringTokenizer st;
BufferedReader br;
public MyScanner(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\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | bef28e5c2e9b05e6288421fbefd6b782 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
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);
try (PrintWriter out = new PrintWriter(outputStream)) {
TaskB solver = new TaskB();
solver.solve(1, in, out);
}
}
}
class TaskB {
public void solve(int testNumber, InputReader in, PrintWriter out) {
long n = in.nextLong();
long xmax = -1000000001;
long xmin = 1000000001;
long ymax = -1000000001;
long ymin = 1000000001;
for(int i = 0; i < n; ++i){
long x = in.nextLong();
long y = in.nextLong();
if(xmin > x) xmin = x;
if(xmax < x) xmax = x;
if(ymin > y) ymin = y;
if(ymax < y) ymax = y;
}
long xlen = Math.abs(xmax - xmin);
long ylen = Math.abs(ymax - ymin);
long maxl = Math.max(xlen, ylen);
out.println(maxl*maxl);
}
}
class InputReader {
private final BufferedReader reader;
private StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String nextLine() {
try {
return reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(nextLine());
}
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 | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | 5084f1942cb8ab788c0cc2e2dc4cced8 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
// while(true){
int number = input.nextInt();
location[] array = new location[number];
for(int i= 0 ; i < number ; i++){
array[i] = new location(input.nextInt(), input.nextInt());
}
long max = Integer.MIN_VALUE;
for(int i = 0 ; i < array.length ; i++){
for(int j = i+1 ; j < array.length ; j++){
long temp = Integer.MIN_VALUE;
if(Math.abs(array[j].y - array[i].y) > Math.abs(array[j].x - array[i].x)){
temp = Math.abs(array[j].y - array[i].y);
}
else{
temp = Math.abs(array[j].x - array[i].x);
}
if(temp > max ){
max = temp;
}
}
}
System.out.println(max*max);
//}
}
}
class location {
int x;
int y;
public location(int x , int y){
this.x =x;
this.y = y;
}
}
| Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | 7a97559328fe3e7efc265ab0f0fbb639 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.util.Scanner;
/**
* Created by vignesh on 5/5/2017.
*/
public class valuable_Resources {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
long x1 = in.nextLong();
long y1 = in.nextLong();
long xmax = x1;
long xmin = x1;
long ymax = y1;
long ymin = y1;
for (int i = 0; i < n - 1; i++) {
long x = in.nextLong();
long y = in.nextLong();
xmax = Math.max(x, xmax);
xmin = Math.min(x, xmin);
ymax = Math.max(y, ymax);
ymin = Math.min(y, ymin);
}
long s = Math.max((xmax-xmin),(ymax-ymin));
System.out.println(s*s);
}
}
| Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | 355fda7d3fa0137b3a97c5224b062c96 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.io.*;
import java.util.StringTokenizer;
import static java.util.Arrays.*;
public class Main {
void solve() throws IOException {
int n = nextInt();
int[] x = new int[n];
int[] y = new int[n];
long minX = Integer.MAX_VALUE, minY = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE, maxY = Integer.MIN_VALUE;
for (int i = 0; i < n; i++) {
x[i] = nextInt();
y[i] = nextInt();
if (x[i] < minX)
minX = x[i];
if (x[i] > maxX)
maxX = x[i];
if (y[i] < minY)
minY = y[i];
if (y[i] > maxY)
maxY = y[i];
}
long ans = Math.max(maxX - minX, maxY - minY) * Math.max(maxX - minX, maxY - minY);
// if (ans == 0)
// ans = Math.max(maxX - minX, maxY - minY);
out.println(ans);
}
class MultiList {
int[] head, next, dest;
int en;
MultiList(int vNum, int eNum) {
head = new int[vNum];
next = new int[eNum + 1];
dest = new int[eNum + 1];
clearGraph();
}
void clearGraph() {
fill(head, -1);
en = 0;
}
void addEdge(int u, int v) {
dest[en] = v;
next[en] = head[u];
head[u] = en;
en++;
}
}
int gcd(int a, int b) {
return (b == 0) ? a : gcd(b, a % b);
}
int lcm(int a, int b) {
return a / gcd(a, b) * b;
}
int modulo(int x, int y) {
return (x % y + y) % y;
}
public static void main(String[] args) throws IOException {
new Main().run();
}
final String fileIn = "input.txt";
final String fileOut = "output.txt";
BufferedReader in;
PrintWriter out;
StringTokenizer st = new StringTokenizer("");
private void run() throws IOException {
if (new File(fileIn).exists())
in = new BufferedReader(new FileReader(fileIn));
else
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
// out = new PrintWriter(new FileWriter(fileOut));
solve();
in.close();
out.close();
}
String nextToken() throws IOException {
while (!st.hasMoreTokens())
st = new StringTokenizer(in.readLine());
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
String nextString() throws IOException {
st = new StringTokenizer("");
return in.readLine();
}
boolean EOF() throws IOException {
while (!st.hasMoreTokens()) {
String s = in.readLine();
if (s == null)
return true;
st = new StringTokenizer(s);
}
return false;
}
}
| Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | 61e84619242cdc38fa0d91c8ad1bd679 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.Vector;
public class Main {
public static void main(String[] args) throws IOException{
FastScanner sc = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int n = sc.nextInt();
long ans =0L;
long x =0 ;
long y =0 ;
int minx =Integer.MAX_VALUE;
int maxx =Integer.MIN_VALUE;
int miny =Integer.MAX_VALUE;
int maxy =Integer.MIN_VALUE;
for(int i=0;i<n;i++){
int xx = sc.nextInt();
int yy =sc.nextInt();
minx = Math.min(minx, xx);
maxx = Math.max(maxx, xx);
miny = Math.min(miny, yy);
maxy = Math.max(maxy, yy);
}
long c1 = maxx-minx;
long c2 = maxy-miny;
long c3 =Math.max(c1, c2);
System.out.println(c3*c3);
}
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[r];
a[r] = a[i];
a[i] = tmp;
}
}
static void generate(int[] p, int L, int R) {
if (L == R) {
}else {
for (int i = L; i <= R; i++) {
int tmp = p[L]; p[L] = p[i]; p[i] = tmp;//swap
generate(p, L+1, R);//recurse
tmp = p[L]; p[L] = p[i]; p[i] = tmp;//unswap
}
}
}
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastScanner(String s) {
try {
br = new BufferedReader(new FileReader(s));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
String nextToken() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(nextToken());
}
long nextLong() {
return Long.parseLong(nextToken());
}
double nextDouble() {
return Double.parseDouble(nextToken());
}
}
| Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | 983bee8f941312ca01667d63b13e4b7e | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.StringTokenizer;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author saket
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
VariableResources solver = new VariableResources();
solver.solve(1, in, out);
out.close();
}
}
class VariableResources {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int n=in.readInt();
long a[]=new long[n];
long b[]=new long[n];
for(int i=0;i<n;i++)
{
a[i]=in.readLong();
b[i]=in.readLong();
}
Arrays.sort(a);
Arrays.sort(b);
long ans=Math.max(Math.abs(a[n-1]-a[0]),Math.abs(b[n-1]-b[0]));
out.printLine(ans*ans);
}
}
class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int readInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public long readLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0)
writer.print(' ');
writer.print(objects[i]);
}
}
public void printLine(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
}
| Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | 1c56ec8d485e90909e4871b944cdfb78 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.util.Scanner;
import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;
public class TestClass //implements Runnable
{
int x,y;
public TestClass(int x,int y)
{
this.x=x;
this.y=y;
}
public static void main(String args[]) throws Exception
{/*
new Thread(null, new TestClass(),"TESTCLASS",1<<23).start();
}
public void run()
{*/
//Scanner scan=new Scanner(System.in);
InputReader hb=new InputReader(System.in);
PrintWriter w=new PrintWriter(System.out);
int n=hb.nextInt();
long minX=Long.MAX_VALUE;
long maxX=Long.MIN_VALUE;
long minY=Long.MAX_VALUE;
long maxY=Long.MIN_VALUE;
for(int i=0;i<n;i++)
{
int x=hb.nextInt();
int y=hb.nextInt();
if(x<minX)
minX=x;
if(x>maxX)
maxX=x;
if(y<minY)
minY=y;
if(y>maxY)
maxY=y;
}
long lengthX=maxX-minX;
long lengthY=maxY-minY;
long ans=Math.max(lengthX,lengthY);
w.print(ans*ans);
w.close();
}
static class DSU
{
int parent[];
int sizeParent[];
DSU(int n)
{
parent=new int[n];
sizeParent=new int[n];
Arrays.fill(sizeParent,1);
for(int i=0;i<n;i++)
parent[i]=i;
}
int find(int x)
{
if(x!=parent[x])
parent[x]=find(parent[x]);
return parent[x];
}
void union(int x,int y)
{
x=find(x);
y=find(y);
if(sizeParent[x]>=sizeParent[y])
{
if(x!=y)
sizeParent[x]+=sizeParent[y];
parent[y]=x;
}
else
{
if(x!=y)
sizeParent[y]+=sizeParent[x];
parent[x]=y;
}
}
}
static class InputReader
{
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream)
{
this.stream = stream;
}
public int read()
{
if (numChars==-1)
throw new InputMismatchException();
if (curChar >= numChars)
{
curChar = 0;
try
{
numChars = stream.read(buf);
}
catch (IOException e)
{
throw new InputMismatchException();
}
if(numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine()
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
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);
}
}
static class Pair implements Comparable<Pair>
{
int a;
int b;
String str;
public Pair(int a,int b)
{
this.a=a;
this.b=b;
str=min(a,b)+" "+max(a,b);
}
public int compareTo(Pair pair)
{
if(Integer.compare(a,pair.a)==0)
return Integer.compare(b,pair.b);
return Integer.compare(a,pair.a);
}
}
} | Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | da1e4648c9276a4da65368ba73fa59bb | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.util.Scanner;
public class _2
{
public static void main(String[] args)
{
int n;
Scanner input =new Scanner(System.in);
n=input.nextInt();
int x1=-1000000000,x2=1000000000,y1=-1000000000,y2=1000000000;
int a,b;
while(n!=0)
{
a=input.nextInt();
b=input.nextInt();
x1=Math.max(a,x1);
x2=Math.min(a,x2);
y1=Math.max(y1,b);
y2=Math.min(y2,b);
n--;
}
int length= Math.max((x1-x2),(y1-y2));
System.out.print((long)length*length);
}
} | Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 8 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | 7e74b631c537e3af97b64a70092071b6 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;
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();
}
}
class TaskB {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
long up, down, left, right;
up = right = Long.MIN_VALUE;
down = left = Long.MAX_VALUE;
for (int i = 0; i < n; ++i) {
long x = in.nextLong();
long y = in.nextLong();
left = Math.min(left, x);
right = Math.max(right, x);
up = Math.max(up, y);
down = Math.min(down, y);
}
long edge = Math.max(up - down,right - left);
out.println(edge*edge);
}
}
class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
} | Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 6 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | ede1fa9ed6924185ba2d539402f047f2 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.StringTokenizer;
public class T485B {
public static void main(String[] args) {
FastScanner in = new FastScanner();
int n = in.nextInt();
int[][] p = new int[n][2];
for (int i = 0; i < n; i ++) {
p[i][0] = in.nextInt();
p[i][1] = in.nextInt();
}
int maxx = 0, maxy = 0;
for (int i = 0; i < n; i ++) {
for (int j = i + 1; j < n; j ++) {
maxx = Math.max(maxx, Math.abs(p[i][0] - p[j][0]));
maxy = Math.max(maxy, Math.abs(p[i][1] - p[j][1]));
}
}
BigInteger ans = new BigInteger(String.valueOf(Math.max(maxx, maxy)))
.multiply(new BigInteger(String.valueOf(Math.max(maxx, maxy))));
System.out.println(ans);
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(String s) {
try {
br = new BufferedReader(new FileReader(s));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String nextToken() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(nextToken());
}
long nextLong() {
return Long.parseLong(nextToken());
}
double nextDouble() {
return Double.parseDouble(nextToken());
}
}
}
| Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 6 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | 0f77a40568b72c695e1d9aed58d54249 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.util.Scanner;
public class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long min_x = sc.nextLong(), min_y = sc.nextLong();
long max_x = min_x, max_y = min_y;
for(int i = 1; i < n; i++)
{
long x = sc.nextLong(), y = sc.nextLong();
if(x < min_x)
min_x = x;
else if(x > max_x)
max_x = x;
if(y < min_y)
min_y = y;
else if(y > max_y)
max_y = y;
}
sc.close();
System.out.print((max_x - min_x > max_y - min_y)?(max_x - min_x)*(max_x - min_x):(max_y - min_y)*(max_y - min_y));
}
}
| Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 6 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | ecb73f9d10ae28ab73ab036285127441 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class MainB {
MyScanner sc = new MyScanner();
Scanner sc2 = new Scanner(System.in);
final int MOD = 1000000007;
int[] dx = { 1, 0, 0, -1 };
int[] dy = { 0, 1, -1, 0 };
void run() {
int n = sc.nextInt();
int x[] = new int[n];
int y[] = new int[n];
for (int i = 0; i < n; i++) {
x[i] = sc.nextInt();
y[i] = sc.nextInt();
}
Arrays.sort(x);
Arrays.sort(y);
long maxX = x[x.length - 1] - x[0];
long maxY = y[y.length - 1] - y[0];
long max = Math.max(maxX, maxY);
System.out.println(max * max);
}
public static void main(String[] args) {
new MainB().run();
}
void debug(Object... o) {
System.out.println(Arrays.deepToString(o));
}
void debug2(int[][] array) {
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
System.out.print(array[i][j]);
}
System.out.println();
}
}
boolean inner(int h, int w, int lim) {
return 0 <= h && h < lim && 0 <= w && w < lim;
}
void swap(int[] x, int a, int b) {
int tmp = x[a];
x[a] = x[b];
x[b] = tmp;
}
// find minimum i (a[i] >= border)
int lower_bound(int a[], int border) {
int l = -1;
int r = a.length;
while (r - l > 1) {
int mid = (l + r) / 2;
if (border <= a[mid]) {
r = mid;
} else {
l = mid;
}
}
// r = l + 1
return r;
}
class MyScanner {
int nextInt() {
try {
int c = System.in.read();
while (c != '-' && (c < '0' || '9' < c))
c = System.in.read();
if (c == '-')
return -nextInt();
int res = 0;
do {
res *= 10;
res += c - '0';
c = System.in.read();
} while ('0' <= c && c <= '9');
return res;
} catch (Exception e) {
return -1;
}
}
double nextDouble() {
return Double.parseDouble(next());
}
long nextLong() {
return Long.parseLong(next());
}
String next() {
try {
StringBuilder res = new StringBuilder("");
int c = System.in.read();
while (Character.isWhitespace(c))
c = System.in.read();
do {
res.append((char) c);
} while (!Character.isWhitespace(c = System.in.read()));
return res.toString();
} catch (Exception e) {
return null;
}
}
int[] nextIntArray(int n) {
int[] in = new int[n];
for (int i = 0; i < n; i++) {
in[i] = nextInt();
}
return in;
}
int[][] nextInt2dArray(int n, int m) {
int[][] in = new int[n][m];
for (int i = 0; i < n; i++) {
in[i] = nextIntArray(m);
}
return in;
}
double[] nextDoubleArray(int n) {
double[] in = new double[n];
for (int i = 0; i < n; i++) {
in[i] = nextDouble();
}
return in;
}
long[] nextLongArray(int n) {
long[] in = new long[n];
for (int i = 0; i < n; i++) {
in[i] = nextLong();
}
return in;
}
}
}
| Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 6 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | bbaea76a18659850820f3b9f5c63592b | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.util.Scanner;
public class CodeforcesContest485B {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
long minX=Long.MAX_VALUE;
long maxX=Long.MIN_VALUE;
long minY=Long.MAX_VALUE;
long maxY=Long.MIN_VALUE;
for(int i=1;i<=n;i++){
long x=sc.nextLong();
long y=sc.nextLong();
if(minX>x) minX =x;
if(maxX<x) maxX=x;
if(minY>y) minY =y;
if(maxY<y) maxY=y;
}
long a=maxX-minX;
long b=maxY-minY;
long max=(a>b)?a:b;
System.out.println(max*max);
}
}
| Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 6 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | e82cceed5f34ea1b4717638df9de68d8 | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) throws NumberFormatException,
IOException {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
long maxY = Long.MIN_VALUE;
long maxX = Long.MIN_VALUE;
long minY = Long.MAX_VALUE;
long minX = Long.MAX_VALUE;
for (int i = 0; i < n; i++) {
Long xi = s.nextLong();
Long yi = s.nextLong();
maxY = Math.max(yi, maxY);
maxX = Math.max(xi, maxX);
minY = Math.min(yi, minY);
minX = Math.min(xi, minX);
}
long fir = Math.abs(minY - maxY);
long sec = Math.abs(minX - maxX);
long getMax = Math.max(fir, sec);
long square = getMax * getMax;
System.out.println(square);
}
} | Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 6 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | e134abc0ad256835b2898c320ded0d7d | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.util.Scanner;
public class CF276B {
public static void main(final String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int xmin = Integer.MAX_VALUE, xmax = Integer.MIN_VALUE, ymin = Integer.MAX_VALUE, ymax = Integer.MIN_VALUE;
for (int i = 0; i < n; i++) {
int x = sc.nextInt();
int y = sc.nextInt();
xmin = Math.min(xmin, x);
xmax = Math.max(xmax, x);
ymin = Math.min(ymin, y);
ymax = Math.max(ymax, y);
}
int xdist = Math.abs(xmin - xmax);
int ydist = Math.abs(ymin - ymax);
long dist = Math.max(xdist, ydist);
System.out.println(dist * dist);
}
}
| Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 6 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | f531740cbd447bd2769d9d56883f308d | train_001.jsonl | 1415205000 | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | 256 megabytes | import java.util.*;
public class R276_2_B {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n, x, y, minx, maxx, miny, maxy;
n= in.nextInt();
minx = miny = Integer.MAX_VALUE;
maxx = maxy = Integer.MIN_VALUE;
for (int i = 0; i < n; i++) {
x = in.nextInt(); y = in.nextInt();
if (x > maxx) maxx = x;
if (x < minx) minx = x;
if (y > maxy) maxy = y;
if (y < miny) miny = y;
}
long max = Math.max(maxx-minx, maxy-miny);
System.out.println(max * max);
}
} | Java | ["2\n0 0\n2 2", "2\n0 0\n0 3"] | 1 second | ["4", "9"] | null | Java 6 | standard input | [
"greedy",
"brute force"
] | 016e00b2b960be792d4ec7fcfb7976e2 | The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct. | 1,300 | Print the minimum area of the city that can cover all the mines with valuable resources. | standard output | |
PASSED | 0b9e9f8af9223ea16a858c5e9e6d9048 | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes | // Working program using Reader Class
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Div3
{
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
public static void main(String[] args) throws IOException
{
Reader s=new Reader();
//int test=s.nextInt();
int n=s.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=s.nextInt();
}
int ans=0;
for(int i=1;i<n-1;i++)
{
if(a[i]==0&&a[i-1]==1&&a[i+1]==1)
{
ans++;
a[i+1]=0;
}
}
System.out.println(ans);
}
}
| Java | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output | |
PASSED | 9be060ba060dc66f5bfe3d2c1f40f1d0 | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes | // problem - https://codeforces.com/problemset/problem/1077/B
import java.util.Scanner;
import java.util.ArrayList;
public class Solution {
private static final String DISTURBED_STATE = "101";
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
StringBuilder stateOfLight = new StringBuilder();
int n = scanner.nextInt();
int k = 0;
for(int i=0; i<n; i++) {
stateOfLight.append(String.valueOf(scanner.nextInt()));
}
String lightState = stateOfLight.toString();
if(lightState.contains(DISTURBED_STATE)) {
for(int i=0; i<lightState.length()-2; i++) {
if(lightState.subSequence(i, i+3).equals(DISTURBED_STATE)) {
//System.out.println((i+1)+" "+k+" "+lightState.subSequence(i, i+3));
i+=2;
//System.out.println(lightState.subSequence((i), i+3));
k++;
}
}
} else {
k = 0;
System.out.println(k);
System.exit(0);
}
System.out.println(k);
scanner.close();
}
} | Java | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output | |
PASSED | d6649cc0e277e8993f7502f6261758fe | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
public class Disturbing {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(bufferedReader.readLine());
StringTokenizer stringTokenizer = new StringTokenizer(bufferedReader.readLine());
List<Integer> nums = new ArrayList<>();
for (int i = 0; i < n; i++) {
nums.add(Integer.parseInt(stringTokenizer.nextToken()));
}
int res = 0;
for (int i = 1; i < nums.size() - 1; i++) {
if (nums.get(i) == 0 && nums.get(i - 1) == 1 && nums.get(i + 1) == 1) {
res++;
nums.set(i + 1, 0);
}
}
System.out.println(res);
}
}
| Java | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output | |
PASSED | e48067434fb584674f68af78931fa24a | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes | import java.util.Scanner;
public class Run {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int tenants[] = new int[n];
for (int i = 0; i < n; i++) {
tenants[i] = sc. nextInt();
}
int res = 0;
for (int i = 1; i < n-1; i++) {
if(tenants[i] == 0 && tenants[i - 1] == 1 && tenants[i + 1] == 1){
res++;
tenants[i+1] = 0;
}
}
System.out.println(res);
}
} | Java | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output | |
PASSED | c4f962dd73dcc38b6bb5df4e10f5cac2 | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes | import java.util.Scanner;
public class Disturbed
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int A[] = new int[n];
int disturbes_how_many[] = new int[n];
for (int i = 0; i < n; i++)
A[i] = in.nextInt();
int disturbed = 0, disturbs2 = 0;
for (int i = 1; i < n-1; i++)
{
if (A[i] == 0 && A[i-1] == 1 && A[i+1] == 1)
{
disturbed++;
disturbes_how_many[i - 1]++;
disturbes_how_many[i + 1]++;
if (disturbes_how_many[i - 1] == 2)
{
disturbs2++;
disturbes_how_many[i + 1]--;
}
}
}
disturbed = disturbed - (disturbs2 * 2);
System.out.println(disturbs2 + disturbed);
}
}
| Java | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output | |
PASSED | 8d6e07d3985c7c291e46c9e5d081e05a | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
public class disturbedPeople {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
public static void main(String[] args) {
FastReader sc = new FastReader();
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
int count=0;
for(int i=1;i<n-1;i++)
{
if(a[i]==0 && a[i-1]==1 && a[i+1]==1)
{
//System.out.println("i:" +i);
a[i-1]=0;
a[i+1]=0;
count++;
i++;
}
}
System.out.println(count);
}
} | Java | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output | |
PASSED | fd41913a84113d34b768373ac2bc797d | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes | import java.util.Scanner;
public class Contest {
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int[] lights = new int[n];
for(int i = 0 ; i < n ; i++)
lights[i] = s.nextInt();
int index= 0;
int[] specialzeroes = new int[n];
for(int i = 1 ; i < n - 1; i++)
{
if(lights[i-1] == 1 && lights[i] == 0 && lights[i+1] == 1)
{
specialzeroes[index] = i;
index++;
}
}
if (index == 0)
{
System.out.println(0);
return;
}
int m = 0;
for(int i = 0 ; i < index ; i++)
{
if((specialzeroes[i+1] - specialzeroes[i] !=2))
{
m++;
}
else if((specialzeroes[i+1] - specialzeroes[i] ==2))
{
m++;
i++;
}
}
System.out.println(m);
}
}
| Java | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output | |
PASSED | bb0a58e7519287e70d18f3a10e5a0d5e | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes |
import java.util.Scanner;
public class Disturbed {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int[] arr = new int[n];
for(int i=0;i<n;i++)
arr[i] = s.nextInt();
int k = 0;
boolean flag = false;
boolean flag2 = false;
if(arr[0]==1)
flag = true;
for(int i=1;i<n;i++){
if(arr[i]==0){
if(flag)
flag2 = true;
else
flag2 = false;
flag = false;
}else{
if(flag2){
k++;
flag=false;
flag2 = false;
}else{
flag = true;
flag2= false;
}
}
}
System.out.println(k);
}
}
| Java | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output | |
PASSED | 4462d878f942e0e2c5f3380436f3e75d | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes | import java.util.Scanner;
public class CODEFORCETEST {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
int count = 0;
int i = 1;
while (i < n - 1) {
if (a[i - 1] == 1 && a[i + 1] == 1 && a[i] == 0) {
count++;
a[i + 1] = 0;
}
i++;
}
System.out.println(count);
}
} | Java | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output | |
PASSED | d8412390d1078a51f5f8b991c76d41b1 | train_001.jsonl | 1542378900 | There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
public class MyClass {
public static void main(String[] args) throws Exception {
Scanner sc=new Scanner(System.in);
PrintWriter pw=new PrintWriter(System.out);
int n=sc.nextInt();
int fwd=0,bwd=0;
int[] a=new int[n];
int[] tmp=new int[n];
for(int i=0; i<n; i++) {
a[i]=sc.nextInt();
tmp[i]=a[i];
}
for(int i=1; i<(n-1); i++) {
if((a[i]==0) && (tmp[i-1]==1) && (tmp[i+1]==1)) {
tmp[i-1]=0;
tmp[i+1]=0;
fwd++;
}
}
for(int i=0; i<n; i++)
tmp[i]=a[i];
for(int i=n-2;i>0;i--) {
if((a[i]==0) && (tmp[i-1]==1) && (tmp[i+1]==1)) {
tmp[i-1]=0;
tmp[i+1]=0;
bwd++;
}
}
pw.println(Math.min(bwd,fwd));
pw.close();
}
} | Java | ["10\n1 1 0 1 1 0 1 0 1 0", "5\n1 1 0 0 0", "4\n1 1 1 1"] | 1 second | ["2", "0", "0"] | NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples. | Java 8 | standard input | [
"greedy"
] | ea62b6f68d25fb17aba8932af8377db0 | The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat. | 1,000 | Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.