exec_outcome
stringclasses 1
value | code_uid
stringlengths 32
32
| file_name
stringclasses 111
values | prob_desc_created_at
stringlengths 10
10
| prob_desc_description
stringlengths 63
3.8k
| prob_desc_memory_limit
stringclasses 18
values | source_code
stringlengths 117
65.5k
| lang_cluster
stringclasses 1
value | prob_desc_sample_inputs
stringlengths 2
802
| prob_desc_time_limit
stringclasses 27
values | prob_desc_sample_outputs
stringlengths 2
796
| prob_desc_notes
stringlengths 4
3k
⌀ | lang
stringclasses 5
values | prob_desc_input_from
stringclasses 3
values | tags
sequencelengths 0
11
| src_uid
stringlengths 32
32
| prob_desc_input_spec
stringlengths 28
2.37k
⌀ | difficulty
int64 -1
3.5k
⌀ | prob_desc_output_spec
stringlengths 17
1.47k
⌀ | prob_desc_output_to
stringclasses 3
values | hidden_unit_tests
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PASSED | 8f0d4e59d60defc026c9a9e9dd986473 | train_000.jsonl | 1369582200 | SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner.Output the probability that SmallR will win the match. | 256 megabytes | import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Hashtable;
import java.util.StringTokenizer;
public class Main
{
public static void main(String args[]) throws IOException
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
StringTokenizer datos = new StringTokenizer(in.readLine());
int a = Integer.parseInt(datos.nextToken());
int b = Integer.parseInt(datos.nextToken());
int c = Integer.parseInt(datos.nextToken());
int d = Integer.parseInt(datos.nextToken());
double pAcertar1 = 1.0d*a/b;
double pFallar1 = 1.0d - pAcertar1;
double pAcertar2 = 1.0d*c/d;
double pFallar2 = 1.0d - pAcertar2;
double res = pAcertar1;
double temp = 1;
do{
temp = temp * pFallar1 * pFallar2;
res+=temp * pAcertar1;
}while(temp>1e-13);
out.println(String.format("%.12f", res).replace(',','.'));
out.flush();
}
} | Java | ["1 2 1 2"] | 2 seconds | ["0.666666666667"] | null | Java 7 | standard input | [
"probabilities",
"math"
] | 7b932b2d3ab65a353b18d81cf533a54e | A single line contains four integers . | 1,300 | Print a single real number, the probability that SmallR will win the match. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6. | standard output | |
PASSED | a882eb76ce131148e1fc83fe1d0526f7 | train_000.jsonl | 1369582200 | SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner.Output the probability that SmallR will win the match. | 256 megabytes | import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Hashtable;
import java.util.StringTokenizer;
public class Main
{
public static void main(String args[]) throws IOException
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
StringTokenizer datos = new StringTokenizer(in.readLine());
int a = Integer.parseInt(datos.nextToken());
int b = Integer.parseInt(datos.nextToken());
int c = Integer.parseInt(datos.nextToken());
int d = Integer.parseInt(datos.nextToken());
double pAcertar1 = 1.0d*a/b;
double pFallar1 = 1.0d - pAcertar1;
double pAcertar2 = 1.0d*c/d;
double pFallar2 = 1.0d - pAcertar2;
double res = pAcertar1;
double temp = 1;
do{
temp = temp * pFallar1 * pFallar2;
res+=temp * pAcertar1;
}while(temp>1e-13);
out.println(res);
out.flush();
}
} | Java | ["1 2 1 2"] | 2 seconds | ["0.666666666667"] | null | Java 7 | standard input | [
"probabilities",
"math"
] | 7b932b2d3ab65a353b18d81cf533a54e | A single line contains four integers . | 1,300 | Print a single real number, the probability that SmallR will win the match. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6. | standard output | |
PASSED | 11a0edc349b85bc7f3af5bf54b269bdd | train_000.jsonl | 1559399700 | There are $$$n$$$ stones arranged on an axis. Initially the $$$i$$$-th stone is located at the coordinate $$$s_i$$$. There may be more than one stone in a single place.You can perform zero or more operations of the following type: take two stones with indices $$$i$$$ and $$$j$$$ so that $$$s_i \leq s_j$$$, choose an integer $$$d$$$ ($$$0 \leq 2 \cdot d \leq s_j - s_i$$$), and replace the coordinate $$$s_i$$$ with $$$(s_i + d)$$$ and replace coordinate $$$s_j$$$ with $$$(s_j - d)$$$. In other words, draw stones closer to each other. You want to move the stones so that they are located at positions $$$t_1, t_2, \ldots, t_n$$$. The order of the stones is not important — you just want for the multiset of the stones resulting positions to be the same as the multiset of $$$t_1, t_2, \ldots, t_n$$$.Detect whether it is possible to move the stones this way, and if yes, construct a way to do so. You don't need to minimize the number of moves. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastScanner in = new FastScanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskE solver = new TaskE();
solver.solve(1, in, out);
out.close();
}
static class TaskE {
Stone[] a;
Stone[] b;
int[] ansI;
int[] ansJ;
int[] ansD;
int ansSize;
public void solve(int testNumber, FastScanner in, PrintWriter out) {
int n = in.nextInt();
a = new Stone[n];
b = new Stone[n];
long sumA = 0;
for (int i = 0; i < n; i++) {
a[i] = new Stone();
a[i].x = in.nextInt();
a[i].id = i;
sumA += a[i].x;
}
long sumB = 0;
for (int i = 0; i < n; i++) {
b[i] = new Stone();
b[i].x = in.nextInt();
b[i].id = i;
sumB += b[i].x;
}
if (sumA != sumB) {
out.println("NO");
return;
}
Arrays.sort(a, (u, v) -> (u.x - v.x));
Arrays.sort(b, (u, v) -> (u.x - v.x));
ansI = new int[5 * n];
ansJ = new int[5 * n];
ansD = new int[5 * n];
int j = 0;
for (int i = 0; i < n; i++) {
if (a[i].x > b[i].x) {
out.println("NO");
return;
}
if (a[i].x == b[i].x) {
continue;
}
while (j <= i) {
++j;
}
while (a[i].x < b[i].x) {
while (j < n && a[j].x <= b[j].x) {
++j;
}
if (j == n) {
out.println("NO");
return;
}
int d = Math.min(b[i].x - a[i].x, a[j].x - b[j].x);
d = Math.min(d, (a[j].x - a[i].x) / 2);
move(i, j, d);
}
}
out.println("YES");
out.println(ansSize);
for (int i = 0; i < ansSize; i++) {
out.println((ansI[i] + 1) + " " + (ansJ[i] + 1) + " " + ansD[i]);
}
}
private void move(int i, int j, int d) {
if (a[i].x > a[j].x) {
throw new AssertionError();
}
ansI[ansSize] = a[i].id;
ansJ[ansSize] = a[j].id;
ansD[ansSize] = d;
++ansSize;
a[i].x += d;
a[j].x -= d;
}
class Stone {
int x;
int id;
}
}
static class FastScanner {
private BufferedReader in;
private StringTokenizer st;
public FastScanner(InputStream stream) {
in = new BufferedReader(new InputStreamReader(stream));
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
String rl = in.readLine();
if (rl == null) {
return null;
}
st = new StringTokenizer(rl);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| Java | ["5\n2 2 7 4 9\n5 4 5 5 5", "3\n1 5 10\n3 5 7"] | 4 seconds | ["YES\n4\n4 3 1\n2 3 1\n2 5 2\n1 5 2", "NO"] | NoteConsider the first example. After the first move the locations of stones is $$$[2, 2, 6, 5, 9]$$$. After the second move the locations of stones is $$$[2, 3, 5, 5, 9]$$$. After the third move the locations of stones is $$$[2, 5, 5, 5, 7]$$$. After the last move the locations of stones is $$$[4, 5, 5, 5, 5]$$$. | Java 8 | standard input | [
"greedy",
"constructive algorithms",
"two pointers",
"math",
"sortings"
] | f236c4110a973d1c9f63cbbcc74b9e0b | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) – the number of stones. The second line contains integers $$$s_1, s_2, \ldots, s_n$$$ ($$$1 \le s_i \le 10^9$$$) — the initial positions of the stones. The second line contains integers $$$t_1, t_2, \ldots, t_n$$$ ($$$1 \le t_i \le 10^9$$$) — the target positions of the stones. | 2,300 | If it is impossible to move the stones this way, print "NO". Otherwise, on the first line print "YES", on the second line print the number of operations $$$m$$$ ($$$0 \le m \le 5 \cdot n$$$) required. You don't have to minimize the number of operations. Then print $$$m$$$ lines, each containing integers $$$i, j, d$$$ ($$$1 \le i, j \le n$$$, $$$s_i \le s_j$$$, $$$0 \leq 2 \cdot d \leq s_j - s_i$$$), defining the operations. One can show that if an answer exists, there is an answer requiring no more than $$$5 \cdot n$$$ operations. | standard output | |
PASSED | 814d8f2d2e5f24c959225ee3bf50517c | train_000.jsonl | 1559399700 | There are $$$n$$$ stones arranged on an axis. Initially the $$$i$$$-th stone is located at the coordinate $$$s_i$$$. There may be more than one stone in a single place.You can perform zero or more operations of the following type: take two stones with indices $$$i$$$ and $$$j$$$ so that $$$s_i \leq s_j$$$, choose an integer $$$d$$$ ($$$0 \leq 2 \cdot d \leq s_j - s_i$$$), and replace the coordinate $$$s_i$$$ with $$$(s_i + d)$$$ and replace coordinate $$$s_j$$$ with $$$(s_j - d)$$$. In other words, draw stones closer to each other. You want to move the stones so that they are located at positions $$$t_1, t_2, \ldots, t_n$$$. The order of the stones is not important — you just want for the multiset of the stones resulting positions to be the same as the multiset of $$$t_1, t_2, \ldots, t_n$$$.Detect whether it is possible to move the stones this way, and if yes, construct a way to do so. You don't need to minimize the number of moves. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastScanner in = new FastScanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskE solver = new TaskE();
solver.solve(1, in, out);
out.close();
}
static class TaskE {
Stone[] a;
Stone[] b;
int[] ansI;
int[] ansJ;
int[] ansD;
int ansSize;
public void solve(int testNumber, FastScanner in, PrintWriter out) {
int n = in.nextInt();
a = new Stone[n];
b = new Stone[n];
long sumA = 0;
for (int i = 0; i < n; i++) {
a[i] = new Stone();
a[i].x = in.nextInt();
a[i].id = i;
sumA += a[i].x;
}
long sumB = 0;
for (int i = 0; i < n; i++) {
b[i] = new Stone();
b[i].x = in.nextInt();
b[i].id = i;
sumB += b[i].x;
}
if (sumA != sumB) {
out.println("NO");
return;
}
Arrays.sort(a, (u, v) -> (u.x - v.x));
Arrays.sort(b, (u, v) -> (u.x - v.x));
ansI = new int[5 * n];
ansJ = new int[5 * n];
ansD = new int[5 * n];
int j = 0;
for (int i = 0; i < n; i++) {
if (a[i].x > b[i].x) {
out.println("NO");
return;
}
if (a[i].x == b[i].x) {
continue;
}
while (j <= i) {
++j;
}
while (a[i].x < b[i].x) {
while (j < n && a[j].x <= b[j].x) {
++j;
}
if (j == n) {
out.println("NO");
return;
}
int d = Math.min(b[i].x - a[i].x, a[j].x - b[j].x);
move(i, j, d);
}
}
out.println("YES");
out.println(ansSize);
for (int i = 0; i < ansSize; i++) {
out.println((ansI[i] + 1) + " " + (ansJ[i] + 1) + " " + ansD[i]);
}
}
private void move(int i, int j, int d) {
if (a[i].x > a[j].x) {
throw new AssertionError();
}
ansI[ansSize] = a[i].id;
ansJ[ansSize] = a[j].id;
ansD[ansSize] = d;
++ansSize;
a[i].x += d;
a[j].x -= d;
}
class Stone {
int x;
int id;
}
}
static class FastScanner {
private BufferedReader in;
private StringTokenizer st;
public FastScanner(InputStream stream) {
in = new BufferedReader(new InputStreamReader(stream));
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
String rl = in.readLine();
if (rl == null) {
return null;
}
st = new StringTokenizer(rl);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| Java | ["5\n2 2 7 4 9\n5 4 5 5 5", "3\n1 5 10\n3 5 7"] | 4 seconds | ["YES\n4\n4 3 1\n2 3 1\n2 5 2\n1 5 2", "NO"] | NoteConsider the first example. After the first move the locations of stones is $$$[2, 2, 6, 5, 9]$$$. After the second move the locations of stones is $$$[2, 3, 5, 5, 9]$$$. After the third move the locations of stones is $$$[2, 5, 5, 5, 7]$$$. After the last move the locations of stones is $$$[4, 5, 5, 5, 5]$$$. | Java 8 | standard input | [
"greedy",
"constructive algorithms",
"two pointers",
"math",
"sortings"
] | f236c4110a973d1c9f63cbbcc74b9e0b | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) – the number of stones. The second line contains integers $$$s_1, s_2, \ldots, s_n$$$ ($$$1 \le s_i \le 10^9$$$) — the initial positions of the stones. The second line contains integers $$$t_1, t_2, \ldots, t_n$$$ ($$$1 \le t_i \le 10^9$$$) — the target positions of the stones. | 2,300 | If it is impossible to move the stones this way, print "NO". Otherwise, on the first line print "YES", on the second line print the number of operations $$$m$$$ ($$$0 \le m \le 5 \cdot n$$$) required. You don't have to minimize the number of operations. Then print $$$m$$$ lines, each containing integers $$$i, j, d$$$ ($$$1 \le i, j \le n$$$, $$$s_i \le s_j$$$, $$$0 \leq 2 \cdot d \leq s_j - s_i$$$), defining the operations. One can show that if an answer exists, there is an answer requiring no more than $$$5 \cdot n$$$ operations. | standard output | |
PASSED | 4bab41763e7920bd4035e5fe9f8ab1cc | train_000.jsonl | 1559399700 | There are $$$n$$$ stones arranged on an axis. Initially the $$$i$$$-th stone is located at the coordinate $$$s_i$$$. There may be more than one stone in a single place.You can perform zero or more operations of the following type: take two stones with indices $$$i$$$ and $$$j$$$ so that $$$s_i \leq s_j$$$, choose an integer $$$d$$$ ($$$0 \leq 2 \cdot d \leq s_j - s_i$$$), and replace the coordinate $$$s_i$$$ with $$$(s_i + d)$$$ and replace coordinate $$$s_j$$$ with $$$(s_j - d)$$$. In other words, draw stones closer to each other. You want to move the stones so that they are located at positions $$$t_1, t_2, \ldots, t_n$$$. The order of the stones is not important — you just want for the multiset of the stones resulting positions to be the same as the multiset of $$$t_1, t_2, \ldots, t_n$$$.Detect whether it is possible to move the stones this way, and if yes, construct a way to do so. You don't need to minimize the number of moves. | 256 megabytes | import java.util.*;
import java.io.*;
import java.text.*;
public class Main{
//SOLUTION BEGIN
//Spread AC, not hacks
void pre() throws Exception{}
void solve(int TC) throws Exception{
int n = ni();
long[][] s = new long[n][];long[] t = new long[n];
for(int i = 0; i< n; i++)s[i] = new long[]{i, nl()};
for(int i = 0; i< n; i++)t[i] = nl();
Arrays.sort(s, (long[] l1, long[] l2) -> Long.compare(l1[1], l2[1]));
Arrays.sort(t);
long sum = 0;
boolean yes = true;
for(int i = 0; i< n; i++){
sum+= s[i][1]-t[i];
yes &= sum <= 0;
}
yes &= sum == 0;
if(yes){
pn("YES");
int ptr = 1;
long[][] op = new long[5*n][];int cnt = 0;
for(int i = 0; i< n; i++){
if(s[i][1] == t[i])continue;
long diff = t[i]-s[i][1];
while(diff>0){
while(ptr< n && s[ptr][1] <= t[ptr])ptr++;
long dd = s[ptr][1]-t[ptr];
long min = Math.min(diff, dd);
op[cnt++] = new long[]{s[i][0], s[ptr][0], min};
s[ptr][1] -= min;
s[i][1] += min;
diff -= min;
}
}
pn(cnt);
for(int i = 0; i< cnt; i++)pn((1+op[i][0])+" "+(1+op[i][1])+" "+op[i][2]);
}else pn("NO");
}
//SOLUTION END
void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
long mod = (long)987654319, IINF = (long)1e18;
final int INF = (int)1e9, MX = (int)2e5+5;
DecimalFormat df = new DecimalFormat("0.00000000000");
double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-8;
static boolean multipleTC = false, memory = true;
FastReader in;PrintWriter out;
void run() throws Exception{
in = new FastReader();
out = new PrintWriter(System.out);
//Solution Credits: Taranpreet Singh
int T = (multipleTC)?ni():1;
pre();for(int t = 1; t<= T; t++)solve(t);
out.flush();
out.close();
}
public static void main(String[] args) throws Exception{
if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start();
else new Main().run();
}
long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
void p(Object o){out.print(o);}
void pn(Object o){out.println(o);}
void pni(Object o){out.println(o);out.flush();}
String n()throws Exception{return in.next();}
String nln()throws Exception{return in.nextLine();}
int ni()throws Exception{return Integer.parseInt(in.next());}
long nl()throws Exception{return Long.parseLong(in.next());}
double nd()throws Exception{return Double.parseDouble(in.next());}
class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br = new BufferedReader(new InputStreamReader(System.in));
}
public FastReader(String s) throws Exception{
br = new BufferedReader(new FileReader(s));
}
String next() throws Exception{
while (st == null || !st.hasMoreElements()){
try{
st = new StringTokenizer(br.readLine());
}catch (IOException e){
throw new Exception(e.toString());
}
}
return st.nextToken();
}
String nextLine() throws Exception{
String str = "";
try{
str = br.readLine();
}catch (IOException e){
throw new Exception(e.toString());
}
return str;
}
}
} | Java | ["5\n2 2 7 4 9\n5 4 5 5 5", "3\n1 5 10\n3 5 7"] | 4 seconds | ["YES\n4\n4 3 1\n2 3 1\n2 5 2\n1 5 2", "NO"] | NoteConsider the first example. After the first move the locations of stones is $$$[2, 2, 6, 5, 9]$$$. After the second move the locations of stones is $$$[2, 3, 5, 5, 9]$$$. After the third move the locations of stones is $$$[2, 5, 5, 5, 7]$$$. After the last move the locations of stones is $$$[4, 5, 5, 5, 5]$$$. | Java 8 | standard input | [
"greedy",
"constructive algorithms",
"two pointers",
"math",
"sortings"
] | f236c4110a973d1c9f63cbbcc74b9e0b | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) – the number of stones. The second line contains integers $$$s_1, s_2, \ldots, s_n$$$ ($$$1 \le s_i \le 10^9$$$) — the initial positions of the stones. The second line contains integers $$$t_1, t_2, \ldots, t_n$$$ ($$$1 \le t_i \le 10^9$$$) — the target positions of the stones. | 2,300 | If it is impossible to move the stones this way, print "NO". Otherwise, on the first line print "YES", on the second line print the number of operations $$$m$$$ ($$$0 \le m \le 5 \cdot n$$$) required. You don't have to minimize the number of operations. Then print $$$m$$$ lines, each containing integers $$$i, j, d$$$ ($$$1 \le i, j \le n$$$, $$$s_i \le s_j$$$, $$$0 \leq 2 \cdot d \leq s_j - s_i$$$), defining the operations. One can show that if an answer exists, there is an answer requiring no more than $$$5 \cdot n$$$ operations. | standard output | |
PASSED | deeacaee6fe17a9e81a104fe955cb2e8 | train_000.jsonl | 1559399700 | There are $$$n$$$ stones arranged on an axis. Initially the $$$i$$$-th stone is located at the coordinate $$$s_i$$$. There may be more than one stone in a single place.You can perform zero or more operations of the following type: take two stones with indices $$$i$$$ and $$$j$$$ so that $$$s_i \leq s_j$$$, choose an integer $$$d$$$ ($$$0 \leq 2 \cdot d \leq s_j - s_i$$$), and replace the coordinate $$$s_i$$$ with $$$(s_i + d)$$$ and replace coordinate $$$s_j$$$ with $$$(s_j - d)$$$. In other words, draw stones closer to each other. You want to move the stones so that they are located at positions $$$t_1, t_2, \ldots, t_n$$$. The order of the stones is not important — you just want for the multiset of the stones resulting positions to be the same as the multiset of $$$t_1, t_2, \ldots, t_n$$$.Detect whether it is possible to move the stones this way, and if yes, construct a way to do so. You don't need to minimize the number of moves. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class First {
public static class dist implements Comparable<dist>{
int from;
int to;
int ind;
public dist(int f, int t, int ind){
this.from = f;
this.to = t;
this.ind = ind;
}
@Override
public int compareTo(dist o) {
if(this.from < o.from){
return -1;
}
else if(this.from > o.from){
return 1;
}
else{
if(this.ind > o.ind){
return 1;
}else if(this.ind < o.ind){
return -1;
}
else{
return 0;
}
}
}
}
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(System.out);
int n = Integer.parseInt(reader.readLine());
TreeSet<dist> left = new TreeSet<>();
TreeSet<dist> right = new TreeSet<>();
dist[] array1 = new dist[n];
StringTokenizer st = new StringTokenizer(reader.readLine());
for(int i = 0; i < n; ++i){
array1[i] = new dist(Integer.parseInt(st.nextToken()), -1 , i + 1);
}
st = new StringTokenizer(reader.readLine());
int[] array2 = new int[n];
for(int i = 0; i < n; ++i){
array2[i] = Integer.parseInt(st.nextToken());
}
Arrays.sort(array1);
Arrays.sort(array2);
for(int i = 0; i < n; ++i){
if(array1[i].from < array2[i]){
left.add(new dist(array1[i].from, array2[i], array1[i].ind));
}
else if(array1[i].from > array2[i]){
right.add(new dist(array1[i].from, array2[i], array1[i].ind));
}
}
ArrayList<String> ans = new ArrayList<>();
while(!left.isEmpty() && !right.isEmpty()){
dist l = left.last();
dist r = right.last();
left.remove(l);
right.remove(r);
if(l.from > r.from){
System.out.println("NO");
return;
}
if(l.to - l.from > r.from - r.to){
ans.add(l.ind + " " + r.ind + " " + (r.from - r.to));
left.add(new dist(l.from + (r.from - r.to), l.to, l.ind));
}
else if(l.to - l.from < r.from - r.to){
ans.add(l.ind + " " + r.ind + " " + (l.to - l.from));
right.add(new dist(r.from - (l.to - l.from), r.to, r.ind));
}
else{
ans.add(l.ind + " " + r.ind + " " + (l.to - l.from));
}
}
if(!right.isEmpty() || !left.isEmpty()){
System.out.println("NO");
return;
}
writer.println("YES");
writer.println(ans.size());
for(String s : ans){
writer.println(s);
}
writer.close();
}
} | Java | ["5\n2 2 7 4 9\n5 4 5 5 5", "3\n1 5 10\n3 5 7"] | 4 seconds | ["YES\n4\n4 3 1\n2 3 1\n2 5 2\n1 5 2", "NO"] | NoteConsider the first example. After the first move the locations of stones is $$$[2, 2, 6, 5, 9]$$$. After the second move the locations of stones is $$$[2, 3, 5, 5, 9]$$$. After the third move the locations of stones is $$$[2, 5, 5, 5, 7]$$$. After the last move the locations of stones is $$$[4, 5, 5, 5, 5]$$$. | Java 8 | standard input | [
"greedy",
"constructive algorithms",
"two pointers",
"math",
"sortings"
] | f236c4110a973d1c9f63cbbcc74b9e0b | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) – the number of stones. The second line contains integers $$$s_1, s_2, \ldots, s_n$$$ ($$$1 \le s_i \le 10^9$$$) — the initial positions of the stones. The second line contains integers $$$t_1, t_2, \ldots, t_n$$$ ($$$1 \le t_i \le 10^9$$$) — the target positions of the stones. | 2,300 | If it is impossible to move the stones this way, print "NO". Otherwise, on the first line print "YES", on the second line print the number of operations $$$m$$$ ($$$0 \le m \le 5 \cdot n$$$) required. You don't have to minimize the number of operations. Then print $$$m$$$ lines, each containing integers $$$i, j, d$$$ ($$$1 \le i, j \le n$$$, $$$s_i \le s_j$$$, $$$0 \leq 2 \cdot d \leq s_j - s_i$$$), defining the operations. One can show that if an answer exists, there is an answer requiring no more than $$$5 \cdot n$$$ operations. | standard output | |
PASSED | 6ed4795c5d65ea97d6ffa38124e13878 | train_000.jsonl | 1559399700 | There are $$$n$$$ stones arranged on an axis. Initially the $$$i$$$-th stone is located at the coordinate $$$s_i$$$. There may be more than one stone in a single place.You can perform zero or more operations of the following type: take two stones with indices $$$i$$$ and $$$j$$$ so that $$$s_i \leq s_j$$$, choose an integer $$$d$$$ ($$$0 \leq 2 \cdot d \leq s_j - s_i$$$), and replace the coordinate $$$s_i$$$ with $$$(s_i + d)$$$ and replace coordinate $$$s_j$$$ with $$$(s_j - d)$$$. In other words, draw stones closer to each other. You want to move the stones so that they are located at positions $$$t_1, t_2, \ldots, t_n$$$. The order of the stones is not important — you just want for the multiset of the stones resulting positions to be the same as the multiset of $$$t_1, t_2, \ldots, t_n$$$.Detect whether it is possible to move the stones this way, and if yes, construct a way to do so. You don't need to minimize the number of moves. | 256 megabytes | //package round003;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;
import java.util.List;
public class E {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve()
{
int n = ni();
int[] a = na(n);
int[] b = na(n);
b = radixSort(b);
int[][] ai = new int[n][];
for(int i = 0;i < n;i++)ai[i] = new int[]{a[i], i};
Arrays.sort(ai, new Comparator<int[]>() {
public int compare(int[] a, int[] b) {
return a[0] - b[0];
}
});
long bal = 0;
for(int i = 0;i < n;i++){
bal += a[i] - b[i];
}
if(bal != 0){
out.println("NO");
return;
}
List<String> route = new ArrayList<>();
int j = 0;
for(int i = 0;i < n;){
while(j < n && ai[j][0] - b[j] <= 0){
j++;
}
if(j == n)break;
int L = b[i] - ai[i][0];
int R = ai[j][0] - b[j];
if(L <= 0){
i++;
continue;
}
if(i >= j){
out.println("NO");
return;
}
if(L <= R){
route.add((ai[i][1]+1) + " " + (ai[j][1]+1) + " " + L);
ai[i][0] += L;
ai[j][0] -= L;
assert ai[i][0] <= ai[j][0];
}else if(L > R){
route.add((ai[i][1]+1) + " " + (ai[j][1]+1) + " " + R);
ai[i][0] += R;
ai[j][0] -= R;
assert ai[i][0] <= ai[j][0];
}
}
for(int i = 0;i < n;i++){
if(ai[i][0] != b[i]){
out.println("NO");
return;
}
}
out.println("YES");
assert route.size() <= 5*n;
out.println(route.size());
for(String line : route){
out.println(line);
}
}
public static int[] radixSort(int[] f){ return radixSort(f, f.length); }
public static int[] radixSort(int[] f, int n)
{
int[] to = new int[n];
{
int[] b = new int[65537];
for(int i = 0;i < n;i++)b[1+(f[i]&0xffff)]++;
for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
for(int i = 0;i < n;i++)to[b[f[i]&0xffff]++] = f[i];
int[] d = f; f = to;to = d;
}
{
int[] b = new int[65537];
for(int i = 0;i < n;i++)b[1+(f[i]>>>16)]++;
for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
for(int i = 0;i < n;i++)to[b[f[i]>>>16]++] = f[i];
int[] d = f; f = to;to = d;
}
return f;
}
void run() throws Exception
{
is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);
long s = System.currentTimeMillis();
solve();
out.flush();
tr(System.currentTimeMillis()-s+"ms");
}
public static void main(String[] args) throws Exception { new E().run(); }
private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;
private int readByte()
{
if(lenbuf == -1)throw new InputMismatchException();
if(ptrbuf >= lenbuf){
ptrbuf = 0;
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
if(lenbuf <= 0)return -1;
}
return inbuf[ptrbuf++];
}
private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
private double nd() { return Double.parseDouble(ns()); }
private char nc() { return (char)skip(); }
private String ns()
{
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private char[] ns(int n)
{
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b))){
buf[p++] = (char)b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private char[][] nm(int n, int m)
{
char[][] map = new char[n][];
for(int i = 0;i < n;i++)map[i] = ns(m);
return map;
}
private int[] na(int n)
{
int[] a = new int[n];
for(int i = 0;i < n;i++)a[i] = ni();
return a;
}
private int ni()
{
int num = 0, b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private long nl()
{
long num = 0;
int b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}
| Java | ["5\n2 2 7 4 9\n5 4 5 5 5", "3\n1 5 10\n3 5 7"] | 4 seconds | ["YES\n4\n4 3 1\n2 3 1\n2 5 2\n1 5 2", "NO"] | NoteConsider the first example. After the first move the locations of stones is $$$[2, 2, 6, 5, 9]$$$. After the second move the locations of stones is $$$[2, 3, 5, 5, 9]$$$. After the third move the locations of stones is $$$[2, 5, 5, 5, 7]$$$. After the last move the locations of stones is $$$[4, 5, 5, 5, 5]$$$. | Java 8 | standard input | [
"greedy",
"constructive algorithms",
"two pointers",
"math",
"sortings"
] | f236c4110a973d1c9f63cbbcc74b9e0b | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) – the number of stones. The second line contains integers $$$s_1, s_2, \ldots, s_n$$$ ($$$1 \le s_i \le 10^9$$$) — the initial positions of the stones. The second line contains integers $$$t_1, t_2, \ldots, t_n$$$ ($$$1 \le t_i \le 10^9$$$) — the target positions of the stones. | 2,300 | If it is impossible to move the stones this way, print "NO". Otherwise, on the first line print "YES", on the second line print the number of operations $$$m$$$ ($$$0 \le m \le 5 \cdot n$$$) required. You don't have to minimize the number of operations. Then print $$$m$$$ lines, each containing integers $$$i, j, d$$$ ($$$1 \le i, j \le n$$$, $$$s_i \le s_j$$$, $$$0 \leq 2 \cdot d \leq s_j - s_i$$$), defining the operations. One can show that if an answer exists, there is an answer requiring no more than $$$5 \cdot n$$$ operations. | standard output | |
PASSED | 6e3119e6d473b542ab93670a79eec7c3 | train_000.jsonl | 1559399700 | There are $$$n$$$ stones arranged on an axis. Initially the $$$i$$$-th stone is located at the coordinate $$$s_i$$$. There may be more than one stone in a single place.You can perform zero or more operations of the following type: take two stones with indices $$$i$$$ and $$$j$$$ so that $$$s_i \leq s_j$$$, choose an integer $$$d$$$ ($$$0 \leq 2 \cdot d \leq s_j - s_i$$$), and replace the coordinate $$$s_i$$$ with $$$(s_i + d)$$$ and replace coordinate $$$s_j$$$ with $$$(s_j - d)$$$. In other words, draw stones closer to each other. You want to move the stones so that they are located at positions $$$t_1, t_2, \ldots, t_n$$$. The order of the stones is not important — you just want for the multiset of the stones resulting positions to be the same as the multiset of $$$t_1, t_2, \ldots, t_n$$$.Detect whether it is possible to move the stones this way, and if yes, construct a way to do so. You don't need to minimize the number of moves. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Stack;
import java.util.ArrayList;
import java.util.Vector;
import java.util.Comparator;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author KharYusuf
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastReader in = new FastReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
EEarthWindAndFire solver = new EEarthWindAndFire();
solver.solve(1, in, out);
out.close();
}
static class EEarthWindAndFire {
public void solve(int testNumber, FastReader s, PrintWriter w) {
int n = s.nextInt(), a[][] = new int[n][2], b[] = new int[n], dif;
long sum1 = 0, sum2 = 0;
for (int i = 0; i < n; i++) {
a[i][0] = s.nextInt();
a[i][1] = i + 1;
}
pair<Integer, Integer> p;
func.sortbyColumn(a, 0);
for (int i = 0; i < n; i++) {
b[i] = s.nextInt();
}
func.sort(b);
Stack<pair> st = new Stack<>();
ArrayList<dist> ans = new ArrayList<>();
for (int i = 0; i < n; i++) {
if (a[i][0] < b[i]) st.push(new pair(a[i][1], b[i] - a[i][0]));
else {
dif = a[i][0] - b[i];
while (dif > 0) {
if (st.isEmpty()) {
w.println("NO");
return;
}
p = st.pop();
if (p.y >= dif) {
ans.add(new dist(p.x, a[i][1], dif));
if (p.y > dif) st.push(new pair(p.x, p.y - dif));
dif = 0;
} else {
ans.add(new dist(p.x, a[i][1], p.y));
dif -= p.y;
}
}
}
}
if (!st.isEmpty()) {
w.println("NO");
return;
}
w.println("YES");
w.println(ans.size());
for (dist d : ans) w.println(d.x + " " + d.y + " " + d.z);
}
}
static class FastReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private FastReader.SpaceCharFilter filter;
public FastReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public 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);
}
}
static class func {
public static void sortbyColumn(int arr[][], final int col) {
Arrays.sort(arr, new Comparator<int[]>() {
public int compare(final int[] entry1, final int[] entry2) {
if (entry1[col] > entry2[col]) return 1;
if (entry1[col] < entry2[col]) return -1;
return 0;
}
});
}
public static void sort(int arr[]) {
int n = arr.length, mid, h, s, l, i, j, k;
int[] res = new int[n];
for (s = 1; s < n; s <<= 1) {
for (l = 0; l < n - 1; l += (s << 1)) {
h = Math.min(l + (s << 1) - 1, n - 1);
mid = Math.min(l + s - 1, n - 1);
i = l;
j = mid + 1;
k = l;
while (i <= mid && j <= h) res[k++] = (arr[i] <= arr[j] ? arr[i++] : arr[j++]);
while (i <= mid) res[k++] = arr[i++];
while (j < n && j <= h) res[k++] = arr[j++];
for (k = l; k <= h; k++) arr[k] = res[k];
}
}
}
}
static class dist implements Comparable<dist> {
public int x;
public int y;
public int z;
public dist(int xi, int yi, int zi) {
x = xi;
y = yi;
z = zi;
}
public int compareTo(dist other) {
if (this.z > other.z) {
return 1;
}
if (this.z < other.z) {
return -1;
}
return 0;
}
}
static class pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<pair<U, V>> {
public U x;
public V y;
public pair(U x, V y) {
this.x = x;
this.y = y;
}
public int compareTo(pair<U, V> other) {
if (this.x.compareTo(other.x) != 0) return this.x.compareTo(other.x);
return this.y.compareTo(other.y);
}
public String toString() {
return x.toString() + "," + y.toString();
}
public boolean equals(Object obj) {
pair<U, V> other = (pair<U, V>) obj;
return this.x.equals(other.x) && this.y.equals(other.y);
}
public int hashCode() {
return toString().hashCode();
}
}
}
| Java | ["5\n2 2 7 4 9\n5 4 5 5 5", "3\n1 5 10\n3 5 7"] | 4 seconds | ["YES\n4\n4 3 1\n2 3 1\n2 5 2\n1 5 2", "NO"] | NoteConsider the first example. After the first move the locations of stones is $$$[2, 2, 6, 5, 9]$$$. After the second move the locations of stones is $$$[2, 3, 5, 5, 9]$$$. After the third move the locations of stones is $$$[2, 5, 5, 5, 7]$$$. After the last move the locations of stones is $$$[4, 5, 5, 5, 5]$$$. | Java 8 | standard input | [
"greedy",
"constructive algorithms",
"two pointers",
"math",
"sortings"
] | f236c4110a973d1c9f63cbbcc74b9e0b | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) – the number of stones. The second line contains integers $$$s_1, s_2, \ldots, s_n$$$ ($$$1 \le s_i \le 10^9$$$) — the initial positions of the stones. The second line contains integers $$$t_1, t_2, \ldots, t_n$$$ ($$$1 \le t_i \le 10^9$$$) — the target positions of the stones. | 2,300 | If it is impossible to move the stones this way, print "NO". Otherwise, on the first line print "YES", on the second line print the number of operations $$$m$$$ ($$$0 \le m \le 5 \cdot n$$$) required. You don't have to minimize the number of operations. Then print $$$m$$$ lines, each containing integers $$$i, j, d$$$ ($$$1 \le i, j \le n$$$, $$$s_i \le s_j$$$, $$$0 \leq 2 \cdot d \leq s_j - s_i$$$), defining the operations. One can show that if an answer exists, there is an answer requiring no more than $$$5 \cdot n$$$ operations. | standard output | |
PASSED | 986dfae0fab987299f6412d67543ecb3 | train_000.jsonl | 1559399700 | There are $$$n$$$ stones arranged on an axis. Initially the $$$i$$$-th stone is located at the coordinate $$$s_i$$$. There may be more than one stone in a single place.You can perform zero or more operations of the following type: take two stones with indices $$$i$$$ and $$$j$$$ so that $$$s_i \leq s_j$$$, choose an integer $$$d$$$ ($$$0 \leq 2 \cdot d \leq s_j - s_i$$$), and replace the coordinate $$$s_i$$$ with $$$(s_i + d)$$$ and replace coordinate $$$s_j$$$ with $$$(s_j - d)$$$. In other words, draw stones closer to each other. You want to move the stones so that they are located at positions $$$t_1, t_2, \ldots, t_n$$$. The order of the stones is not important — you just want for the multiset of the stones resulting positions to be the same as the multiset of $$$t_1, t_2, \ldots, t_n$$$.Detect whether it is possible to move the stones this way, and if yes, construct a way to do so. You don't need to minimize the number of moves. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.NoSuchElementException;
public class Main {
private static FastScanner sc = new FastScanner();
private static boolean DEBUG_FLG = false;
public static void main(String[] args) {
int n = sc.nextInt();
Stone[] stone = new Stone[n];
long ssum = 0;
for(int i=0; i<n; i++) {
long s = sc.nextLong();
stone[i] = new Stone(i+1, s);
ssum += s;
}
long[] t = new long[n];
long tsum = 0;
for(int i=0; i<n; i++) {
t[i] = sc.nextLong();
tsum += t[i];
}
if(ssum != tsum) {
System.out.println("NO");
return;
}
Arrays.sort(t);
Arrays.sort(stone, (a, b) -> (int)a.s - (int)b.s);
ArrayList<Integer> moveright = new ArrayList<>();
ArrayList<Integer> moveleft = new ArrayList<>();
for(int i=0; i<n; i++) {
stone[i].t = t[i];
if(stone[i].s < stone[i].t) {
moveright.add(i);
} else if(stone[i].s > stone[i].t) {
moveleft.add(i);
}
}
int ri = 0;
int li = 0;
int opnum = 0;
StringBuilder sb = new StringBuilder();
while(ri < moveright.size() && li < moveleft.size()) {
Stone r = stone[moveright.get(ri)];
Stone l = stone[moveleft.get(li)];
if(r.s >= l.s) {
System.out.println("NO");
return;
}
long d = Math.min(r.t - r.s, l.s - l.t);
sb.append(r.idx + " " + l.idx + " " + d + "\n");
r.s += d;
l.s -= d;
if(r.s > l.s) {
System.out.println("NO");
return;
}
if(r.s == r.t) {
ri++;
}
if(l.s == l.t) {
li++;
}
opnum++;
}
if((ri == moveright.size() && li >= moveleft.size() - 1) || (ri >= moveright.size() - 1 && li == moveleft.size())) {
System.out.println("YES");
System.out.println(opnum);
System.out.print(sb);
} else {
System.out.println("NO");
}
}
static class Stone{
int idx;
long s;
long t;
public Stone(int idx, long s) {
this.idx = idx;
this.s = s;
}
}
static void debug(long... args) {
if(!DEBUG_FLG) return;
boolean flg = false;
for(long s : args) {
if(flg) System.out.print(" ");
flg = true;
System.out.print(s);
}
System.out.println();
}
static class FastScanner {
private final InputStream in = System.in;
private final byte[] buffer = new byte[1024];
private int ptr = 0;
private int buflen = 0;
private boolean hasNextByte() {
if(ptr < buflen) {
return true;
} else {
ptr = 0;
try {
buflen = in.read(buffer);
} catch(IOException e) {
e.printStackTrace();
}
if(buflen <= 0) {
return false;
}
}
return true;
}
private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
public boolean hasNext() { skipUnprintable(); return hasNextByte();}
public String next() {
if (!hasNext()) throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while(isPrintableChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public long nextLong() {
return Long.parseLong(next());
}
public int nextInt(){
return Integer.parseInt(next());
}
public double nextDouble(){
return Double.parseDouble(next());
}
}
}
| Java | ["5\n2 2 7 4 9\n5 4 5 5 5", "3\n1 5 10\n3 5 7"] | 4 seconds | ["YES\n4\n4 3 1\n2 3 1\n2 5 2\n1 5 2", "NO"] | NoteConsider the first example. After the first move the locations of stones is $$$[2, 2, 6, 5, 9]$$$. After the second move the locations of stones is $$$[2, 3, 5, 5, 9]$$$. After the third move the locations of stones is $$$[2, 5, 5, 5, 7]$$$. After the last move the locations of stones is $$$[4, 5, 5, 5, 5]$$$. | Java 8 | standard input | [
"greedy",
"constructive algorithms",
"two pointers",
"math",
"sortings"
] | f236c4110a973d1c9f63cbbcc74b9e0b | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) – the number of stones. The second line contains integers $$$s_1, s_2, \ldots, s_n$$$ ($$$1 \le s_i \le 10^9$$$) — the initial positions of the stones. The second line contains integers $$$t_1, t_2, \ldots, t_n$$$ ($$$1 \le t_i \le 10^9$$$) — the target positions of the stones. | 2,300 | If it is impossible to move the stones this way, print "NO". Otherwise, on the first line print "YES", on the second line print the number of operations $$$m$$$ ($$$0 \le m \le 5 \cdot n$$$) required. You don't have to minimize the number of operations. Then print $$$m$$$ lines, each containing integers $$$i, j, d$$$ ($$$1 \le i, j \le n$$$, $$$s_i \le s_j$$$, $$$0 \leq 2 \cdot d \leq s_j - s_i$$$), defining the operations. One can show that if an answer exists, there is an answer requiring no more than $$$5 \cdot n$$$ operations. | standard output | |
PASSED | fa0e5f69e88de0adc6001daedbae53b7 | train_000.jsonl | 1559399700 | There are $$$n$$$ stones arranged on an axis. Initially the $$$i$$$-th stone is located at the coordinate $$$s_i$$$. There may be more than one stone in a single place.You can perform zero or more operations of the following type: take two stones with indices $$$i$$$ and $$$j$$$ so that $$$s_i \leq s_j$$$, choose an integer $$$d$$$ ($$$0 \leq 2 \cdot d \leq s_j - s_i$$$), and replace the coordinate $$$s_i$$$ with $$$(s_i + d)$$$ and replace coordinate $$$s_j$$$ with $$$(s_j - d)$$$. In other words, draw stones closer to each other. You want to move the stones so that they are located at positions $$$t_1, t_2, \ldots, t_n$$$. The order of the stones is not important — you just want for the multiset of the stones resulting positions to be the same as the multiset of $$$t_1, t_2, \ldots, t_n$$$.Detect whether it is possible to move the stones this way, and if yes, construct a way to do so. You don't need to minimize the number of moves. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.StringTokenizer;
public class E {
public static void main(String[] args) throws IOException {
MyScanner sc = new MyScanner();
PrintWriter out = new PrintWriter(System.out);
int n = sc.nextInt();
List<Stone> from = new ArrayList<>(n), to = new ArrayList<>(n);
for (int i = 0; i < n; i++) {
int tmp = sc.nextInt();
from.add(new Stone(i + 1, tmp));
}
for (int i = 0; i < n; i++) {
int tmp = sc.nextInt();
to.add(new Stone(i + 1, tmp));
}
Collections.sort(from, Comparator.comparingInt(s -> s.pos));
Collections.sort(to, Comparator.comparingInt(s -> s.pos));
List<Ans> ret = new ArrayList<>();
int posI = -1, negI = -1;
int remPos = 0, remNeg = 0;
boolean can = true;
while (can) {
while (posI + 1 < n && remPos == 0) {
posI++;
if (from.get(posI).pos < to.get(posI).pos) {
remPos = to.get(posI).pos - from.get(posI).pos;
}
}
while (negI + 1 < n && remNeg == 0) {
negI++;
if (from.get(negI).pos > to.get(negI).pos) {
remNeg = from.get(negI).pos - to.get(negI).pos;
}
}
if (remPos > 0 && remNeg > 0) {
if (posI < negI) {
int move = Math.min(remPos, remNeg);
ret.add(new Ans(from.get(posI).id, from.get(negI).id, move));
remPos -= move;
remNeg -= move;
} else {
can = false;
}
} else if (remPos == 0 && remNeg == 0) {
break;
} else {
can = false;
}
}
if (can) {
out.println("YES");
out.println(ret.size());
for (Ans ans : ret) {
out.println(ans.i + " " + ans.j + " " + ans.d);
}
} else {
out.println("NO");
}
out.flush();
}
static class Stone {
int id, pos;
public Stone(int id, int pos) {
this.id = id;
this.pos = pos;
}
@Override
public String toString() {
return pos + "";
}
}
static class Ans {
int i, j, d;
public Ans(int i, int j, int d) {
this.i = i;
this.j = j;
this.d = d;
}
}
static class MyScanner {
private BufferedReader br;
private StringTokenizer tokenizer;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.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 | ["5\n2 2 7 4 9\n5 4 5 5 5", "3\n1 5 10\n3 5 7"] | 4 seconds | ["YES\n4\n4 3 1\n2 3 1\n2 5 2\n1 5 2", "NO"] | NoteConsider the first example. After the first move the locations of stones is $$$[2, 2, 6, 5, 9]$$$. After the second move the locations of stones is $$$[2, 3, 5, 5, 9]$$$. After the third move the locations of stones is $$$[2, 5, 5, 5, 7]$$$. After the last move the locations of stones is $$$[4, 5, 5, 5, 5]$$$. | Java 8 | standard input | [
"greedy",
"constructive algorithms",
"two pointers",
"math",
"sortings"
] | f236c4110a973d1c9f63cbbcc74b9e0b | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) – the number of stones. The second line contains integers $$$s_1, s_2, \ldots, s_n$$$ ($$$1 \le s_i \le 10^9$$$) — the initial positions of the stones. The second line contains integers $$$t_1, t_2, \ldots, t_n$$$ ($$$1 \le t_i \le 10^9$$$) — the target positions of the stones. | 2,300 | If it is impossible to move the stones this way, print "NO". Otherwise, on the first line print "YES", on the second line print the number of operations $$$m$$$ ($$$0 \le m \le 5 \cdot n$$$) required. You don't have to minimize the number of operations. Then print $$$m$$$ lines, each containing integers $$$i, j, d$$$ ($$$1 \le i, j \le n$$$, $$$s_i \le s_j$$$, $$$0 \leq 2 \cdot d \leq s_j - s_i$$$), defining the operations. One can show that if an answer exists, there is an answer requiring no more than $$$5 \cdot n$$$ operations. | standard output | |
PASSED | 88c26bdb6d2ad1f6352143a1e7c3ba5c | train_000.jsonl | 1559399700 | There are $$$n$$$ stones arranged on an axis. Initially the $$$i$$$-th stone is located at the coordinate $$$s_i$$$. There may be more than one stone in a single place.You can perform zero or more operations of the following type: take two stones with indices $$$i$$$ and $$$j$$$ so that $$$s_i \leq s_j$$$, choose an integer $$$d$$$ ($$$0 \leq 2 \cdot d \leq s_j - s_i$$$), and replace the coordinate $$$s_i$$$ with $$$(s_i + d)$$$ and replace coordinate $$$s_j$$$ with $$$(s_j - d)$$$. In other words, draw stones closer to each other. You want to move the stones so that they are located at positions $$$t_1, t_2, \ldots, t_n$$$. The order of the stones is not important — you just want for the multiset of the stones resulting positions to be the same as the multiset of $$$t_1, t_2, \ldots, t_n$$$.Detect whether it is possible to move the stones this way, and if yes, construct a way to do so. You don't need to minimize the number of moves. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.util.Random;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskE solver = new TaskE();
solver.solve(1, in, out);
out.close();
}
static class TaskE {
Random random = new Random(751454315315L + System.currentTimeMillis());
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
int[] t = new int[n];
TaskE.Stone[] stones = new TaskE.Stone[n];
for (int i = 0; i < n; ++i) {
int pos = in.nextInt();
stones[i] = new TaskE.Stone(pos, i + 1);
}
Arrays.sort(stones, new Comparator<TaskE.Stone>() {
public int compare(TaskE.Stone o1, TaskE.Stone o2) {
return o1.where - o2.where;
}
});
int[] s = new int[n];
int[] sFrom = new int[n];
for (int i = 0; i < n; ++i) {
s[i] = stones[i].where;
sFrom[i] = stones[i].index;
}
for (int i = 0; i < n; ++i) {
t[i] = in.nextInt();
}
sortArray(t);
int[] available = new int[n];
int[] via = new int[n];
int cnt = 0;
int[] resI = new int[5 * n];
int[] resJ = new int[5 * n];
int[] resBy = new int[5 * n];
int resPtr = 0;
for (int i = 0; i < n; ++i) {
int src = s[i];
int dst = t[i];
if (src < dst) {
available[cnt] = dst - src;
via[cnt] = i;
++cnt;
} else {
int need = src - dst;
while (need > 0 && cnt > 0) {
int by = Math.min(need, available[cnt - 1]);
resI[resPtr] = via[cnt - 1];
resJ[resPtr] = i;
resBy[resPtr] = by;
++resPtr;
need -= by;
if (by == available[cnt - 1]) {
--cnt;
} else {
available[cnt - 1] -= by;
}
}
if (need > 0) {
out.println("NO");
return;
}
}
}
if (cnt != 0) {
out.println("NO");
return;
}
out.println("YES");
out.println(resPtr);
for (int i = 0; i < resPtr; ++i) {
out.println(sFrom[resI[i]] + " " + sFrom[resJ[i]] + " " + resBy[i]);
}
}
private void sortArray(int[] s) {
shuffle(s);
Arrays.sort(s);
}
private void shuffle(int[] s) {
for (int i = 0; i < s.length; ++i) {
int j = random.nextInt(i + 1);
int t = s[i];
s[i] = s[j];
s[j] = t;
}
}
static class Stone {
int where;
int index;
public Stone(int where, int index) {
this.where = where;
this.index = index;
}
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| Java | ["5\n2 2 7 4 9\n5 4 5 5 5", "3\n1 5 10\n3 5 7"] | 4 seconds | ["YES\n4\n4 3 1\n2 3 1\n2 5 2\n1 5 2", "NO"] | NoteConsider the first example. After the first move the locations of stones is $$$[2, 2, 6, 5, 9]$$$. After the second move the locations of stones is $$$[2, 3, 5, 5, 9]$$$. After the third move the locations of stones is $$$[2, 5, 5, 5, 7]$$$. After the last move the locations of stones is $$$[4, 5, 5, 5, 5]$$$. | Java 8 | standard input | [
"greedy",
"constructive algorithms",
"two pointers",
"math",
"sortings"
] | f236c4110a973d1c9f63cbbcc74b9e0b | The first line contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) – the number of stones. The second line contains integers $$$s_1, s_2, \ldots, s_n$$$ ($$$1 \le s_i \le 10^9$$$) — the initial positions of the stones. The second line contains integers $$$t_1, t_2, \ldots, t_n$$$ ($$$1 \le t_i \le 10^9$$$) — the target positions of the stones. | 2,300 | If it is impossible to move the stones this way, print "NO". Otherwise, on the first line print "YES", on the second line print the number of operations $$$m$$$ ($$$0 \le m \le 5 \cdot n$$$) required. You don't have to minimize the number of operations. Then print $$$m$$$ lines, each containing integers $$$i, j, d$$$ ($$$1 \le i, j \le n$$$, $$$s_i \le s_j$$$, $$$0 \leq 2 \cdot d \leq s_j - s_i$$$), defining the operations. One can show that if an answer exists, there is an answer requiring no more than $$$5 \cdot n$$$ operations. | standard output | |
PASSED | 0e11a5458fb3377f6c0eccc55a22b9e1 | train_000.jsonl | 1438273200 | As you must know, the maximum clique problem in an arbitrary graph is NP-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices of this subset are connected by an edge. In particular, an empty set of vertexes and a set consisting of a single vertex, are cliques.Let's define a divisibility graph for a set of positive integers A = {a1, a2, ..., an} as follows. The vertices of the given graph are numbers from set A, and two numbers ai and aj (i ≠ j) are connected by an edge if and only if either ai is divisible by aj, or aj is divisible by ai.You are given a set of non-negative integers A. Determine the size of a maximum clique in a divisibility graph for set A. | 256 megabytes | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
public class cf566f_2 {
public static void main(String[] args) throws IOException {
int n = ri(), ans = 1, dp[] = new int[1000001];
r();
for (int i = 0; i < n; ++i) {
++dp[ni()];
}
for (int i = 1; i <= 1000000; ++i) {
if (dp[i] > 0) {
for (int j = i * 2; j <= 1000000; j += i) {
if (dp[j] > 0) {
ans = max(ans, dp[j] = max(dp[j], dp[i] + 1));
}
}
}
}
prln(ans);
close();
}
static BufferedReader __in = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter __out = new PrintWriter(new OutputStreamWriter(System.out));
static StringTokenizer input;
static Random __rand = new Random();
// references
// IBIG = 1e9 + 7
// IMAX ~= 2e9
// LMAX ~= 9e18
// constants
static final int IBIG = 1000000007;
static final int IMAX = 2147483647;
static final int IMIN = -2147483648;
static final long LMAX = 9223372036854775807L;
static final long LMIN = -9223372036854775808L;
// math util
static int minof(int a, int b, int c) {return min(a, min(b, c));}
static int minof(int... x) {if(x.length == 1) return x[0]; if(x.length == 2) return min(x[0], x[1]); if(x.length == 3) return min(x[0], min(x[1], x[2])); int min = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] < min) min = x[i]; return min;}
static long minof(long a, long b, long c) {return min(a, min(b, c));}
static long minof(long... x) {if(x.length == 1) return x[0]; if(x.length == 2) return min(x[0], x[1]); if(x.length == 3) return min(x[0], min(x[1], x[2])); long min = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] < min) min = x[i]; return min;}
static int maxof(int a, int b, int c) {return max(a, max(b, c));}
static int maxof(int... x) {if(x.length == 1) return x[0]; if(x.length == 2) return max(x[0], x[1]); if(x.length == 3) return max(x[0], max(x[1], x[2])); int max = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] > max) max = x[i]; return max;}
static long maxof(long a, long b, long c) {return max(a, max(b, c));}
static long maxof(long... x) {if(x.length == 1) return x[0]; if(x.length == 2) return max(x[0], x[1]); if(x.length == 3) return max(x[0], max(x[1], x[2])); long max = x[0]; for(int i = 1; i < x.length; ++i) if(x[i] > max) max = x[i]; return max;}
static int powi(int a, int b) {if(a == 0) return 0; int ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}
static long powl(long a, int b) {if(a == 0) return 0; long ans = 1; while(b > 0) {if((b & 1) > 0) ans *= a; a *= a; b >>= 1;} return ans;}
static int fli(double d) {return (int)d;}
static int cei(double d) {return (int)ceil(d);}
static long fll(double d) {return (long)d;}
static long cel(double d) {return (long)ceil(d);}
static int gcf(int a, int b) {return b == 0 ? a : gcf(b, a % b);}
static long gcf(long a, long b) {return b == 0 ? a : gcf(b, a % b);}
static int lcm(int a, int b) {return a * b / gcf(a, b);}
static long lcm(long a, long b) {return a * b / gcf(a, b);}
static int randInt(int min, int max) {return __rand.nextInt(max - min + 1) + min;}
static long hash(long x) {x += 0x9e3779b97f4a7c15L; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9L; x = (x ^ (x >> 27)) * 0x94d049bb133111ebL; return x ^ (x >> 31);}
// array util
static void reverse(int[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {int swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}
static void reverse(long[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {long swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}
static void reverse(char[] a) {for(int i = 0, n = a.length, half = n / 2; i < half; ++i) {char swap = a[i]; a[i] = a[n - i - 1]; a[n - i - 1] = swap;}}
static void shuffle(int[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); int swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}
static void shuffle(long[] a) {int n = a.length - 1; for(int i = 0; i < n; ++i) {int ind = randInt(i, n); long swap = a[i]; a[i] = a[ind]; a[ind] = swap;}}
static void rsort(int[] a) {shuffle(a); sort(a);}
static void rsort(long[] a) {shuffle(a); sort(a);}
static int[] copy(int[] a) {int[] ans = new int[a.length]; for(int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;}
static long[] copy(long[] a) {long[] ans = new long[a.length]; for(int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;}
static char[] copy(char[] a) {char[] ans = new char[a.length]; for(int i = 0; i < a.length; ++i) ans[i] = a[i]; return ans;}
// graph util
static List<List<Integer>> g(int n) {List<List<Integer>> g = new ArrayList<>(); for(int i = 0; i < n; ++i) g.add(new ArrayList<>()); return g;}
static List<Set<Integer>> sg(int n) {List<Set<Integer>> g = new ArrayList<>(); for(int i = 0; i < n; ++i) g.add(new HashSet<>()); return g;}
static void c(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).add(v); g.get(v).add(u);}
static void cto(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).add(v);}
static void dc(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).remove(v); g.get(v).remove(u);}
static void dcto(List<? extends Collection<Integer>> g, int u, int v) {g.get(u).remove(v);}
// input
static void r() throws IOException {input = new StringTokenizer(__in.readLine());}
static int ri() throws IOException {return Integer.parseInt(__in.readLine());}
static long rl() throws IOException {return Long.parseLong(__in.readLine());}
static int[] ria(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()); return a;}
static int[] riam1(int n) throws IOException {int[] a = new int[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Integer.parseInt(input.nextToken()) - 1; return a;}
static long[] rla(int n) throws IOException {long[] a = new long[n]; input = new StringTokenizer(__in.readLine()); for(int i = 0; i < n; ++i) a[i] = Long.parseLong(input.nextToken()); return a;}
static char[] rcha() throws IOException {return __in.readLine().toCharArray();}
static String rline() throws IOException {return __in.readLine();}
static int rni() throws IOException {input = new StringTokenizer(__in.readLine()); return Integer.parseInt(input.nextToken());}
static int ni() {return Integer.parseInt(input.nextToken());}
static long rnl() throws IOException {input = new StringTokenizer(__in.readLine()); return Long.parseLong(input.nextToken());}
static long nl() {return Long.parseLong(input.nextToken());}
static List<List<Integer>> rg(int n, int m) throws IOException {List<List<Integer>> g = g(n); for(int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1); return g;}
static void rg(List<List<Integer>> g, int m) throws IOException {for(int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1);}
static List<List<Integer>> rdg(int n, int m) throws IOException {List<List<Integer>> g = g(n); for(int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1); return g;}
static void rdg(List<List<Integer>> g, int m) throws IOException {for(int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1);}
static List<Set<Integer>> rsg(int n, int m) throws IOException {List<Set<Integer>> g = sg(n); for(int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1); return g;}
static void rsg(List<Set<Integer>> g, int m) throws IOException {for(int i = 0; i < m; ++i) c(g, rni() - 1, ni() - 1);}
static List<Set<Integer>> rdsg(int n, int m) throws IOException {List<Set<Integer>> g = sg(n); for(int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1); return g;}
static void rdsg(List<Set<Integer>> g, int m) throws IOException {for(int i = 0; i < m; ++i) cto(g, rni() - 1, ni() - 1);}
// output
static void pr(int i) {__out.print(i);}
static void prln(int i) {__out.println(i);}
static void pr(long l) {__out.print(l);}
static void prln(long l) {__out.println(l);}
static void pr(double d) {__out.print(d);}
static void prln(double d) {__out.println(d);}
static void pr(char c) {__out.print(c);}
static void prln(char c) {__out.println(c);}
static void pr(char[] s) {__out.print(new String(s));}
static void prln(char[] s) {__out.println(new String(s));}
static void pr(String s) {__out.print(s);}
static void prln(String s) {__out.println(s);}
static void pr(Object o) {__out.print(o);}
static void prln(Object o) {__out.println(o);}
static void prln() {__out.println();}
static void pryes() {__out.println("yes");}
static void pry() {__out.println("Yes");}
static void prY() {__out.println("YES");}
static void prno() {__out.println("no");}
static void prn() {__out.println("No");}
static void prN() {__out.println("NO");}
static void pryesno(boolean b) {__out.println(b ? "yes" : "no");};
static void pryn(boolean b) {__out.println(b ? "Yes" : "No");}
static void prYN(boolean b) {__out.println(b ? "YES" : "NO");}
static void prln(int... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}
static void prln(long... a) {for(int i = 0, len = a.length - 1; i < len; __out.print(a[i]), __out.print(' '), ++i); __out.println(a[a.length - 1]);}
static <T> void prln(Collection<T> c) {int n = c.size() - 1; Iterator<T> iter = c.iterator(); for(int i = 0; i < n; __out.print(iter.next()), __out.print(' '), ++i); if(n >= 0) __out.println(iter.next()); else __out.println();}
static void h() {__out.println("hlfd");}
static void flush() {__out.flush();}
static void close() {__out.close();}
} | Java | ["8\n3 4 6 8 10 18 21 24"] | 1 second | ["3"] | NoteIn the first sample test a clique of size 3 is, for example, a subset of vertexes {3, 6, 18}. A clique of a larger size doesn't exist in this graph. | Java 11 | standard input | [
"dp",
"number theory",
"math"
] | f33991da3b4a57dd6535af86edeeddc0 | The first line contains integer n (1 ≤ n ≤ 106), that sets the size of set A. The second line contains n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 106) — elements of subset A. The numbers in the line follow in the ascending order. | 1,500 | Print a single number — the maximum size of a clique in a divisibility graph for set A. | standard output | |
PASSED | 0642303f3b09839d3e58249aae1c43df | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes | import java.io.*;
import java.math.*;
import java.util.*;
public class A {
public static void main(String[] agrs) {
FastScanner sc = new FastScanner();
int yo = sc.nextInt();
while(yo-->0) {
long n = sc.nextLong();
if(n%4 == 0) {
System.out.println("YES");
}
else {
System.out.println("NO");
}
}
}
static int mod = 1000000007;
static long pow(int a, int b) {
if(b == 0) {
return 1;
}
if(b == 1) {
return a;
}
if(b%2 == 0) {
long ans = pow(a,b/2);
return ans*ans;
}
else {
long ans = pow(a,(b-1)/2);
return a * ans * ans;
}
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
} | Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | b48bc8f7e48b1b48de43f11e86714674 | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
Scanner in = new Main().new Scanner(inputStream);
Main solver = new Main();
solver.solve(in);
}
public void solve(Scanner in) {
int t = in.ni();
for (int i = 0; i < t; i++) {
long l = in.nl();
System.out.println(l % 4 == 0 ? "YES" : "NO");
}
}
class Scanner {
BufferedReader br;
StringTokenizer in;
public Scanner(InputStream inputStream) {
br = new BufferedReader(new InputStreamReader(inputStream));
}
public String next() {
return hasMoreTokens() ? in.nextToken() : null;
}
public String readLine() {
try {
return br.readLine();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
boolean hasMoreTokens() {
while (in == null || !in.hasMoreTokens()) {
String s = readLine();
if (s == null)
return false;
in = new StringTokenizer(s);
}
return true;
}
public String nextString() {
return next();
}
public int ni() {
return Integer.parseInt(nextString());
}
public long nl() {
return Long.parseLong(nextString());
}
public int[] nia(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ni();
}
return a;
}
public long[] nla(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = ni();
}
return a;
}
}
}
| Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | 25ef3fe56fbc344c849d3021da2c4cf1 | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes | import java.util.*;
public class gay {
public static void main (String [] args) {
Scanner kb = new Scanner (System.in);
int num = kb.nextInt();
for (int i=0; i<num; i++) {
if (kb.nextInt()%4==0) {
System.out.println("YES");
}
else {
System.out.println("NO");
}//
}
}
} | Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | 3e6406c15268654b481da7a840c77d6b | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes | import java.util.*;
public class Solution{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
for(int t=0;t<T;t++){
long n=sc.nextLong();
if(n%4==0)
System.out.println("YES");
else System.out.println("NO");
}
}
} | Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | 64a197401464564fad7850e14ae81633 | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes | import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
public class C {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0){
int n = sc.nextInt();
// n = n/4;
if (n % 4 == 0) System.out.println("YES");
else System.out.println("NO");
}
}
}
| Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | 2a66508a22e8e901c222edbb71c8b8ed | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes |
import java.util.Scanner;
public class fashionablee {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner = new Scanner(System.in);
int length = scanner.nextInt();
int i;
for(i=0;i<length;i++)
{
int n = scanner.nextInt();
if((n%4)==0)
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}
}
}
}
| Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | a3b6fd9cade4f97d9cdf65f7dfa46f71 | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes |
import java.io.*;
import java.util.*;
public class CP {
static Scanner sc = new Scanner(System.in);
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 int lowerBound
(Integer[] array, int length, int value) {
int l = 0;
int r = length;
while (l < r) {
int mid = (l + r) / 2;
if (value < array[mid]) {
r = mid;
} else {
l = mid + 1;
}
}
return l;
}
public static long gcd(long a, long b){
if (b == 0)
return a;
else return gcd(b, a % b);
}
public static void swap(int x, int y ){
int temp =y;
y=x;
x=temp;
}
public static void main(String [] args) {
int T = sc.nextInt();while (T--!=0)
{
solve();
}
}
public static void solve() {
///////////////////////////////////////////////////////////////////////////////////////////
int n =sc.nextInt();
if(n%2!=0){
System.out.println("NO");
return;
}
n-=2;
n/=2;
if(n%2==0) System.out.println("NO");
else System.out.println("YES");
////////////////////////////////////////////////////////////////////////////////////////////
}
} | Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | 8d90b75dd7b95aab24b4c645905c12f7 | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes | import java.util.*;
import java.io.*;
@SuppressWarnings("unused")
public class HelloWorld {
static class InputReader{
BufferedReader reader;
StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public Long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
static InputReader r = new InputReader(System.in);
static PrintWriter pw = new PrintWriter(System.out);
public static void main(String[] args) {
new Solve();
pw.close();
}
static class Solve {
Solve() {
int t = r.nextInt();
while (t-- != 0) {
int n = r.nextInt();
if (n % 4 != 0) {
pw.println("NO");
} else {
pw.println("YES");
}
}
return;
}
}
}
| Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | a644b1f6be7fafcbbf384c72fd0ad367 | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class FashionabLee {
public static void main(String[] args) throws IOException {
BufferedReader f = new BufferedReader(
new InputStreamReader(System.in));
int cases = Integer.parseInt(f.readLine());
int sides;
int i;
for(i = 0; i < cases; i++)
{
sides = Integer.parseInt(f.readLine());
if(sides % 4 == 0)
System.out.println("YES");
else
System.out.println("NO");
}
}
}
| Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | 35a067cf0d34b67f01a323a843abeaa0 | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes | import java.util.Scanner;
public class Main
{
public static void main(String[]args)
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
if(n%4==0)
System.out.println("YES");
else
System.out.println("NO");
}
}
} | Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | 6b90ee4ac027119b33fbd6cf2046daae | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes | import java.util.Scanner;
public class maxGCD {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s = new Scanner(System.in);
int T = s.nextInt();
while(T>0)
{
int n = s.nextInt();
if((n-2)%2==0)
{
if(((n-2)/2)%2 !=0 )
System.out.println("YES");
else
System.out.println("NO");
}
else
System.out.println("NO");
T--;
}
}
}
| Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | 02fa38d1910b0a0cd3091883b3cd35a0 | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes | import java.util.*;
public class try2{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int t=input.nextInt();
while(t!=0){
int n=input.nextInt();
// // int each=((2*n)-4)*90;
// int allangle=((n-2)*180)/n;
// System.out.println(allangle);
if(n%4==0)
System.out.println("YES");
else
System.out.println("NO");
t--;
}
}
} | Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | b16b1f02e2b9bac6b75c64bf2639dd74 | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.StringTokenizer;
import java.io.OutputStreamWriter;
import java.io.InputStreamReader;
import java.io.FileOutputStream;
public class Pa{
public static void main(String[] args)throws IOException{
FastReader sc = new FastReader();
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out),"ASCII"),512);
int t = sc.nextInt();
while(t-- > 0){
int n = sc.nextInt();
if(n%4==0) out.write("YES");
else out.write("NO");
out.write('\n');
out.flush();
}
}
}
class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br = new BufferedReader(new InputStreamReader(System.in));
}
String next(){
while (st == null || !st.hasMoreElements()){
try{
st = new StringTokenizer(br.readLine());
}
catch (IOException e){
e.printStackTrace();
}
}
return st.nextToken();
}
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 | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | 29fd3b56d3ede51fdf7b28bc8f2af871 | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
int n = 0;
for (int i = 0; i < t; i++)
{
n = scan.nextInt();
if (n < 4)
{
System.out.println("NO");
continue;
}
if (n % 4 == 0) System.out.println("YES");
else System.out.println("NO");
}
}
static void solution(Scanner scan) {
int n = scan.nextInt();
double p = scan.nextDouble();
int t = scan.nextInt();
double[][] matrix = new double[t + 1][n + 1];
matrix[0][0] = 1;
for (int i = 1; i <= t; i++) {
for (int j = 0; j <= i && j <= n; j++) {
if (j == n) {
matrix[i][j] = matrix[i - 1][j - 1] * p + matrix[i - 1][j];
continue;
}
if (j == 0) matrix[i][j] += matrix[i - 1][0] * (1 - p);
else matrix[i][j] += matrix[i - 1][j - 1] * p + matrix[i - 1][j] * (1 - p);
}
}
double sum = 0;
for (int i = 0; i <= n; i++) {
sum += matrix[t][i] * i;
}
System.out.println(sum);
}
} | Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | 7e5b6e20a3b4f352cfe2e53d18e0b8ca | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes | import java.util.*;
public class Main
{
public static void main(String args[])
{
int i;
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int a[]=new int[n];
for(i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
for(i=0;i<n;i++)
{
if(a[i]%4==0)
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}
}
}
} | Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | 8b7a6f124674fa8ca299be7e890bc3d9 | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes | /******************************************************************************
Online Java Compiler.
Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.
*******************************************************************************/
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
if(n%4==0)
System.out.println("YES");
else
System.out.println("NO");
}
sc.close();
}
}
| Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | ded982859d649f51de436f7c75b81f22 | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes | //package com.company;
import java.io.*;
import java.util.*;
public class Main {
static int isprime(long n) {
int flag = 0;
for (int i = 2; i <= (Math.sqrt(n)); i++) {
if (n % i == 0) {
flag = 1;
break;
}
}
if (flag == 0)
return 1;
else return 0;
}
public static void main(String[] args) {
StringBuffer s = new StringBuffer();
Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
int t = sc.nextInt();
while (t-- > 0)
{
long n=sc.nextLong();
if(n>8)
{
if (n % 8 == 0)
s.append("YES" + "\n");
else if(n%4==0)
s.append("YES" + "\n");
else
s.append("NO" + "\n");
}
else {
if (n == 4)
s.append("YES" + "\n");
else
s.append("NO" + "\n");
}
// s.append();
}
System.out.println(s);
}
}
| Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | 5ffe68397b5697734f290f95b04133d8 | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes | //package com.company;
import java.io.*;
import java.util.*;
public class Main {
static int isprime(long n) {
int flag = 0;
for (int i = 2; i <= (Math.sqrt(n)); i++) {
if (n % i == 0) {
flag = 1;
break;
}
}
if (flag == 0)
return 1;
else return 0;
}
public static void main(String[] args) {
StringBuffer s = new StringBuffer();
Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
int t = sc.nextInt();
while (t-- > 0)
{
long n=sc.nextLong();
if(n%4==0)
{
s.append("YES" + "\n");
}
else {
s.append("NO" + "\n");
}
// s.append();
}
System.out.println(s);
}
}
| Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | 425fa996a5e0ef3a0148bd3b4767b2cb | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes | import java.util.*;
import java.io.*;
public class Problem{
public static void main(String[] args) throws NumberFormatException, IOException{
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
while(t-->0) {
int n=Integer.parseInt(br.readLine());
if(n%4==0) {
System.out.println("Yes");
}
else{
System.out.println("No");
}
}
}
} | Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | cf9ea8bf9e20eec88ce8e2b5d009f09d | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes | import java.util.Scanner;
//Solve No 5
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int t = input.nextInt();
for (int i = 0; i <t; i++) {
int a = input.nextInt();
if (a%4==0) {
System.out.println("YES");
}
else {
System.out.println("NO");
}
}
input.close();
}
} | Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | d5e0489aaadc565aa4b1109f25f49ab4 | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes | import java.io.IOException;
import java.util.Scanner;
public class Codeforces {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int x = 0;
while (n > 0) {
x = scanner.nextInt();
String answer = x%4 == 0 ? "yes" : "no";
System.out.println(answer);
n--;
}
}
}
| Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | d3b98cf3a9d7e10458ed2db631a1d86a | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes |
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
public static int r(int n){
while(n%2==0){
n=n/2;
}
return n;
}
public static int r2(int a){
if(a==0){
a=1;
}
else{
a=0;
}
return a;
}
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[]) throws Exception
{
FastReader sc = new FastReader();
PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t=sc.nextInt();
for(int test=0;test<t;test++){
int n=sc.nextInt();
if(n%4!=0){
System.out.println("NO");
}
else{
System.out.println("YES");
}
}
}
}
| Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | 00b2feb2056171fa193f6276dd16e0e3 | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes |
import java.io.*;
import java.sql.Array;
import java.util.*;
public class Main {
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 String readLine() throws IOException
{
byte[] buf = new byte[1000001]; // line length
int cnt = 0, c;
while((c = read()) <= ' '){}
do{
if (c == 13 || c == 10)
break;
buf[cnt++] = (byte) c;
}while ((c = read()) != -1);
return new String(buf, 0, cnt);
}
public String next() throws IOException
{
byte[] buf = new byte[2000001]; // line length
int cnt = 0, c;
while((c = read()) <= ' '){}
do{
buf[cnt++] = (byte) c;
}while ((c = read()) != -1 && c > ' ');
return new String(buf, 0, cnt);
}
public int[] nextArray(int N) throws IOException{
int[] arr = new int[N];
for(int i = 0;i<N;i++)arr[i] = nextInt();
return arr;
}
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 print(int[] arr){
for(int i = 0 ;i<arr.length;i++){
System.out.print((arr[i])+" ");
}
System.out.println("");
}
public static void print(int[][] arr){
for(int i = 0 ;i<arr.length;i++) {
for (int j = 0; j < arr[0].length; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println("");
}
}
public static void print(ArrayList<Integer> arr){
for(int i:arr){
System.out.print(i+" ");
}
System.out.println("");
}
public static long prime = 1000000007;
public static class pair<E,V>{
E a;
V b;
public pair(E a1,V a2){
this.a = a1;
this.b = a2;
}
@Override
public boolean equals(Object obj) {
pair temp = (pair)obj;
return ((temp.a == this.a) && (temp.b == this.b));
}
@Override
public int hashCode() {
return (int)((long)a^(long)b);
}
}
public static void main(String[] args) throws IOException {
Reader sc = new Reader();
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
//System.out.println((-7%5)+" "+(-2%5)+" "+(3%5));
int tc = sc.nextInt();
while(tc-- > 0){
int N = sc.nextInt();
N -= 4;
if(N%4 == 0)pw.println("YES");
else pw.println("NO");
}
pw.flush();
}
}
| Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | 183d1700febaa19621b8dc099263c203 | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes | import java.io.*;
import java.util.*;
import java.math.BigInteger;
import java.math.BigDecimal;
import java.math.RoundingMode;
public class forces{
public static void main(String args[])throws IOException{
//DataInputStream ins = new DataInputStream(System.in);
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i=0;i<t;i++){
int n= sc.nextInt();
System.out.println((n%4 == 0) ? "YES": "NO");
}
}
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
}
/*
*/ | Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | e0bd81778ac65767a91e1e8d220373b0 | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes |
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Solution {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
//System.out.println("Kickstart baby!!");
int test=s.nextInt();
while(test-->0)
{
long n=s.nextLong();
if(n%4==0)
System.out.println("YES");
else
System.out.println("NO");
}
}
}
| Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | a66e31ef937f789160e066cfdd856ef8 | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes |
import java.util.*;
public class CodeForces {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int m,n;
n=in.nextInt();
for(int i=0;i<n;i++)
{
m=in.nextInt();
if(m%4!=0)
System.out.println("NO");
else
System.out.println("YES");
}
}
}
| Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | 49efc8a2e458bf39d0aa82b7c7d67ce3 | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes |
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.Scanner;
public class Fashinablee {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s=new Scanner(System.in);
int t=s.nextInt();
for(int i=0;i<t;i++) {
int n=s.nextInt();
if((n%4)==0) {
System.out.println("YES");
}
else {
System.out.println("NO");
}
}
}
}
| Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | 99746434007b9f973b833e59c9707077 | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes | //package Codeforces;
import java.util.*;
public class Codeforces {
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int t;
t = scan.nextInt();
while(t != 0){
long n;
n = scan.nextLong();
if(n%4 == 0){
System.out.println("YES");
}
else{
System.out.println("NO");
}
t--;
}
scan.close();
}
}
| Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | e2a69b75c15ee9b6b78e6fcc3b5b490a | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes |
import java.util.*;
import java.io.*;
public class WeirdAlgorithm {
public static void main(String[] args) {
FastReader sc = new FastReader();
int t = sc.nextInt();
Map<String, Boolean> map=new HashMap<>();
while (t-->0) {
int n = sc.nextInt();
System.out.println(n%4==0?"YES":"NO");
}
}
private static boolean preSum(int[] nums, int target) {
int cur = 0;
Set<Integer> set = new HashSet<>();
set.add(0);
for (int i = 0; i < nums.length; i++) {
cur += nums[i];
if (set.contains(cur-target)) {
System.out.println(cur-target);
return true;
}
set.add(cur);
}
return false;
}
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 | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | bb1e0757441675de7685e5e8f1c90896 | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes | import java.util.*;
public class Convex{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
int test=sc.nextInt();
for(int i=0;i<test;i++){
long n=sc.nextLong();
if(((n-2)*180)/n<180 && n%4==0){
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
}
} | Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | 1d2b734d71ea5bb6de6b03d277d52cfd | train_000.jsonl | 1592921100 | Lee is going to fashionably decorate his house for a party, using some regular convex polygons...Lee thinks a regular $$$n$$$-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the $$$OX$$$-axis and at least one of its edges is parallel to the $$$OY$$$-axis at the same time.Recall that a regular $$$n$$$-sided polygon is a convex polygon with $$$n$$$ vertices such that all the edges and angles are equal.Now he is shopping: the market has $$$t$$$ regular polygons. For each of them print YES if it is beautiful and NO otherwise. | 256 megabytes | import java.util.*;
public class Demo {
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int n=s.nextInt();
for(int i=0;i<n;i++)
{
int a=s.nextInt();
if(a%4==0)
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}
}
}
} | Java | ["4\n3\n4\n12\n1000000000"] | 2 seconds | ["NO\nYES\nYES\nYES"] | NoteIn the example, there are $$$4$$$ polygons in the market. It's easy to see that an equilateral triangle (a regular $$$3$$$-sided polygon) is not beautiful, a square (a regular $$$4$$$-sided polygon) is beautiful and a regular $$$12$$$-sided polygon (is shown below) is beautiful as well. | Java 11 | standard input | [
"geometry",
"math"
] | 07e56d4031bcb119d2f684203f7ed133 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of polygons in the market. Each of the next $$$t$$$ lines contains a single integer $$$n_i$$$ ($$$3 \le n_i \le 10^9$$$): it means that the $$$i$$$-th polygon is a regular $$$n_i$$$-sided polygon. | 800 | For each polygon, print YES if it's beautiful or NO otherwise (case insensitive). | standard output | |
PASSED | 82fa63af728613ca187dcf8520c99436 | train_000.jsonl | 1348500600 | There are n piles of stones of sizes a1, a2, ..., an lying on the table in front of you.During one move you can take one pile and add it to the other. As you add pile i to pile j, the size of pile j increases by the current size of pile i, and pile i stops existing. The cost of the adding operation equals the size of the added pile.Your task is to determine the minimum cost at which you can gather all stones in one pile. To add some challenge, the stone piles built up conspiracy and decided that each pile will let you add to it not more than k times (after that it can only be added to another pile). Moreover, the piles decided to puzzle you completely and told you q variants (not necessarily distinct) of what k might equal. Your task is to find the minimum cost for each of q variants. | 256 megabytes | import java.io.*;
import java.util.*;
public class P226B
{
public static StringTokenizer st;
public static void nextLine(BufferedReader br) throws IOException
{
st = new StringTokenizer(br.readLine());
}
public static String next()
{
return st.nextToken();
}
public static int nextInt()
{
return Integer.parseInt(st.nextToken());
}
public static long nextLong()
{
return Long.parseLong(st.nextToken());
}
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
nextLine(br);
int n = nextInt();
ArrayList<Long> list = new ArrayList<Long>();
nextLine(br);
for (int i = 0; i < n; i++)
{
list.add(nextLong());
//list.add(1000000000L);
}
nextLine(br);
int m = nextInt();
int[] q = new int[m];
nextLine(br);
for (int i = 0; i < m; i++) q[i] = nextInt();
Collections.sort(list);
long[] sum = new long[n+1];
sum[0] = 0;
for (int i = 1; i < n+1; i++)
{
sum[i] = sum[i-1] + list.get(i-1);
}
long[] ans = new long[n];
Arrays.fill(ans, 0);
for (int i = 1; i < n; i++)
{
int times = 1;
long a = i;
long pos = n-1;
while (pos > 0)
{
long lb = pos > a ? pos-a : 0;
long val = sum[(int)pos] - sum[(int)lb];
ans[i] += val * times;
times++;
pos -= a;
a *= i;
}
}
StringBuffer sb = new StringBuffer();
for (int i = 0; i < m; i++)
{
if (q[i] >= n)
{
sb.append(sum[n-1]);
}
else
{
sb.append(ans[q[i]]);
}
sb.append(" ");
}
sb.deleteCharAt(sb.length() - 1);
System.out.println(sb.toString());
}
}
| Java | ["5\n2 3 4 1 1\n2\n2 3"] | 2 seconds | ["9 8"] | NoteIn the first sample one way to get the optimal answer goes like this: we add in turns the 4-th and the 5-th piles to the 2-nd one; then we add the 1-st pile to the 3-rd one; we add the 2-nd pile to the 3-rd one. The first two operations cost 1 each; the third one costs 2, the fourth one costs 5 (the size of the 2-nd pile after the first two operations is not 3, it already is 5). In the second sample you can add the 2-nd pile to the 3-rd one (the operations costs 3); then the 1-st one to the 3-th one (the cost is 2); then the 5-th one to the 4-th one (the costs is 1); and at last, the 4-th one to the 3-rd one (the cost is 2). | Java 7 | standard input | [
"greedy"
] | 87045c4df69110642122f2c114476947 | The first line contains integer n (1 ≤ n ≤ 105) — the number of stone piles. The second line contains n space-separated integers: a1, a2, ..., an (1 ≤ ai ≤ 109) — the initial sizes of the stone piles. The third line contains integer q (1 ≤ q ≤ 105) — the number of queries. The last line contains q space-separated integers k1, k2, ..., kq (1 ≤ ki ≤ 105) — the values of number k for distinct queries. Note that numbers ki can repeat. | 1,900 | Print q whitespace-separated integers — the answers to the queries in the order, in which the queries are given in the input. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | 5bc9b8bb02539e444db8d90284b4c982 | train_000.jsonl | 1348500600 | There are n piles of stones of sizes a1, a2, ..., an lying on the table in front of you.During one move you can take one pile and add it to the other. As you add pile i to pile j, the size of pile j increases by the current size of pile i, and pile i stops existing. The cost of the adding operation equals the size of the added pile.Your task is to determine the minimum cost at which you can gather all stones in one pile. To add some challenge, the stone piles built up conspiracy and decided that each pile will let you add to it not more than k times (after that it can only be added to another pile). Moreover, the piles decided to puzzle you completely and told you q variants (not necessarily distinct) of what k might equal. Your task is to find the minimum cost for each of q variants. | 256 megabytes | import java.io.*;
import java.util.*;
public class B {
public static void main(String[] args) throws Exception {
new B().solve();
// new FileInputStream(new File("input.txt")),
// new PrintStream(new FileOutputStream(new File("output.txt"))));
}
void solve() throws IOException {
BufferedReader in = new BufferedReader(new
InputStreamReader(System.in));
Scanner sc = new Scanner(System.in);
String[] sp;
int n = Integer.parseInt(in.readLine());
Integer[] a = new Integer[n];
sp = in.readLine().split(" ");
for (int i = 0; i < sp.length; i++) {
a[i] = Integer.parseInt(sp[i]);
}
int Q = Integer.parseInt(in.readLine());
int[] k = new int[Q];
sp = in.readLine().split(" ");
for (int i = 0; i < Q; i++) {
k[i] = Integer.parseInt(sp[i]);
}
Arrays.sort(a);
for (int i = 0; i < n - 1 - i; i++) {
int tmp = a[i];
a[i] = a[n - 1 - i];
a[n - 1 - i] = tmp;
}
// sum
long[] sum = new long[n];
sum[0] = a[0];
for (int i = 1; i < n; i++) {
sum[i] = sum[i - 1] + a[i];
}
StringBuilder sb = new StringBuilder();
long[] memo = new long[100100];
Arrays.fill(memo, -1);
for (int qi = 0; qi < Q; qi++) {
long cost = 0;
if (memo[k[qi]] != -1) {
cost = memo[k[qi]];
} else {
if (k[qi] == 1) {
for (int d = 1; d < n; d++) {
cost += (long) d * a[d];
}
} else {
long idx = 1;
for (int d = 1; idx < n; d++) {
long w = (long) Math.pow(k[qi], d);
cost += d * (sum[(int) Math.min(n - 1, idx + w - 1)] - sum[(int) (idx - 1)]);
idx += w;
}
}
memo[k[qi]] = cost;
}
sb.append(cost);
sb.append(" ");
}
System.out.println(sb);
}
}
| Java | ["5\n2 3 4 1 1\n2\n2 3"] | 2 seconds | ["9 8"] | NoteIn the first sample one way to get the optimal answer goes like this: we add in turns the 4-th and the 5-th piles to the 2-nd one; then we add the 1-st pile to the 3-rd one; we add the 2-nd pile to the 3-rd one. The first two operations cost 1 each; the third one costs 2, the fourth one costs 5 (the size of the 2-nd pile after the first two operations is not 3, it already is 5). In the second sample you can add the 2-nd pile to the 3-rd one (the operations costs 3); then the 1-st one to the 3-th one (the cost is 2); then the 5-th one to the 4-th one (the costs is 1); and at last, the 4-th one to the 3-rd one (the cost is 2). | Java 7 | standard input | [
"greedy"
] | 87045c4df69110642122f2c114476947 | The first line contains integer n (1 ≤ n ≤ 105) — the number of stone piles. The second line contains n space-separated integers: a1, a2, ..., an (1 ≤ ai ≤ 109) — the initial sizes of the stone piles. The third line contains integer q (1 ≤ q ≤ 105) — the number of queries. The last line contains q space-separated integers k1, k2, ..., kq (1 ≤ ki ≤ 105) — the values of number k for distinct queries. Note that numbers ki can repeat. | 1,900 | Print q whitespace-separated integers — the answers to the queries in the order, in which the queries are given in the input. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | abcfb53c6ec2550fd44ffd8d5e1f7a53 | train_000.jsonl | 1348500600 | There are n piles of stones of sizes a1, a2, ..., an lying on the table in front of you.During one move you can take one pile and add it to the other. As you add pile i to pile j, the size of pile j increases by the current size of pile i, and pile i stops existing. The cost of the adding operation equals the size of the added pile.Your task is to determine the minimum cost at which you can gather all stones in one pile. To add some challenge, the stone piles built up conspiracy and decided that each pile will let you add to it not more than k times (after that it can only be added to another pile). Moreover, the piles decided to puzzle you completely and told you q variants (not necessarily distinct) of what k might equal. Your task is to find the minimum cost for each of q variants. | 256 megabytes | /* Codeforces Template */
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.fill;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.sort;
public class Main {
static long initTime;
static final Random rnd = new Random(7777L);
static boolean writeLog = false;
public static void main(String[] args) throws IOException {
initTime = System.currentTimeMillis();
try {
writeLog = "true".equals(System.getProperty("LOCAL_RUN"));
} catch (SecurityException e) {}
new Thread(null, new Runnable() {
public void run() {
try {
try {
if (new File("input.txt").exists())
System.setIn(new FileInputStream("input.txt"));
} catch (SecurityException e) {}
long prevTime = System.currentTimeMillis();
new Main().run();
System.err.println("Total time: " + (System.currentTimeMillis() - prevTime) + " ms");
System.err.println("Memory status: " + memoryStatus());
} catch (IOException e) {
e.printStackTrace();
}
}
}, "1", 1L << 24).start();
}
void run() throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
in.close();
}
/***************************************************************
* Solution
**************************************************************/
int n;
int[] a;
long[] sum;
void solve() throws IOException {
n = nextInt();
a = nextIntArray(n);
sort(a);
sum = new long [n + 1];
for (int i = 1; i <= n; i++) {
sum[i] = sum[i - 1] + a[n - i];
}
long[] ans = new long [n];
fill(ans, -1L);
int Q = nextInt();
long[] q = new long [Q];
for (int i = 0; i < Q; i++) {
int k = min(nextInt(), n - 1);
if (ans[k] == -1L) {
ans[k] = solve(k);
}
q[i] = ans[k];
}
printArray(q);
}
long solve(int k) {
long ret = 0L;
long l = 0;
long r = 0;
long sz = 1;
for (int level = 1; l < n; level++) {
sz *= k;
l = r + 1;
r = r + sz;
if (l >= n)
break;
ret += level * (sum[(int) min(r, n - 1) + 1] - sum[(int) l]);
}
return ret;
}
/***************************************************************
* Input
**************************************************************/
BufferedReader in;
PrintWriter out;
StringTokenizer st = new StringTokenizer("");
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());
}
int[] nextIntArray(int size) throws IOException {
int[] ret = new int [size];
for (int i = 0; i < size; i++)
ret[i] = nextInt();
return ret;
}
long[] nextLongArray(int size) throws IOException {
long[] ret = new long [size];
for (int i = 0; i < size; i++)
ret[i] = nextLong();
return ret;
}
double[] nextDoubleArray(int size) throws IOException {
double[] ret = new double [size];
for (int i = 0; i < size; i++)
ret[i] = nextDouble();
return ret;
}
String nextLine() 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;
}
/***************************************************************
* Output
**************************************************************/
void printRepeat(String s, int count) {
for (int i = 0; i < count; i++)
out.print(s);
}
void printArray(int[] array) {
if (array == null || array.length == 0)
return;
for (int i = 0; i < array.length; i++) {
if (i > 0) out.print(' ');
out.print(array[i]);
}
out.println();
}
void printArray(long[] array) {
if (array == null || array.length == 0)
return;
for (int i = 0; i < array.length; i++) {
if (i > 0) out.print(' ');
out.print(array[i]);
}
out.println();
}
void printArray(double[] array) {
if (array == null || array.length == 0)
return;
for (int i = 0; i < array.length; i++) {
if (i > 0) out.print(' ');
out.print(array[i]);
}
out.println();
}
void printArray(double[] array, String spec) {
if (array == null || array.length == 0)
return;
for (int i = 0; i < array.length; i++) {
if (i > 0) out.print(' ');
out.printf(Locale.US, spec, array[i]);
}
out.println();
}
void printArray(Object[] array) {
if (array == null || array.length == 0)
return;
boolean blank = false;
for (Object x : array) {
if (blank) out.print(' '); else blank = true;
out.print(x);
}
out.println();
}
@SuppressWarnings("rawtypes")
void printCollection(Collection collection) {
if (collection == null || collection.isEmpty())
return;
boolean blank = false;
for (Object x : collection) {
if (blank) out.print(' '); else blank = true;
out.print(x);
}
out.println();
}
/***************************************************************
* Utility
**************************************************************/
static String memoryStatus() {
return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() >> 20) + "/" + (Runtime.getRuntime().totalMemory() >> 20) + " MB";
}
static void checkMemory() {
System.err.println(memoryStatus());
}
static long prevTimeStamp = Long.MIN_VALUE;
static void updateTimer() {
prevTimeStamp = System.currentTimeMillis();
}
static long elapsedTime() {
return (System.currentTimeMillis() - prevTimeStamp);
}
static void checkTimer() {
System.err.println(elapsedTime() + " ms");
}
static void chk(boolean f) {
if (!f) throw new RuntimeException("Assert failed");
}
static void chk(boolean f, String format, Object ... args) {
if (!f) throw new RuntimeException(String.format(format, args));
}
static void log(String format, Object ... args) {
if (writeLog) System.err.println(String.format(Locale.US, format, args));
}
}
| Java | ["5\n2 3 4 1 1\n2\n2 3"] | 2 seconds | ["9 8"] | NoteIn the first sample one way to get the optimal answer goes like this: we add in turns the 4-th and the 5-th piles to the 2-nd one; then we add the 1-st pile to the 3-rd one; we add the 2-nd pile to the 3-rd one. The first two operations cost 1 each; the third one costs 2, the fourth one costs 5 (the size of the 2-nd pile after the first two operations is not 3, it already is 5). In the second sample you can add the 2-nd pile to the 3-rd one (the operations costs 3); then the 1-st one to the 3-th one (the cost is 2); then the 5-th one to the 4-th one (the costs is 1); and at last, the 4-th one to the 3-rd one (the cost is 2). | Java 7 | standard input | [
"greedy"
] | 87045c4df69110642122f2c114476947 | The first line contains integer n (1 ≤ n ≤ 105) — the number of stone piles. The second line contains n space-separated integers: a1, a2, ..., an (1 ≤ ai ≤ 109) — the initial sizes of the stone piles. The third line contains integer q (1 ≤ q ≤ 105) — the number of queries. The last line contains q space-separated integers k1, k2, ..., kq (1 ≤ ki ≤ 105) — the values of number k for distinct queries. Note that numbers ki can repeat. | 1,900 | Print q whitespace-separated integers — the answers to the queries in the order, in which the queries are given in the input. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | standard output | |
PASSED | f0b0bc2b27ed94634a6476941d379f3c | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
public class codeforces{
public static void main(String[] args) throws IOException{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
StringBuilder str=new StringBuilder();
PrintWriter out=new PrintWriter(System.out);
String[] lol=br.readLine().split(" ");
int n=Integer.parseInt(lol[0]);
int k=Integer.parseInt(lol[1]);
int[] a=new int[k+1];
int odd=0;
for(int i=0;i<n;i++)
a[Integer.parseInt(br.readLine())]++;
for(int i=0;i<=k;i++){
if(a[i]%2==1)
odd++;
}
str.append(n-odd/2);
out.println(str);
out.close();
}
} | Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | 41b83aa200d2c1ee0248c3573350141d | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes |
import java.io.*;
import java.util.Arrays;
public class Codechef
{
public static void main(String args[]) throws NumberFormatException, IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line[]=br.readLine().split(" ");
int n=Integer.parseInt(line[0]);
int k=Integer.parseInt(line[1]);
int count=(n/2)+(n%2);
int ans=0;
int a[]=new int[k+1];
for(int i=0;i<n;i++)
{
int num=Integer.parseInt(br.readLine());
a[num]++;
}
Arrays.sort(a);
int i=k;
while(count>0 && i>=0)
{
count-=a[i]/2;
ans+=(a[i]/2)*2;
i--;
}
System.out.println(ans+count);
}
} | Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | 33f6298f143443bfa2bb66f16f99e926 | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
static PrintWriter out;
static Reader in;
public static void main(String[] args) throws IOException {
//out = new PrintWriter(new File("out.txt"));
//PrintWriter out = new PrintWriter(System.out);
//in = new Reader(new FileInputStream("in.txt"));
//Reader in = new Reader();
input_output();
Main solver = new Main();
solver.solve();
out.flush();
out.close();
}
static int INF = -(int)1e9-1;
static int maxn = (int)1e6+5;
static int mod= (int)1e9+7;
static int n, m, q, k, t;
void solve() throws IOException{
n = in.nextInt();
k = in.nextInt();
int ans = 0, remain = (n+1)/2;
int[] cnt = new int[k+1];
for (int i = 0; i < n; i++) {
cnt[in.nextInt()]++;
}
int a = 0;
for (int i = 1; i <= k; i++) {
while (cnt[i] >= 2) {
cnt[i]-=2;
remain--;
ans += 2;
}
if (cnt[i] == 1) a++;
}
ans += Math.min(remain, a);
out.println(ans);
}
//<>
static class Reader {
private InputStream mIs;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public Reader() {
this(System.in);
}
public Reader(InputStream is) {
mIs = is;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = mIs.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public String nextLine() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
public String next() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
double nextDouble()
{
return Double.parseDouble(next());
}
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 int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
}
static void input_output() throws IOException {
File f = new File("in.txt");
if(f.exists() && !f.isDirectory()) {
in = new Reader(new FileInputStream("in.txt"));
} else in = new Reader();
f = new File("out.txt");
if(f.exists() && !f.isDirectory()) {
out = new PrintWriter(new File("out.txt"));
} else out = new PrintWriter(System.out);
}
} | Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | 32da5c7bb1c390fa0570d966698a19ce | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | //package round_574;
import java.util.*;
public class test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int k=in.nextInt();
int[] a=new int[n];
int[] cnt=new int[k+1];
for(int i=0;i<n;i++) {
a[i]=in.nextInt();
cnt[a[i]]++;
}
int odd=0;int ans=0;
// int setav=(int) Math.ceil(n/2);
for(int i=0;i<k+1;i++) {
if(cnt[i]%2!=0) {
// ans+=cnt[i];
// setav-=cnt[i]/2;
odd++;
// cnt[i]=0;
}
}
if(odd%2==0) {
System.out.println(n-(odd/2));
}
else {
System.out.println(n-(odd/2));
}
// for(int i=0;i<k+1;i++) {
// System.out.println(i+" "+cnt[i]);
// }
// int i;
// for(i=0;i<k+1;i++) {
//// for(int i1=0;i1<k+1;i1++) {
//// System.out.println(i1+" "+cnt[i1]);
//// }
//// System.out.println(setav);
// if(cnt[i]>0 && setav>0 && setav>Math.ceil(cnt[i]/2)+1) {
//// System.out.println(i);
// setav-=Math.ceil(cnt[i]/2)+1;
// ans+=cnt[i];
// cnt[i]=0;
// }
// else if(cnt[i]>0 && setav>0) {
//// System.out.println(i);
// ans+=setav*2;
// i++;
// break;
// }
// if(setav<=0)
// break;
//
// }
//// for(;i<1001;i++) {
//// ans+=cnt[i];
//// }
// System.out.println(ans);
}
}
| Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | 84823dd388ccfdff1526aceecc1a7809 | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | import java.util.*;
//574
public class qa
{
public static void main(String ... args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int k=sc.nextInt();
int arr[]=new int[n];
for(int i=0;i<n;i++)
arr[i]=sc.nextInt();
HashMap<Integer,Integer>hm=new HashMap<Integer,Integer>();
for(int i=0;i<n;i++)
{
if(hm.containsKey(arr[i]))
hm.put(arr[i],hm.get(arr[i])+1);
else hm.put(arr[i],1);
}
int count=0;
int sets=(int)Math.ceil(((float)n)/2);
//System.out.println("keahf"+sets);
for(int key: hm.keySet())
{
int frq=hm.get(key);
//if(sets>(frq/2))
//{
sets-=(frq/2);
if(frq%2==0)
count+=frq;
else count+=frq-1;
//}
}
if(sets>0)
{
for(int key: hm.keySet())
{
int frq=hm.get(key);
if(frq%2==0)
continue;
else
{
count++;
sets--;
if(sets==0)
break;
}
}
}
System.out.println(count);
}
} | Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | d21110e3590caa15bd99046b84471cfe | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | import java.util.*;
import java.lang.*;
public class problem1 {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n=scn.nextInt();
int k=scn.nextInt();
int limit=n/2;
if(n%2==0)
limit=n/2;
else
limit=(n/2)+1;
int[] arr=new int[k+1];
for(int i=0;i<n;i++) {
int num=scn.nextInt();
arr[num]++;
}
int count=0;
int remain=0;
Arrays.sort(arr);
int i=k;
for(;i>=0 && count<limit;i--) {
if(arr[i]!=0 && count<limit) {
int numtoadd=arr[i]/2;
if(numtoadd+count<=limit)
count+=numtoadd;
else {
int noinclude=limit-count;
remain+=noinclude*2;
break;
}
remain+=arr[i]%2;
}
}
for(int j=i;j>=0;j--) {
if(arr[j]!=0) {
remain+=arr[j];
}
}
if(count!=limit)
remain=remain-(limit-count);
System.out.println(n-remain);
}
}
| Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | 31484ee5cf90f90601ae274f385c7e9e | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class DrinksChoosing {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
HashMap<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < n; i++) {
int drinkChoice = sc.nextInt();
int value = map.getOrDefault(drinkChoice, 0);
map.put(drinkChoice, value + 1);
}
int maxStudents = 0;
int drinkSets = n/2 + (n%2);
for (Map.Entry<Integer, Integer> kvMapping : map.entrySet()) {
int drinkSetCount = kvMapping.getValue()/2;
map.put(kvMapping.getKey(), kvMapping.getValue() % 2);
maxStudents += (drinkSetCount*2);
drinkSets -= drinkSetCount;
}
for (Map.Entry<Integer, Integer> kvMapping : map.entrySet()) {
if (drinkSets == 0) {
break;
}
if (kvMapping.getValue() > 0) {
drinkSets--;
maxStudents += 1;
}
}
System.out.println(maxStudents);
}
}
| Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | abed2e33e978addb7cef1c00bf55a01c | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
public class Watermelon {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int a[] =new int [1001];
for(int i=0;i<n;i++)
{
a[sc.nextInt()]++;
}
int maxStudents=n ,drinkSets=0,students=0 ,c=0;
for(int i=1;i<=1000;i++)
{
if(a[i]%2==0)
{
drinkSets=drinkSets+ n/2;
a[i]=0;
}
else if(a[i]%2!=0)
{
drinkSets= drinkSets + (n-1)/2;
a[i]=1;
c=c+1;
}
}
if(c%2==0)
{
drinkSets = drinkSets + c/2;
c=c-c/2;
}
else
if(c%2!=0)
{
drinkSets = drinkSets + (c+1)/2;
c=c- (c+1)/2;
}
System.out.println(n-c);
}
}
| Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | 07cacaedc88425dfc9d210d1ec5943b2 | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class test1 {
public static void main(String[] args) {
Scanner s =new Scanner(System.in);
int n = s.nextInt();
int k = s.nextInt();
int[] inp = new int[n];
for(int i = 0;i<n;++i)
{
inp[i] = s.nextInt();
}
Arrays.sort(inp);
int count = 0;
int flag = 0;
for(int i=0;i<n;++i)
{
if(i==n-1 || inp[i] !=inp[i+1])
{
if(flag == 0 )
{
count += 1;
flag = 1;
}
else
{
flag = 0;
}
}
else
{
count+=2;
i+=1;
}
}
System.out.println(count);
}
}
| Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | 2cba6bfd3ecdc4856122bad626c0c113 | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes |
import java.util.Scanner;
public class DrinksChoosing {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
int k=scan.nextInt();
int a[]=new int[n];
int count[]=new int[k+1];
for(int i=0;i<n;i++) {
a[i]=scan.nextInt();
count[a[i]]++;
}int ans=0;
for(int i=1;i<=k;i++) {
if(count[i]>1) {
if(count[i]%2==0) {ans+=count[i];count[i]=0;
}else {
ans+=count[i]-1;count[i]=1;
}
}
}
int temp=0;
for(int i=1;i<k+1;i++) {
if(count[i]!=0){
temp++;
}
}
if(temp%2!=0)temp++;
System.out.println(ans+temp/2);
}
}
| Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | dd0d172db1b3ae32c4bcb37a7996c091 | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | /*package whatever //do not write package name here */
import java.io.*;
import java.util.*;
public class GFG {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int K = sc.nextInt();
int pairs = (int)Math.round((N*1.0)/2.0);
int count = 0;
int arr[] = new int[K];
for (int i=0; i<N; i++) {
int inp = sc.nextInt();
arr[inp-1]++;
}
for (int i=0; i<K; i++) {
count += arr[i]/2;
}
count = count*2 + (pairs-count);
System.out.println(count);
}
} | Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | 7e3cc47ca1f84c28f43b2ac10a426dbc | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class bb {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
DrinksChoosin solver = new DrinksChoosin();
solver.solve(1, in, out);
out.close();
}
static class DrinksChoosin {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
int k = in.nextInt();
int[] count = new int[k];
for(int i=0; i<n;i++) {
count[in.nextInt()-1]++;
}
int total = 0;
for (int i = 0; i < count.length; i++) {
int curr = count[i];
if(curr%2==1) {
total++;
}
}
out.println(n-(total/2));
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | f578ede398e5e89ca3cac132bbbc8b75 | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | import java.util.*;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
int[] freq = new int[k];
ArrayList<Integer> arr = new ArrayList<>();
for(int i=0;i<n;i++) {
arr.add(in.nextInt());
freq[arr.get(i)-1]++;
}
Arrays.sort(freq); int ctr =0,cnt=0,c=0;
while(k>0){
ctr+=freq[k-1]/2;
if(freq[k-1]%2==1)
c++;
k--;
}
System.out.println(ctr*2+c/2+((n%2==1)?1:0));
}
} | Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | fc01ad2db771d438ec3108520fc71f84 | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes |
import java.util.Scanner;
public class Cf {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int students = scan.nextInt();
int choices = scan.nextInt();
int hashie[] = new int[choices+1];
for(int i=0; i< students; i++)
{
int temp = scan.nextInt();
hashie[temp]++;
}
double maximum = Math.ceil((double)students/2);
int zeyada=0;
int noFav = 0;
for(int i=1; i<choices+1; i++)
{
double ans = (double)hashie[i]/2;
if(!( ans == Math.floor(ans) ))
{
zeyada++;
noFav++;
}
}
int studentsNew = students - noFav;
System.out.println((int)(studentsNew + Math.ceil((double)noFav/2)));
scan.close();
}
}
| Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | f7cb052aebe3811b10b43c19bcce75f7 | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.zip.Inflater;
public class Main {
private static AWriter writer = new AWriter(System.out);
private static AReader reader = new AReader(System.in);
private static final int INF=0X3F3F3F3F;
private static int n,m;
private static int a[];
private static int cnt[];
public static void main(String[] args) throws IOException {
int n = reader.nextInt();
int k = reader.nextInt();
cnt = new int[k + 1];
for (int i = 0; i < n; i++) {
int op = reader.nextInt();
cnt[op]++;
}
int sum = (int) Math.ceil(n / 2.0);
for (int i = 1; i <= k; i++)
if (cnt[i] % 2 == 0)
sum -= cnt[i] / 2;
for (int i = 1; i <= k; i++)
if (cnt[i] % 2 == 1)
sum -= cnt[i] / 2 + 1;
sum = Math.min(0, sum);
writer.println(n + sum);
writer.close();
reader.close();
}
}
class AReader implements Closeable {
private BufferedReader reader;
private StringTokenizer tokenizer;
public AReader(InputStream inputStream) {
reader = new BufferedReader(new InputStreamReader(inputStream));
tokenizer = new StringTokenizer("");
}
private String innerNextLine() {
try {
return reader.readLine();
} catch (IOException ex) {
return null;
}
}
public boolean hasNext() {
while (!tokenizer.hasMoreTokens()) {
String nextLine = innerNextLine();
if (nextLine == null) {
return false;
}
tokenizer = new StringTokenizer(nextLine);
}
return true;
}
public String nextLine() {
tokenizer = new StringTokenizer("");
return innerNextLine();
}
public String next() {
hasNext();
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.valueOf(next());
}
public long nextLong() {
return Long.valueOf(next());
}
public double nextDouble() {
return Double.valueOf(next());
}
public BigDecimal nextBigDecimal(){ return new BigDecimal(next()); }
public BigInteger nextBigInteger() {
return new BigInteger(next());
}
@Override
public void close() throws IOException {
reader.close();
}
}
// Fast writer for ACM By Azure99
class AWriter implements Closeable {
private BufferedWriter writer;
public AWriter(OutputStream outputStream) {
writer = new BufferedWriter(new OutputStreamWriter(outputStream));
}
public void print(Object object) throws IOException {
writer.write(object.toString());
}
public void println(Object object) throws IOException {
writer.write(object.toString());
writer.write("\n");
}
@Override
public void close() throws IOException {
writer.close();
}
}
| Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | 33687bf509802cd53c2dfa19c8466150 | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.Random;
import java.io.PrintWriter;
/*
Solution Created: 02:52:34 18/07/2019
Custom Competitive programming helper.
*/
public class Main {
public static void solve(Reader in, Writer out) {
int n = in.nextInt(), k = in.nextInt();
int[] a = in.na(n);
Sort.sortArray(a);
int d = 0, s = 0;
for(int i = 0; i<n; i++) {
if(i+1<n&&a[i]==a[i+1]) {
d++;
i++;
}else s++;
}
int cnt = 0;
int sets = (n+1)/2;
int rem = Math.min(sets, d);
cnt+=rem*2;
sets-=rem;
rem = Math.min(sets, s);
cnt+=rem;
sets-=rem;
out.println(cnt);
}
public static void main(String[] args) {
Reader in = new Reader();
Writer out = new Writer();
solve(in, out);
out.exit();
}
static class Graph {
private ArrayList<Integer> con[];
private boolean[] visited;
public Graph(int n) {
con = new ArrayList[n];
for (int i = 0; i < n; ++i)
con[i] = new ArrayList();
visited = new boolean[n];
}
public void reset() {
Arrays.fill(visited, false);
}
public void addEdge(int v, int w) {
con[v].add(w);
}
public void dfs(int cur) {
visited[cur] = true;
for (Integer v : con[cur]) {
if (!visited[v]) {
dfs(v);
}
}
}
public void bfs(int cur) {
Queue<Integer> q = new LinkedList<>();
q.add(cur);
visited[cur] = true;
while (!q.isEmpty()) {
cur = q.poll();
for (Integer v : con[cur]) {
if (!visited[v]) {
visited[v] = true;
q.add(v);
}
}
}
}
}
static class Reader {
static BufferedReader br;
static StringTokenizer st;
private int charIdx = 0;
private String s;
public Reader() {
this.br = new BufferedReader(new InputStreamReader(System.in));
}
public int[] na(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++)
a[i] = nextInt();
return a;
}
public double[] nd(int n) {
double[] a = new double[n];
for (int i = 0; i < n; i++)
a[i] = nextDouble();
return a;
}
public char nextChar() {
if (s == null || charIdx >= s.length()) {
if (st == null || !st.hasMoreTokens())
try {
readLine();
} catch (Exception e) {
}
s = st.nextToken();
charIdx = 0;
}
return s.charAt(charIdx++);
}
public long[] nl(int n) {
long[] a = new long[n];
for (int i = 0; i < n; i++)
a[i] = nextLong();
return a;
}
public char[] nca() {
return next().toCharArray();
}
public String[] nS(int n) {
String[] a = new String[n];
for (int i = 0; i < n; i++)
a[i] = next();
return a;
}
public int nextInt() {
if (st == null || !st.hasMoreTokens())
try {
readLine();
} catch (Exception e) {
}
return Integer.parseInt(st.nextToken());
}
public double nextDouble() {
if (st == null || !st.hasMoreTokens())
try {
readLine();
} catch (Exception e) {
}
return Double.parseDouble(st.nextToken());
}
public Long nextLong() {
if (st == null || !st.hasMoreTokens())
try {
readLine();
} catch (Exception e) {
}
return Long.parseLong(st.nextToken());
}
public String next() {
if (st == null || !st.hasMoreTokens())
try {
readLine();
} catch (Exception e) {
}
return st.nextToken();
}
public static void readLine() {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
}
}
}
static class Sort {
static Random random = new Random();
public static void sortArray(int[] s) {
shuffle(s);
Arrays.sort(s);
}
public static void sortArray(long[] s) {
shuffle(s);
Arrays.sort(s);
}
public static void sortArray(String[] s) {
shuffle(s);
Arrays.sort(s);
}
public static void sortArray(char[] s) {
shuffle(s);
Arrays.sort(s);
}
private static void shuffle(int[] s) {
for (int i = 0; i < s.length; ++i) {
int j = random.nextInt(i + 1);
int t = s[i];
s[i] = s[j];
s[j] = t;
}
}
private static void shuffle(long[] s) {
for (int i = 0; i < s.length; ++i) {
int j = random.nextInt(i + 1);
long t = s[i];
s[i] = s[j];
s[j] = t;
}
}
private static void shuffle(String[] s) {
for (int i = 0; i < s.length; ++i) {
int j = random.nextInt(i + 1);
String t = s[i];
s[i] = s[j];
s[j] = t;
}
}
private static void shuffle(char[] s) {
for (int i = 0; i < s.length; ++i) {
int j = random.nextInt(i + 1);
char t = s[i];
s[i] = s[j];
s[j] = t;
}
}
}
static class Util{
static boolean isPrime(int n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
public static int upperBound(long[] a, long v) {
int l=0, h=a.length-1, ans = -1;
while(l<h) {
int mid = (l+h)/2;
if(a[mid]<=v) {
ans = mid;
l = mid+1;
}else h = mid-1;
}
return ans;
}
public static int lowerBound(long[] a, long v) {
int l=0, h=a.length-1, ans = -1;
while(l<h) {
int mid = (l+h)/2;
if(v<=a[mid]) {
ans = mid;
h = mid-1;
}else l = mid-1;
}
return ans;
}
public static boolean[] getSieve(int n) {
boolean[] isPrime = new boolean[n+1];
for (int i = 2; i <= n; i++) isPrime[i] = true;
for (int i = 2; i*i <= n; i++) if (isPrime[i])
for (int j = i; i*j <= n; j++) isPrime[i*j] = false;
return isPrime;
}
public static long gcd(long a, long b) {
if (a == 0)
return b;
return gcd(b%a, a);
}
public static long modAdd(long a, long b, long mod) {
return (a%mod+b%mod)%mod;
}
public static long modMul(long a, long b, long mod) {
return ((a%mod)*(b%mod))%mod;
}
public static void dbg(Object... o) {
System.out.println(Arrays.deepToString(o));
}
}
static class Writer {
private PrintWriter pw;
public Writer(){
pw = new PrintWriter(System.out);
}
public void printArray(int[] a) {
for(int i = 0; i<a.length; i++) print(a[i]+" ");
}
public void printlnArray(int[] a) {
for(int i = 0; i<a.length; i++) print(a[i]+" ");
pw.println();
}
public void printArray(long[] a) {
for(int i = 0; i<a.length; i++) print(a[i]+" ");
}
public void printlnArray(long[] a) {
for(int i = 0; i<a.length; i++) print(a[i]+" ");
pw.println();
}
public void print(Object o) {
pw.print(o.toString());
}
public void println(Object o) {
pw.println(o.toString());
}
public void println() {
pw.println();
}
public void flush() {
pw.flush();
}
public void exit() {
pw.close();
}
}
}
| Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | 94b8819cb072adb0e04a66f074221935 | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | import java.util.Scanner;
public class CodeForces {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int[] a = new int[k];
for (int i = 0; i < n; i++) {
a[sc.nextInt()-1]++;
}
int ans = 0;
for (int i = 0; i < k; i++) {
if (a[i] % 2 == 1) {
ans++;
}
}
if (n%2==1) {
ans--;
}
ans/=2;
System.out.println(n-ans);
}
} | Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | 96a4d27e69c7e75a2c5cbc4a43395b16 | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int n = scanner.nextInt();
int k = scanner.nextInt();
int choices[] = new int[n];
for(int i=0;i<n;i++) {
choices[i]=scanner.nextInt();
}
Arrays.parallelSort(choices);
int tmp, count, cnt=0;
for (int i = 0; i < n; i++) {
tmp=choices[i];
count=0;
while(i<n && tmp==choices[i]) {
count++;
i++;
}
i--;
if (count%2!=0) {
cnt++;
}
}
scanner.close();
System.out.println(n-(int)(cnt/2));
}
} | Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | 5fef524a5f4f89a6f71a10c877af2026 | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes |
import java.util.*;
import java.io.*;
import static java.lang.System.out;
public class Main {
private Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
public static void main(String[] args) {
System.out.println(new Main().solveTest());
}
void solveAll(){
int T = in.nextInt();
for(int i = 1; i <= T; i++){
String res = solveTest();
out.println(res);
}
}
String solveTest(){
int N = in.nextInt();
int k = in.nextInt();
int[] pref = new int[N];
for(int i = 0; i < N; i++){
pref[i] = in.nextInt();
}
Map<Integer, Integer> counts = new HashMap<>();
for(int i = 0; i < N; i++){
counts.merge(pref[i], 1, Integer::sum);
}
boolean flag = true;
int result = 0;
for(Integer count : counts.values()){
if(count % 2 == 0){
result += count;
} else {
if(flag){
result += count;
flag = false;
} else {
result += count - 1;
flag = true;
}
}
}
return String.valueOf(result);
}
} | Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | 56617583510eb3d58b19d5e36e12fe9b | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.*;
public class DigitPair {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int k=sc.nextInt();
int a[]=new int[k+1];
for(int i=0;i<n;i++)
{
int t=sc.nextInt();
a[t]++;
}
int total=((n/2)+(n%2))*2;
int t=0,ans=0;
for(int i=1;i<k+1;i++)
{
if(a[i]%2==1)
{
t++;
ans=ans+(a[i]-1);
}
else
{
ans=ans+a[i];
}
}
if((total-ans)/2>0 && t!=0)
{
ans=ans+Math.min(t,(total-ans)/2);
}
System.out.println(ans);
}
}
| Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | fa3574b936d96d4af4a6be827ef091fd | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | import java.util.Scanner;
public class SportMafia {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
long n = sc.nextLong();
long k = sc.nextLong();
int arr[] = new int[10000];
for(int i = 0 ; i < n ; i++){
int s = sc.nextInt();
arr[s] += 1;
}
for(int i = 0 ; i < arr.length ; i++){
if(arr[i] == 0){
arr[i] = -1;
}
}
int ans = 0;
int count = 0;
for(int i = 0 ; i < arr.length ; i++){
if(arr[i] != -1){
// System.out.println(i+" : " +arr[i]);
if(arr[i]%2 == 0){
ans += arr[i];
arr[i] = -1;
}else{
ans += arr[i] -1;
count ++;
}
}
}
ans += count / 2;
if(count %2 != 0){
ans +=1;
}
System.out.println(ans);
}
}
| Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | 39ddfd7baef4fd16c4d58ce0e0f10f08 | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | import java.util.Scanner;
public class SportMafia {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
long n = sc.nextLong();
long k = sc.nextLong();
int arr[] = new int[10000];
for(int i = 0 ; i < n ; i++){
int s = sc.nextInt();
arr[s] += 1;
}
for(int i = 0 ; i < arr.length ; i++){
if(arr[i] == 0){
arr[i] = -1;
}
}
int ans = 0;
int count = 0;
for(int i = 0 ; i < arr.length ; i++){
if(arr[i] != -1){
// System.out.println(i+" : " +arr[i]);
if(arr[i]%2 == 0){
ans += arr[i];
arr[i] = -1;
}else{
ans += arr[i] -1;
count ++;
}
}
}
ans += count / 2;
if(count %2 != 0){
ans +=1;
}
System.out.println(ans);
}
}
| Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | e823576504e71a03d237207e472da052 | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 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 coding;
import java.util.*;
/**
*
* @author Dell
*/
public class cdfctest {
public static Scanner in = new Scanner(System.in);
public static void main(String[] args) {
int n=in.nextInt();
in.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
int k=in.nextInt();
int[] a=new int[k];
in.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
for(int i=0;i<k;i++)
{a[i]=0;
}
for(int i=0;i<n;i++)
{int value=in.nextInt();
in.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
a[value-1]++;
}
int count=0;
for(int i=0;i<k;i++)
{if(a[i]%2!=0)
{count++;
}
}
int c;
if(n%2!=0)
{count--;
c=count/2;
}
else
c=count/2;
System.out.println(n-c);
}
}
| Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | c324949545a24b6988ea45c4a33254d5 | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class DrinksChoosing {
public static void main(String[] args) {
DrinksChoosing single = new DrinksChoosing();
single.solve();
}
private void solve() {
BufferedReader reader =
new BufferedReader(new InputStreamReader(System.in));
// Reading data using readLine
try {
String ip = reader.readLine();
String[] ipStr = ip.split(" ");
int n = Integer.parseInt(ipStr[0]);
int k = Integer.parseInt(ipStr[1]);
int[] arr = new int[n];
int[] ka = new int[k+1];
int i,j;
for(i=0;i<n;++i) {
ip = reader.readLine();
int x = Integer.parseInt(ip);
++ka[x];
}int m=0;
for(i=1;i<=k;++i){
m+=ka[i]/2;
}
int sol = 2*m + ((n+1)/2-m);
System.out.println(sol);
} catch (IOException e) {
e.printStackTrace();
}
}
}
| Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | f012b756e3e4bd32a8a1b940f2d00767 | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | import java.util.*;
import java.io.*;
import java.lang.*;
public class Drinkschoosing
{
static class pair
{
private int fi;
private int se;
public pair(int fi,int se)
{
this.fi=fi;
this.se=se;
}
public static Comparator<pair> compare = new Comparator<pair>()
{
@Override
public int compare(pair o1, pair o2)
{
if(o1.fi==o2.fi) return o2.se-o1.se;
return o2.fi-o1.fi;
}
};
}
public static int n,k;
public static int[] a = new int[1001];
//public static Scanner scan= new Scanner(System.in);
public static pair[] d = new pair[1001];
public static void main(String[] args) throws IOException
{
Reader scan= new Reader();
n=scan.I();
k=scan.I();
//n= scan.nextInt();
//k= scan.nextInt();
for(int i=1;i<=n;i++) a[i]=scan.I();
for(int i=1;i<=k;i++) d[i] = new pair(0,0);
for(int i=1;i<=n;i++)
{
d[a[i]].fi++;
d[a[i]].se=a[i];
}
Arrays.sort(d,1,k+1,pair.compare);
int text=(n+1)/2;
int res=0;
for(int i=1;i<=k;i++)
{
int text1=d[i].fi/2;
if(text>=text1)
{
text-=text1;
res+=text1*2;
d[i].fi-=text1*2;
}
else
{
text1-=text;
res+=text*2;
d[i].fi-=text*2;
text=0;
}
}
if(text!=0)
{
for(int i=1;i<=k;i++)
{
if(d[i].fi>0 && text>=(d[i].fi+1)/2)
{
text-=(d[i].fi+1)/2;
res+=d[i].fi;
d[i].fi=0;
}
}
}
System.out.println(res);
}
static class Reader
{
BufferedReader br;
StringTokenizer st;
public Reader()
{
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 I()
{
return Integer.parseInt(next());
}
long L()
{
return Long.parseLong(next());
}
double D()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
}
| Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | 208e15f9620e0e0f70e2f70bdf1e5b7f | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | /*Author: Satyajeet Singh, Delhi Technological University*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;
import java.math.*;
public class Main{
/*********************************************Constants******************************************/
static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static long mod=(long)1e9+7;
static long mod1=998244353;
static boolean sieve[];
static ArrayList<Integer> primes;
static ArrayList<Long> factorial;
static HashSet<Pair> graph[];
/****************************************Solutions Begins***************************************/
public static void main (String[] args) throws Exception {
String st[]=br.readLine().split(" ");
int n=Integer.parseInt(st[0]);
int k=Integer.parseInt(st[1]);
int input[]=new int[k+1];
for(int i=0;i<n;i++){
st=br.readLine().split(" ");
int a=Integer.parseInt(st[0]);
input[a]++;
}
int ans=0;
int ass=0;
for(int i=0;i<=k;i++){
ass+=input[i]/2;
if(input[i]%2==1){
ans++;
}
}
int tot=0;
if(n%2==0){
tot=n/2;
}
else{
tot=n/2+1;
}
out.println(n-(ans-(tot-ass)));
/****************************************Solutions Ends**************************************************/
out.flush();
out.close();
}
/****************************************Template Begins************************************************/
/***************************************Precision Printing**********************************************/
static void printPrecision(double d){
DecimalFormat ft = new DecimalFormat("0.00000000000000000");
out.println(ft.format(d));
}
/**************************************Bit Manipulation**************************************************/
static int set(int mask,int bit){
return (mask|(1<<bit));
}
static int unset(int mask,int bit){
return (mask&(~(1<<bit)));
}
static int countBit(long mask){
int ans=0;
while(mask!=0){
if(mask%2==1){
ans++;
}
mask/=2;
}
return ans;
}
static boolean checkBit(int mask,int bit){
int a=mask&(1<<bit);
if(a!=0){
return true;
}
else{
return false;
}
}
static void printMask(int mask){
System.out.println(Integer.toBinaryString(mask));
}
/******************************************Graph*********************************************************/
static void Makegraph(int n){
graph=new HashSet[n];
for(int i=0;i<n;i++){
graph[i]=new HashSet<>();
}
}
static void addEdge(int a,int b,int c){
graph[a].add(new Pair(b,c));
}
/*********************************************PAIR********************************************************/
static class PairComp implements Comparator<Pair>{
public int compare(Pair p1,Pair p2){
if(p1.u!=p2.u){
return p1.u-p2.u;
}
else{
return p1.v-p2.v;
}
}
}
static class Pair implements Comparable<Pair> {
int u;
int v;
int index=-1;
public Pair(int u, int v) {
this.u = u;
this.v = v;
}
public int hashCode() {
int hu = (int) (u ^ (u >>> 32));
int hv = (int) (v ^ (v >>> 32));
return 31 * hu + hv;
}
public boolean equals(Object o) {
Pair other = (Pair) o;
return u == other.u && v == other.v;
}
public int compareTo(Pair other) {
if(index!=other.index)
return Long.compare(index, other.index);
return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
}
public String toString() {
return "[u=" + u + ", v=" + v + "]";
}
}
/******************************************Long Pair*************************************************/
static class PairCompL implements Comparator<Pairl>{
public int compare(Pairl p1,Pairl p2){
long aa=p2.u-p1.u;
if(aa<0){
return -1;
}
else if(aa>0){
return 1;
}
else{
return 0;
}
}
}
static class Pairl implements Comparable<Pair> {
long u;
long v;
int index=-1;
public Pairl(long u, long v) {
this.u = u;
this.v = v;
}
public int hashCode() {
int hu = (int) (u ^ (u >>> 32));
int hv = (int) (v ^ (v >>> 32));
return 31 * hu + hv;
}
public boolean equals(Object o) {
Pair other = (Pair) o;
return u == other.u && v == other.v;
}
public int compareTo(Pair other) {
if(index!=other.index)
return Long.compare(index, other.index);
return Long.compare(v, other.v)!=0?Long.compare(v, other.v):Long.compare(u, other.u);
}
public String toString() {
return "[u=" + u + ", v=" + v + "]";
}
}
/*****************************************DEBUG***********************************************************/
public static void debug(Object... o) {
System.out.println(Arrays.deepToString(o));
}
/************************************MODULAR EXPONENTIATION***********************************************/
static long modulo(long a,long b,long c) {
long x=1;
long y=a;
while(b > 0){
if(b%2 == 1){
x=(x*y)%c;
}
y = (y*y)%c; // squaring the base
b /= 2;
}
return x%c;
}
/********************************************GCD**********************************************************/
static long gcd(long x, long y)
{
if(x==0)
return y;
if(y==0)
return x;
long r=0, a, b;
a = (x > y) ? x : y; // a is greater number
b = (x < y) ? x : y; // b is smaller number
r = b;
while(a % b != 0)
{
r = a % b;
a = b;
b = r;
}
return r;
}
/******************************************SIEVE**********************************************************/
static void sieveMake(int n){
sieve=new boolean[n];
Arrays.fill(sieve,true);
sieve[0]=false;
sieve[1]=false;
for(int i=2;i*i<n;i++){
if(sieve[i]){
for(int j=i*i;j<n;j+=i){
sieve[j]=false;
}
}
}
primes=new ArrayList<Integer>();
for(int i=0;i<n;i++){
if(sieve[i]){
primes.add(i);
}
}
}
/********************************************End***********************************************************/
} | Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | 3637ebd2aefb6f573c73f469f0d32b69 | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
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);
Task solver = new Task();
solver.solve(1, in, out);
out.close();
}
static class Task {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
int k = in.nextInt();
Map<Integer,Integer> counter = new HashMap<>();
for(int i = 0 ; i < n ; i++){
int a = in.nextInt();
if(counter.containsKey(a)){
counter.put((Integer)a,counter.get(a)+1);
}else{
counter.put((Integer)a,1);
}
}
int odd = 0;
for(int i = 1 ; i <= k ; i++){
if(counter.containsKey(i)){
if(counter.get(i)%2==1){
odd++;
}
}
}
out.println(n-odd/2);
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public Long nextLong() {
return Long.parseLong(next());
}
public Double nextDouble() {
return Double.parseDouble(next());
}
}
public static int[] inputArr(int n, InputReader in) {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
}
return a;
}
public static int[] inputArrFrom1(int n, InputReader in) {
int[] a = new int[n + 1];
for (int i = 1; i <= n; i++) {
a[i] = in.nextInt();
}
return a;
}
public static void printArr(int[] a, PrintWriter out) {
if (a.length > 0) {
for (int i = 0; i < a.length - 1; ++i) {
out.print(a[i] + " ");
}
out.println(a[a.length - 1]);
}
}
public static long gcd(long a, long b) {
while (b > 0) {
long c = a;
a = b;
b = c % b;
}
return a;
}
// C(n,m)=C(n,n-m)。(n≥m)
// Cn0+Cn1+...+Cnn = 2^n
}
| Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | 2fb03b3a44307ca05afb310f54334c6e | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | import java.util.*;
public class A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(), k = sc.nextInt();
int a;
int[] cnt = new int[k + 1];
int res = 0;
for (int i = 0; i < n; i++) {
a = sc.nextInt();
cnt[a]++;
}
int l = 0;
for (int i = 1; i <= k; i++) {
if (cnt[i] % 2 == 1) l++;
}
System.out.println(n - l / 2);
}
}
| Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | 1c5762441ce518c0ac8d19710b27906d | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes |
//package codeforce;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public class drinks {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
String[] ss = s.trim().split(" ");
int n = Integer.parseInt(ss[0]);
int k = Integer.parseInt(ss[1]);
int[] arr = new int[n];
HashMap<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(br.readLine());
if (map.containsKey(arr[i])) {
int val = map.get(arr[i]);
map.put(arr[i], val + 1);
} else {
map.put(arr[i], 1);
}
}
int[] val = new int[k];
int j = 0;
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
val[j++] = entry.getValue();
}
int set = (n + 1) / 2;
int stud = 0;
Arrays.sort(val);
int single = 0;
for (int i = k - 1; i >= 0; i--) {
int req = val[i] / 2;
if (set >= req && set > 0) {
set -= req;
stud += req * 2;
val[i] -= req * 2;
if (val[i] % 2 == 0) {
single += val[i] / 2;
}
}
single += val[i] % 2;
}
while (set > 0 && single > 0) {
set -= 1;
single -= 1;
stud += 1;
}
System.out.println(stud);
}
}
| Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | 5545a85f34460a9c32c28b3da774e8bd | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.*;
public class A {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] s = (br.readLine()).trim().split(" ");
int n = Integer.parseInt(s[0]);
int k = Integer.parseInt(s[1]);
HashMap<Integer,Integer> map = new HashMap<>();
while(n-->0){
int m = Integer.parseInt(br.readLine());
map.put(m,map.getOrDefault(m,0)+1);
}
int count = 0;
int p = 0;
for(Map.Entry e : map.entrySet()){
int r = (Integer)e.getValue();
int x = r%2;
count += x;
p += r-x;
}
if(count%2!=0)
count += 1;
p += count/2;
System.out.println(p);
}
}
| Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | cacf78d4c47a8788c9cac5a58ce1cbaa | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
static final int N = 1050;
static int[] a = new int[N];
public static void main (String[] args) throws java.lang.Exception
{
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
int n = in.nextInt();
int k = in.nextInt();
for(int i = 1; i <= n; i++)
{
int x = in.nextInt();
a[x]++;
}
int ans = n;
int odd = 0;
for(int i = 1; i <= k; i++)
if(a[i] % 2 != 0)
odd++;
if(n % 2 != 0)
odd--;
ans -= odd / 2;
out.println(ans);
out.close();
}
static class InputReader
{
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream)
{
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next()
{
while(tokenizer == null || !tokenizer.hasMoreTokens())
{
try
{
tokenizer = new StringTokenizer(reader.readLine());
}
catch(IOException e)
{
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt()
{
return Integer.parseInt(next());
}
public long nextLong()
{
return Long.parseLong(next());
}
}
} | Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | 104e2a974c758d0b9f5868b98db795a8 | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
public class A574{
public static void main(String args[]){
FastReader sc = new FastReader();
StringBuilder sb=new StringBuilder();
int t,i,n,k,a;
t=1;
while(t-->0){
n=sc.nextInt();
k=sc.nextInt();
int set=(int)Math.ceil(n/2.0);
int f[]=new int[k+1];
for(i=0;i<n;i++){
a=sc.nextInt();
f[a]++;
}
PriorityQueue<Integer> q=new PriorityQueue<>(Collections.reverseOrder());
for(i=1;i<=k;i++){
q.add(f[i]);
}
int count=0;
while(q.peek()>0 && set>0){
int temp=q.poll();
temp=temp-2;
if(temp>=0)
count+=2;
else
count++;
set--;
q.add(temp);
}
sb.append(count+"\n");
}
out.println(sb);
out.flush();
}
static PrintWriter out;
static class FastReader{
BufferedReader br;
StringTokenizer st;
public FastReader(){
br=new BufferedReader(new InputStreamReader(System.in));
out=new PrintWriter(System.out,true);
}
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 boolean isPrime(int n) {
if(n<2) return false;
for(int i=2;i<=(int)Math.sqrt(n);i++) {
if(n%i==0) return false;
}
return true;
}
public static void print(int a[],int l,int r){
int i;
for(i=l;i<=r;i++)
out.print(a[i]+" ");
out.println();
}
public static long fastexpo(long x, long y, long p){
long res=1;
while(y > 0){
if((y & 1)==1)
res= ((res%p)*(x%p))%p;
y= y >> 1;
x = ((x%p)*(x%p))%p;
}
return res;
}
public static boolean[] sieve (int n) {
boolean primes[]=new boolean[n+1];
Arrays.fill(primes,true);
primes[0]=primes[1]=false;
for(int i=2;i*i<=n;i++){
if(primes[i]){
for(int j=i*i;j<=n;j+=i)
primes[j]=false;
}
}
return primes;
}
public static long gcd(long a,long b){
return (BigInteger.valueOf(a).gcd(BigInteger.valueOf(b))).longValue();
}
public static void merge(int a[],int l,int m,int r){
int n1,n2,i,j,k;
n1=m-l+1;
n2=r-m;
int L[]=new int[n1];
int R[]=new int[n2];
for(i=0;i<n1;i++)
L[i]=a[l+i];
for(j=0;j<n2;j++)
R[j]=a[m+1+j];
i=0;j=0;
k=l;
while(i<n1&&j<n2){
if(L[i]<=R[j]){
a[k]=L[i];
i++;
}
else{
a[k]=R[j];
j++;
}
k++;
}
while(i<n1){
a[k]=L[i];
i++;
k++;
}
while(j<n2){
a[k]=R[j];
j++;
k++;
}
}
public static void sort(int a[],int l,int r){
int m;
if(l<r){
m=(l+r)/2;
sort(a,l,m);
sort(a,m+1,r);
merge(a,l,m,r);
}
}
}
| Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | 5a8bef2202992e79c85ff21da73e283d | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;
public class A {
public static void main(String[] args) throws FileNotFoundException {
int toFile = 0;
InputStream inputStream;
OutputStream outputStream;
if (toFile == 0) {
inputStream = System.in;
outputStream = System.out;
} else {
inputStream = new FileInputStream(new File("A.in"));
outputStream = new FileOutputStream(new File("A.out"));
}
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(in, out);
out.close();
}
static class TaskA {
public void solve(InputReader in, PrintWriter out) {
int n = in.nextInt();
int k = in.nextInt();
int a[] = new int[k];
for (int i = 0; i < n; i++) {
int x = in.nextInt();
a[x - 1]++;
}
int ch = 0;
List<Integer> g = new ArrayList<>();
for (int i = 0; i < k; i++) {
if (a[i] % 2 == 0)
g.add(a[i]);
else {
g.add(a[i] - 1);
ch++;
}
}
int j = n / 2 + n % 2;
int ans = 0;
for (int i = 0; i < g.size(); i++) {
int cur = Math.min(j, a[i] / 2);
j -= cur;
ans += cur * 2;
}
for (int i = 0; i < j; i++) {
if (ch > 0) {
ch--;
ans++;
}
}
System.out.println(ans);
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public Double nextDouble() {
return Double.parseDouble(next());
}
}
}
| Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | bb2d6cf8c77c2c2879c4fedccff721c1 | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | import java.util.Scanner;
public class m {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
int[] a = new int[n];
for (int i=0;i<a.length;i++) {
a[i]=in.nextInt();
}
in.close();
int[] loveList= new int[k];
for(int i=0;i<a.length;i++)
loveList[a[i]-1]++;
int setsCount = (int) Math.ceil(((double)n)/2);
int res = 0;
for(int i=0;i<loveList.length;i++) res+= loveList[i]/2;
if(res*2>n)System.out.write(n);
setsCount-=res;
System.out.print(setsCount+res*2);
}
} | Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | 53c86033558522e3a328fb5f033bebe1 | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | import java.util.*;
public class TEST{
public static void main(String args []){
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int k=sc.nextInt();
int d[]=new int[k+1];
for(int i=0;i<n;i++) {
int q=sc.nextInt();
d[q]++;
}
/*for(int i=1;i<=k;i++) {
//System.out.println(i+" "+d[i]);
}*/
int t=0;
if(n%2==1) {
t=n/2+1;
}else{
t=n/2;
}
//System.out.println(t);
int count=0;
for(int i=1;i<=k;i++) {
//System.out.println(i+" "+ d[i]);
if(d[i]%2!=0) {
int p=d[i]/2;
t-=p;
count++;
}else {
int p=d[i]/2;
t-=p;
}
//System.out.println(t);
}
int T=count-t;
//System.out.println(count);
//System.out.println(t);
System.out.println(n-T);
}
} | Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | 5d7a97d3e4f30d772ea8461c0217a538 | train_000.jsonl | 1563374100 | Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated?There are $$$n$$$ students living in a building, and for each of them the favorite drink $$$a_i$$$ is known. So you know $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le k$$$) is the type of the favorite drink of the $$$i$$$-th student. The drink types are numbered from $$$1$$$ to $$$k$$$.There are infinite number of drink sets. Each set consists of exactly two portions of the same drink. In other words, there are $$$k$$$ types of drink sets, the $$$j$$$-th type contains two portions of the drink $$$j$$$. The available number of sets of each of the $$$k$$$ types is infinite.You know that students will receive the minimum possible number of sets to give all students exactly one drink. Obviously, the number of sets will be exactly $$$\lceil \frac{n}{2} \rceil$$$, where $$$\lceil x \rceil$$$ is $$$x$$$ rounded up.After students receive the sets, they will distribute their portions by their choice: each student will get exactly one portion. Note, that if $$$n$$$ is odd then one portion will remain unused and the students' teacher will drink it.What is the maximum number of students that can get their favorite drink if $$$\lceil \frac{n}{2} \rceil$$$ sets will be chosen optimally and students will distribute portions between themselves optimally? | 256 megabytes | import java.util.Scanner;
public class CodeA {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int n,k;
n=scanner.nextInt();
k=scanner.nextInt();
int a[]=new int[n];
int b[]=new int[1001];
int totalSets=(n%2==0?(n/2):((n/2)+1));
int count=0;
for(int i=0;i<n;i++)
{
a[i]=scanner.nextInt();
}
for(int i=0;i<n;i++)
b[a[i]]+=1;
// for(int i=0;i<1001;i++)
// if(b[i]>0)System.out.println("value i="+i+" "+b[i]);
for(int i=0;i<=1000;i++)
{
if(b[i]>1)
{
count+=b[i]/2;
b[i]=b[i]%2;
}
}
// System.out.println(totalSets+"***");
// System.out.println(count+"**");
System.out.println(count+totalSets);
}
}
| Java | ["5 3\n1\n3\n1\n1\n2", "10 3\n2\n1\n3\n2\n3\n3\n1\n3\n1\n2"] | 2 seconds | ["4", "9"] | NoteIn the first example, students could choose three sets with drinks $$$1$$$, $$$1$$$ and $$$2$$$ (so they will have two sets with two drinks of the type $$$1$$$ each and one set with two drinks of the type $$$2$$$, so portions will be $$$1, 1, 1, 1, 2, 2$$$). This way all students except the second one will get their favorite drinks.Another possible answer is sets with drinks $$$1$$$, $$$2$$$ and $$$3$$$. In this case the portions will be $$$1, 1, 2, 2, 3, 3$$$. Then all the students except one will gain their favorite drinks. The only student that will not gain the favorite drink will be a student with $$$a_i = 1$$$ (i.e. the first, the third or the fourth). | Java 8 | standard input | [
"greedy",
"math"
] | dceeb739a56bb799550138aa8c127996 | The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 1\,000$$$) — the number of students in the building and the number of different drinks. The next $$$n$$$ lines contain student's favorite drinks. The $$$i$$$-th line contains a single integer from $$$1$$$ to $$$k$$$ — the type of the favorite drink of the $$$i$$$-th student. | 1,000 | Print exactly one integer — the maximum number of students that can get a favorite drink. | standard output | |
PASSED | e26be158cacfd6a007636c829b0f7af6 | train_000.jsonl | 1332516600 | Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.You know the rules of comparing the results of two given teams very well. Let's say that team a solved pa problems with total penalty time ta and team b solved pb problems with total penalty time tb. Team a gets a higher place than team b in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team a gets a higher place than team b in the final results' table if either pa > pb, or pa = pb and ta < tb. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of x teams that solved the same number of problems with the same penalty time. Let's also say that y teams performed better than the teams from this group. In this case all teams from the group share places y + 1, y + 2, ..., y + x. The teams that performed worse than the teams from this group, get their places in the results table starting from the y + x + 1-th place.Your task is to count what number of teams from the given list shared the k-th place. | 256 megabytes | import java.io.*;
import java.util.*;
public class Codeforces
{
public static void main(String args[])throws Exception
{
BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb=new StringBuilder();
String s[]=bu.readLine().split(" ");
int n=Integer.parseInt(s[0]),k=Integer.parseInt(s[1])-1;
int i,a[][]=new int[n][2];
for(i=0;i<n;i++)
{
s=bu.readLine().split(" ");
a[i][0]=Integer.parseInt(s[0]);
a[i][1]=Integer.parseInt(s[1]);
}
Arrays.sort(a, new Comparator<int[]>() {
public int compare(int[] o1, int[] o2) {
if(o1[0]<o2[0]) return 1;
else if(o1[0]==o2[0]) return o1[1]>o2[1]?1:-1;
else return -1;
}});
int c=1,sc=a[k][0],pe=a[k][1];
i=k-1;
while(i>=0)
{
if(a[i][0]==sc && a[i][1]==pe) c++;
else break;
i--;
}
i=k+1;
while(i<n)
{
if(a[i][0]==sc && a[i][1]==pe) c++;
else break;
i++;
}
System.out.print(c);
}
} | Java | ["7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10", "5 4\n3 1\n3 1\n5 3\n3 1\n3 1"] | 2 seconds | ["3", "4"] | NoteThe final results' table for the first sample is: 1-3 places — 4 solved problems, the penalty time equals 10 4 place — 3 solved problems, the penalty time equals 20 5-6 places — 2 solved problems, the penalty time equals 1 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.The final table for the second sample is: 1 place — 5 solved problems, the penalty time equals 3 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams. | Java 11 | standard input | [
"sortings",
"binary search",
"implementation"
] | 63e03361531999db408dc0d02de93579 | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 50). Then n lines contain the description of the teams: the i-th line contains two integers pi and ti (1 ≤ pi, ti ≤ 50) — the number of solved problems and the total penalty time of the i-th team, correspondingly. All numbers in the lines are separated by spaces. | 1,100 | In the only line print the sought number of teams that got the k-th place in the final results' table. | standard output | |
PASSED | 773b9240869049bcf0901ec145974f36 | train_000.jsonl | 1332516600 | Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.You know the rules of comparing the results of two given teams very well. Let's say that team a solved pa problems with total penalty time ta and team b solved pb problems with total penalty time tb. Team a gets a higher place than team b in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team a gets a higher place than team b in the final results' table if either pa > pb, or pa = pb and ta < tb. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of x teams that solved the same number of problems with the same penalty time. Let's also say that y teams performed better than the teams from this group. In this case all teams from the group share places y + 1, y + 2, ..., y + x. The teams that performed worse than the teams from this group, get their places in the results table starting from the y + x + 1-th place.Your task is to count what number of teams from the given list shared the k-th place. | 256 megabytes | import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
public class Rank {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int[] p = new int[n];
int[] t = new int[n];
PriorityQueue<RankNode> pq = new PriorityQueue<>();
for (int i = 0; i < n; i++) {
p[i] = sc.nextInt();
t[i] = sc.nextInt();
RankNode rn = new RankNode(p[i], t[i]);
pq.offer(rn);
}
int cr = 1;
int nr = 1;
Map<Integer, Integer> rankNums = new HashMap<>();
rankNums.put(1, 1);
RankNode curr = pq.poll();
while (!pq.isEmpty()) {
cr++;
RankNode next = pq.poll();
if (curr.compareTo(next) == 0) {
nr++;
for (int i = cr - nr + 1; i <= cr; i++) {
rankNums.put(i, nr);
}
} else {
nr = 1;
rankNums.put(cr, 1);
}
curr = next;
}
System.out.println(rankNums.get(k));
}
private static class RankNode implements Comparable<RankNode> {
int p;
int t;
RankNode(int p, int t) {
this.p = p;
this.t = t;
}
@Override
public int compareTo(RankNode o) {
if (p < o.p) {
return 1;
}
if (p > o.p) {
return -1;
}
if (t < o.t) {
return -1;
}
if (t > o.t) {
return 1;
}
return 0;
}
@Override
public String toString() {
return "problems: " + p + ", time: " + t + "\n";
}
}
}
| Java | ["7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10", "5 4\n3 1\n3 1\n5 3\n3 1\n3 1"] | 2 seconds | ["3", "4"] | NoteThe final results' table for the first sample is: 1-3 places — 4 solved problems, the penalty time equals 10 4 place — 3 solved problems, the penalty time equals 20 5-6 places — 2 solved problems, the penalty time equals 1 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.The final table for the second sample is: 1 place — 5 solved problems, the penalty time equals 3 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams. | Java 11 | standard input | [
"sortings",
"binary search",
"implementation"
] | 63e03361531999db408dc0d02de93579 | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 50). Then n lines contain the description of the teams: the i-th line contains two integers pi and ti (1 ≤ pi, ti ≤ 50) — the number of solved problems and the total penalty time of the i-th team, correspondingly. All numbers in the lines are separated by spaces. | 1,100 | In the only line print the sought number of teams that got the k-th place in the final results' table. | standard output | |
PASSED | d3ef90017b16e086fba82937f810faf1 | train_000.jsonl | 1332516600 | Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.You know the rules of comparing the results of two given teams very well. Let's say that team a solved pa problems with total penalty time ta and team b solved pb problems with total penalty time tb. Team a gets a higher place than team b in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team a gets a higher place than team b in the final results' table if either pa > pb, or pa = pb and ta < tb. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of x teams that solved the same number of problems with the same penalty time. Let's also say that y teams performed better than the teams from this group. In this case all teams from the group share places y + 1, y + 2, ..., y + x. The teams that performed worse than the teams from this group, get their places in the results table starting from the y + x + 1-th place.Your task is to count what number of teams from the given list shared the k-th place. | 256 megabytes | import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;
public class A166sol2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt(), //No. of teams
k = in.nextInt(); //look for place
ArrayList<Integer> arr = new ArrayList<>(n);
for (int i = 0; i < n; i++) {
int p = in.nextInt();
int t = in.nextInt();
//Adding total score numOfProblems *100(points) - penaltyTime
arr.add(p * 100 - t);
}
arr.sort(Comparator.reverseOrder()); // sorting the scores DESC
int score = arr.get(k - 1);
int shared = 0;
for (int i = n - 1; i >= 0; i--) {
if (arr.get(i) == score) {
shared++;
} else if (arr.get(i) > score) {
break;
}
}
System.out.println(shared);
}
}
| Java | ["7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10", "5 4\n3 1\n3 1\n5 3\n3 1\n3 1"] | 2 seconds | ["3", "4"] | NoteThe final results' table for the first sample is: 1-3 places — 4 solved problems, the penalty time equals 10 4 place — 3 solved problems, the penalty time equals 20 5-6 places — 2 solved problems, the penalty time equals 1 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.The final table for the second sample is: 1 place — 5 solved problems, the penalty time equals 3 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams. | Java 11 | standard input | [
"sortings",
"binary search",
"implementation"
] | 63e03361531999db408dc0d02de93579 | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 50). Then n lines contain the description of the teams: the i-th line contains two integers pi and ti (1 ≤ pi, ti ≤ 50) — the number of solved problems and the total penalty time of the i-th team, correspondingly. All numbers in the lines are separated by spaces. | 1,100 | In the only line print the sought number of teams that got the k-th place in the final results' table. | standard output | |
PASSED | c287d991e507d871cd61253177e61c58 | train_000.jsonl | 1332516600 | Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.You know the rules of comparing the results of two given teams very well. Let's say that team a solved pa problems with total penalty time ta and team b solved pb problems with total penalty time tb. Team a gets a higher place than team b in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team a gets a higher place than team b in the final results' table if either pa > pb, or pa = pb and ta < tb. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of x teams that solved the same number of problems with the same penalty time. Let's also say that y teams performed better than the teams from this group. In this case all teams from the group share places y + 1, y + 2, ..., y + x. The teams that performed worse than the teams from this group, get their places in the results table starting from the y + x + 1-th place.Your task is to count what number of teams from the given list shared the k-th place. | 256 megabytes | import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class A166 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt(), //No. of teams
k = in.nextInt(); //look for place
int[][] arr = new int[n][2]; //col1 is problems, col2 is penalty time
for (int i = 0; i < n; i++) {
arr[i][0] = in.nextInt();
arr[i][1] = in.nextInt();
in.nextLine();
}
// sort 2D array in Desc order
Arrays.sort(arr, (entry1, entry2) -> {
// col 1
final int p1 = entry1[0];
final int p2 = entry2[0];
// col 2
final int t1 = entry1[1];
final int t2 = entry2[1];
return p1 == p2 ? Integer.compare(t1,t2) : Integer.compare(p2,p1);
});
// look up values..
int problems = arr[k - 1][0];
int time = arr[k - 1][1];
int shared = 1;
//loop before and after the specified index k
for (int i = k - 2; i >= 0; i--) {
if (arr[i][0] == problems && arr[i][1] == time) {
shared++;
} else {
break;
}
}
for (int i = k; i < n; i++) {
if (arr[i][0] == problems && arr[i][1] == time) {
shared++;
} else {
break;
}
}
System.out.println(shared);
}
}
| Java | ["7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10", "5 4\n3 1\n3 1\n5 3\n3 1\n3 1"] | 2 seconds | ["3", "4"] | NoteThe final results' table for the first sample is: 1-3 places — 4 solved problems, the penalty time equals 10 4 place — 3 solved problems, the penalty time equals 20 5-6 places — 2 solved problems, the penalty time equals 1 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.The final table for the second sample is: 1 place — 5 solved problems, the penalty time equals 3 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams. | Java 11 | standard input | [
"sortings",
"binary search",
"implementation"
] | 63e03361531999db408dc0d02de93579 | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 50). Then n lines contain the description of the teams: the i-th line contains two integers pi and ti (1 ≤ pi, ti ≤ 50) — the number of solved problems and the total penalty time of the i-th team, correspondingly. All numbers in the lines are separated by spaces. | 1,100 | In the only line print the sought number of teams that got the k-th place in the final results' table. | standard output | |
PASSED | ea9fc03efdf96d20e035956e0a28313c | train_000.jsonl | 1332516600 | Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.You know the rules of comparing the results of two given teams very well. Let's say that team a solved pa problems with total penalty time ta and team b solved pb problems with total penalty time tb. Team a gets a higher place than team b in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team a gets a higher place than team b in the final results' table if either pa > pb, or pa = pb and ta < tb. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of x teams that solved the same number of problems with the same penalty time. Let's also say that y teams performed better than the teams from this group. In this case all teams from the group share places y + 1, y + 2, ..., y + x. The teams that performed worse than the teams from this group, get their places in the results table starting from the y + x + 1-th place.Your task is to count what number of teams from the given list shared the k-th place. | 256 megabytes | //https://codeforces.com/problemset/problem/166/A
//A. Rank List
import java.util.*;
import java.io.*;
public class Rank_List{
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
StringBuilder sb = new StringBuilder();
StringTokenizer st = new StringTokenizer(br.readLine().trim());
int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
int a[][] = new int[n][2];
for(int i=0;i<n;i++)
{
st = new StringTokenizer(br.readLine().trim());
a[i][0] = Integer.parseInt(st.nextToken());
a[i][1] = Integer.parseInt(st.nextToken());
}
Arrays.sort(a, (x, y) -> Double.compare(x[1], y[1]));
Arrays.sort(a, (x, y) -> Double.compare(y[0], x[0]));
int count = 1;
for(int i=k;i<n;i++)
if(a[k-1][0]==a[i][0] && a[k-1][1]==a[i][1])
count++;
else
break;
for(int i = k-2;i>=0;i--)
if(a[k-1][0]==a[i][0] && a[k-1][1]==a[i][1])
count++;
else
break;
pw.print(count);
pw.flush();
pw.close();
}
} | Java | ["7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10", "5 4\n3 1\n3 1\n5 3\n3 1\n3 1"] | 2 seconds | ["3", "4"] | NoteThe final results' table for the first sample is: 1-3 places — 4 solved problems, the penalty time equals 10 4 place — 3 solved problems, the penalty time equals 20 5-6 places — 2 solved problems, the penalty time equals 1 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.The final table for the second sample is: 1 place — 5 solved problems, the penalty time equals 3 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams. | Java 11 | standard input | [
"sortings",
"binary search",
"implementation"
] | 63e03361531999db408dc0d02de93579 | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 50). Then n lines contain the description of the teams: the i-th line contains two integers pi and ti (1 ≤ pi, ti ≤ 50) — the number of solved problems and the total penalty time of the i-th team, correspondingly. All numbers in the lines are separated by spaces. | 1,100 | In the only line print the sought number of teams that got the k-th place in the final results' table. | standard output | |
PASSED | 203467d61006899e40795968f861838f | train_000.jsonl | 1332516600 | Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.You know the rules of comparing the results of two given teams very well. Let's say that team a solved pa problems with total penalty time ta and team b solved pb problems with total penalty time tb. Team a gets a higher place than team b in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team a gets a higher place than team b in the final results' table if either pa > pb, or pa = pb and ta < tb. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of x teams that solved the same number of problems with the same penalty time. Let's also say that y teams performed better than the teams from this group. In this case all teams from the group share places y + 1, y + 2, ..., y + x. The teams that performed worse than the teams from this group, get their places in the results table starting from the y + x + 1-th place.Your task is to count what number of teams from the given list shared the k-th place. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner in = new Scanner(System.in);
int n = in.nextInt();int g = 0; int h = 0;
int k = in.nextInt();int y = 0;
int[] a = new int[n];
for(int i = 0; i < n; i++)
{
g = in.nextInt();
h = in.nextInt();
a[i] = 100*g - h;
}
Arrays.sort(a);
for(int i = 0; i < n; i++)
{
if(a[i] == a[n-k])
y++;
}
System.out.println(y);
}
} | Java | ["7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10", "5 4\n3 1\n3 1\n5 3\n3 1\n3 1"] | 2 seconds | ["3", "4"] | NoteThe final results' table for the first sample is: 1-3 places — 4 solved problems, the penalty time equals 10 4 place — 3 solved problems, the penalty time equals 20 5-6 places — 2 solved problems, the penalty time equals 1 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.The final table for the second sample is: 1 place — 5 solved problems, the penalty time equals 3 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams. | Java 11 | standard input | [
"sortings",
"binary search",
"implementation"
] | 63e03361531999db408dc0d02de93579 | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 50). Then n lines contain the description of the teams: the i-th line contains two integers pi and ti (1 ≤ pi, ti ≤ 50) — the number of solved problems and the total penalty time of the i-th team, correspondingly. All numbers in the lines are separated by spaces. | 1,100 | In the only line print the sought number of teams that got the k-th place in the final results' table. | standard output | |
PASSED | f6a6feb6b9aeb6f999c5a7d95f026813 | train_001.jsonl | 1332516600 | Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.You know the rules of comparing the results of two given teams very well. Let's say that team a solved pa problems with total penalty time ta and team b solved pb problems with total penalty time tb. Team a gets a higher place than team b in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team a gets a higher place than team b in the final results' table if either pa > pb, or pa = pb and ta < tb. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of x teams that solved the same number of problems with the same penalty time. Let's also say that y teams performed better than the teams from this group. In this case all teams from the group share places y + 1, y + 2, ..., y + x. The teams that performed worse than the teams from this group, get their places in the results table starting from the y + x + 1-th place.Your task is to count what number of teams from the given list shared the k-th place. | 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.StringTokenizer;
public class Main {
//Fast Reader
private static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public void resetST() {
st = null;
}
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());
}
public String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
st = null;
return str;
}
public int[] nextIntArray(int size) {
int[] arr = new int[size];
for (int i = 0; i < size; i++) {
arr[i] = nextInt();
}
return arr;
}
public long[] nextLongArray(int size) {
long[] arr = new long[size];
for (int i = 0; i < size; i++) {
arr[i] = nextLong();
}
return arr;
}
public double[] nextDoubleArray(int size) {
double[] arr = new double[size];
for (int i = 0; i < size; i++) {
arr[i] = nextDouble();
}
return arr;
}
}
public static void main(String[] args) {
final FastReader sc = new FastReader();
final PrintWriter pr = new PrintWriter(System.out);
int n = sc.nextInt();
int k = sc.nextInt();
int a[][] = new int[n][2];
for (int i = 0; i < n; i++) {
a[i][0] = sc.nextInt();
a[i][1] = sc.nextInt();
}
Arrays.sort(a, (x, y) -> Integer.compare(x[1], y[1]));
Arrays.sort(a, (x, y) -> Integer.compare(y[0], x[0]));
int count = 1;
for (int i = k; i < n; i++)
if (a[k - 1][0] == a[i][0] && a[k - 1][1] == a[i][1])
count++;
else
break;
for (int i = k - 2; i >= 0; i--)
if (a[k - 1][0] == a[i][0] && a[k - 1][1] == a[i][1])
count++;
else
break;
pr.println(count);
pr.close();
// write your code here
}
}
| Java | ["7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10", "5 4\n3 1\n3 1\n5 3\n3 1\n3 1"] | 2 seconds | ["3", "4"] | NoteThe final results' table for the first sample is: 1-3 places — 4 solved problems, the penalty time equals 10 4 place — 3 solved problems, the penalty time equals 20 5-6 places — 2 solved problems, the penalty time equals 1 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.The final table for the second sample is: 1 place — 5 solved problems, the penalty time equals 3 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams. | Java 11 | standard input | [
"sortings",
"binary search",
"implementation"
] | 63e03361531999db408dc0d02de93579 | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 50). Then n lines contain the description of the teams: the i-th line contains two integers pi and ti (1 ≤ pi, ti ≤ 50) — the number of solved problems and the total penalty time of the i-th team, correspondingly. All numbers in the lines are separated by spaces. | 1,100 | In the only line print the sought number of teams that got the k-th place in the final results' table. | standard output | |
PASSED | 2dc25a847ed11b9c8e47581b8353aaec | train_001.jsonl | 1332516600 | Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.You know the rules of comparing the results of two given teams very well. Let's say that team a solved pa problems with total penalty time ta and team b solved pb problems with total penalty time tb. Team a gets a higher place than team b in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team a gets a higher place than team b in the final results' table if either pa > pb, or pa = pb and ta < tb. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of x teams that solved the same number of problems with the same penalty time. Let's also say that y teams performed better than the teams from this group. In this case all teams from the group share places y + 1, y + 2, ..., y + x. The teams that performed worse than the teams from this group, get their places in the results table starting from the y + x + 1-th place.Your task is to count what number of teams from the given list shared the k-th place. | 256 megabytes | import java.io.*;
import java.util.Arrays;
public class RankList {
static class Team implements Comparable<Team>
{
int problemsSolved;
int penaltyTime;
public Team(int x, int y)
{
this.problemsSolved = x;
this.penaltyTime = y;
}
// descending order
public int compareTo(Team otherTeam)
{
if (this.problemsSolved < otherTeam.problemsSolved)
{
return 1;
}
else if (this.problemsSolved > otherTeam.problemsSolved)
{
return -1;
}
else
{
return this.penaltyTime - otherTeam.penaltyTime;
}
}
}
static BufferedReader reader = new BufferedReader(new InputStreamReader (System.in));
public static void main (String [] args) throws IOException {
int [] nk = Arrays.stream(reader.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
int n = nk[0];
int k = nk[1];
Team [] teams = new Team[n];
int index = 0;
while (index < n)
{
int [] team = Arrays.stream(reader.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
teams[index] = new Team(team[0], team[1]);
index++;
}
Arrays.sort(teams);
int currentSame = 0;
for (int i = 0; i < n; i++)
{
if (i == 0)
currentSame = 1;
else if (teams[i].problemsSolved == teams[i-1].problemsSolved &&
teams[i].penaltyTime == teams[i-1].penaltyTime)
currentSame++;
else
currentSame = 1;
if (i == k - 1)
{
index = i + 1;
while (index < n &&
teams[index].problemsSolved == teams[index-1].problemsSolved &&
teams[index].penaltyTime == teams[index-1].penaltyTime)
{
currentSame++;
index++;
}
System.out.println(currentSame);
return;
}
}
}
} | Java | ["7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10", "5 4\n3 1\n3 1\n5 3\n3 1\n3 1"] | 2 seconds | ["3", "4"] | NoteThe final results' table for the first sample is: 1-3 places — 4 solved problems, the penalty time equals 10 4 place — 3 solved problems, the penalty time equals 20 5-6 places — 2 solved problems, the penalty time equals 1 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.The final table for the second sample is: 1 place — 5 solved problems, the penalty time equals 3 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams. | Java 11 | standard input | [
"sortings",
"binary search",
"implementation"
] | 63e03361531999db408dc0d02de93579 | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 50). Then n lines contain the description of the teams: the i-th line contains two integers pi and ti (1 ≤ pi, ti ≤ 50) — the number of solved problems and the total penalty time of the i-th team, correspondingly. All numbers in the lines are separated by spaces. | 1,100 | In the only line print the sought number of teams that got the k-th place in the final results' table. | standard output | |
PASSED | c2c4578d0a3b6355cdf48e05348676d5 | train_001.jsonl | 1332516600 | Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.You know the rules of comparing the results of two given teams very well. Let's say that team a solved pa problems with total penalty time ta and team b solved pb problems with total penalty time tb. Team a gets a higher place than team b in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team a gets a higher place than team b in the final results' table if either pa > pb, or pa = pb and ta < tb. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of x teams that solved the same number of problems with the same penalty time. Let's also say that y teams performed better than the teams from this group. In this case all teams from the group share places y + 1, y + 2, ..., y + x. The teams that performed worse than the teams from this group, get their places in the results table starting from the y + x + 1-th place.Your task is to count what number of teams from the given list shared the k-th place. | 256 megabytes | import java.io.*;
import java.util.*;
public class S {
static class x implements Comparable<x>{
int s;
int d;
@Override
public int compareTo(x o) {
if(o.s > this.s) {
return 1;
}else if(o.s == this.s){
if(o.d < this.d) {
return 1;
}else {
return -1;
}
}else {
return -1;
}
}
}
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input) );
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine() );
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static long nextLong() throws IOException{
return Long.parseLong( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
public static long gcd(long a, long b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
public static void main(String args[]) throws IOException{
S.init(System.in);
int n = S.nextInt();
int k = S.nextInt();
x arr[] = new x[n];
for(int i = 0 ; i < n ; i++) {
x temp = new x();
temp.s = S.nextInt();
temp.d = S.nextInt();
arr[i] = temp;
}
Arrays.parallelSort(arr);
int a1 = arr[k - 1].s;
int a2 = arr[k - 1].d;
int ans = 0;
for(int i = 0 ; i < n ; i++) {
if(arr[i].s == a1 && arr[i].d == a2) {
ans++;
}
}
System.out.println(ans);
}
} | Java | ["7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10", "5 4\n3 1\n3 1\n5 3\n3 1\n3 1"] | 2 seconds | ["3", "4"] | NoteThe final results' table for the first sample is: 1-3 places — 4 solved problems, the penalty time equals 10 4 place — 3 solved problems, the penalty time equals 20 5-6 places — 2 solved problems, the penalty time equals 1 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.The final table for the second sample is: 1 place — 5 solved problems, the penalty time equals 3 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams. | Java 11 | standard input | [
"sortings",
"binary search",
"implementation"
] | 63e03361531999db408dc0d02de93579 | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 50). Then n lines contain the description of the teams: the i-th line contains two integers pi and ti (1 ≤ pi, ti ≤ 50) — the number of solved problems and the total penalty time of the i-th team, correspondingly. All numbers in the lines are separated by spaces. | 1,100 | In the only line print the sought number of teams that got the k-th place in the final results' table. | standard output | |
PASSED | a3c90ce5f5d4aa6a7a5e9e49fefeb984 | train_001.jsonl | 1332516600 | Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.You know the rules of comparing the results of two given teams very well. Let's say that team a solved pa problems with total penalty time ta and team b solved pb problems with total penalty time tb. Team a gets a higher place than team b in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team a gets a higher place than team b in the final results' table if either pa > pb, or pa = pb and ta < tb. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of x teams that solved the same number of problems with the same penalty time. Let's also say that y teams performed better than the teams from this group. In this case all teams from the group share places y + 1, y + 2, ..., y + x. The teams that performed worse than the teams from this group, get their places in the results table starting from the y + x + 1-th place.Your task is to count what number of teams from the given list shared the k-th place. | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
public class S {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(
new InputStreamReader(input) );
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(
reader.readLine() );
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
public static long gcd(long a, long b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
public static void main(String args[]) throws IOException{
S.init(System.in);
int n = S.nextInt();
int k = S.nextInt();
int a[] = new int[n];
int b[] = new int[n];
for(int i = 0 ; i < n ; i++) {
a[i] = S.nextInt();
b[i] = S.nextInt();
}
int arr[][] = new int[50][50];
for(int i = 0 ; i < n ; i++) {
int s = a[i] - 1;
int p = b[i] - 1;
arr[s][p]++;
}
int x = 0;
int ans = 0;
int f = 0;
for(int i = 49 ; i >= 0 ; i--) {
for(int j = 0 ; j < 50 ; j++) {
if(arr[i][j] > 0) {
x += arr[i][j];
if(x >= k) {
ans = arr[i][j];
f = 1;
break;
}
}
}
if(f == 1) {
break;
}
}
System.out.println(ans);
}
} | Java | ["7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10", "5 4\n3 1\n3 1\n5 3\n3 1\n3 1"] | 2 seconds | ["3", "4"] | NoteThe final results' table for the first sample is: 1-3 places — 4 solved problems, the penalty time equals 10 4 place — 3 solved problems, the penalty time equals 20 5-6 places — 2 solved problems, the penalty time equals 1 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.The final table for the second sample is: 1 place — 5 solved problems, the penalty time equals 3 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams. | Java 11 | standard input | [
"sortings",
"binary search",
"implementation"
] | 63e03361531999db408dc0d02de93579 | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 50). Then n lines contain the description of the teams: the i-th line contains two integers pi and ti (1 ≤ pi, ti ≤ 50) — the number of solved problems and the total penalty time of the i-th team, correspondingly. All numbers in the lines are separated by spaces. | 1,100 | In the only line print the sought number of teams that got the k-th place in the final results' table. | standard output | |
PASSED | 067a9cc6d4fe171994b5e6d0242d2dc4 | train_001.jsonl | 1332516600 | Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.You know the rules of comparing the results of two given teams very well. Let's say that team a solved pa problems with total penalty time ta and team b solved pb problems with total penalty time tb. Team a gets a higher place than team b in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team a gets a higher place than team b in the final results' table if either pa > pb, or pa = pb and ta < tb. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of x teams that solved the same number of problems with the same penalty time. Let's also say that y teams performed better than the teams from this group. In this case all teams from the group share places y + 1, y + 2, ..., y + x. The teams that performed worse than the teams from this group, get their places in the results table starting from the y + x + 1-th place.Your task is to count what number of teams from the given list shared the k-th place. | 256 megabytes | import java.io.*;
import java.util.*;
public class Main {
static class Solver {
// long[][] dp;
int n,k;
int mod = (int)1e9 + 7;
public void solve(MyReader in, PrintWriter out) {
n = in.nextInt();
k = in.nextInt();
Pair<Integer,Integer>[] pairs = new Pair[n];
for (int i = 0; i < n; i++) {
pairs[i] = new Pair<>(in.nextInt(),in.nextInt());
}
Arrays.sort(pairs,Collections.reverseOrder());
// out.println(Arrays.toString(pairs));
var target = pairs[k-1];
out.println(Arrays.stream(pairs).filter(e -> e.equals(target)).count());
}
}
public static void main(String[] args) {
MyReader mr = new MyReader();
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
new Solver().solve(mr, out);
out.close();
}
//////////////////////////////////////////////////////////////////////////
// static int[][] dir = {{0,1}, {1,0},{-1,0}, {0,-1}};
// static int[][] dir = {{0,1}, {1,0},{-1,0}, {0,-1}, {-1,-1},{-1,1}, {1,1}, {1,-1}};
static class MyReader {
BufferedReader br;
StringTokenizer st;
MyReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String res = "";
try {
res = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return res;
}
int[] nextIntArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
Integer[] nextIntegerArray(int n) {
Integer[] arr = new Integer[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
Long[] nextLongArray(int n) {
Long[] arr = new Long[n];
for (int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
}
long[] nextlongArray(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
}
String[] nextStringArray(int n) {
String[] arr = new String[n];
for (int i = 0; i < n; i++) {
arr[i] = next();
}
return arr;
}
}
/////////////////////////////////////////////////////////////
static class Pair<K, V> implements Comparable<Pair<K,V>>{
K x;
V y;
public Pair(K x, V y) {
this.x = x;
this.y = y;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Pair<?, ?> pair = (Pair<?, ?>) o;
return Objects.equals(x, pair.x) &&
Objects.equals(y, pair.y);
}
@Override
public String toString() {
return "{"+x+" "+y+"}\n";
}
@Override
public int hashCode() {
return Objects.hash(x, y);
}
@Override
public int compareTo(Pair<K, V> o) {
if (this.x == o.x)return (int)o.y - (int)this.y;
return (int)this.x - (int)o.x;
}
}
/////////////////////////////////////////////////////////////
static <T> void swap(T[] arr, int i, int j) {
T tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
static <T> void memset(T[] arr, T val) {
Arrays.fill(arr, val);
}
static <T> void memset(T[][] arr, T val) {
for (T[] a : arr) Arrays.fill(a, val);
}
static <T> void memset(T[][][] arr, T val) {
for (T[][] a1 : arr) for (T[] a : a1) Arrays.fill(a, val);
}
static <T> void memset(T[][][][] arr, T val) {
for (T[][][] a1 : arr) for (T[][] a2 : a1) for (T[] a : a2) Arrays.fill(a, val);
}
}
| Java | ["7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10", "5 4\n3 1\n3 1\n5 3\n3 1\n3 1"] | 2 seconds | ["3", "4"] | NoteThe final results' table for the first sample is: 1-3 places — 4 solved problems, the penalty time equals 10 4 place — 3 solved problems, the penalty time equals 20 5-6 places — 2 solved problems, the penalty time equals 1 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.The final table for the second sample is: 1 place — 5 solved problems, the penalty time equals 3 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams. | Java 11 | standard input | [
"sortings",
"binary search",
"implementation"
] | 63e03361531999db408dc0d02de93579 | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 50). Then n lines contain the description of the teams: the i-th line contains two integers pi and ti (1 ≤ pi, ti ≤ 50) — the number of solved problems and the total penalty time of the i-th team, correspondingly. All numbers in the lines are separated by spaces. | 1,100 | In the only line print the sought number of teams that got the k-th place in the final results' table. | standard output | |
PASSED | 3ae482debd3f7a9aba77d2c18f38f4fd | train_001.jsonl | 1332516600 | Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.You know the rules of comparing the results of two given teams very well. Let's say that team a solved pa problems with total penalty time ta and team b solved pb problems with total penalty time tb. Team a gets a higher place than team b in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team a gets a higher place than team b in the final results' table if either pa > pb, or pa = pb and ta < tb. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of x teams that solved the same number of problems with the same penalty time. Let's also say that y teams performed better than the teams from this group. In this case all teams from the group share places y + 1, y + 2, ..., y + x. The teams that performed worse than the teams from this group, get their places in the results table starting from the y + x + 1-th place.Your task is to count what number of teams from the given list shared the k-th place. | 256 megabytes | import java.util.*;
import java.io.*;
public class A {
public static class SortMarks implements Comparator<ArrayList<Integer>> {
public int compare(ArrayList<Integer> a1, ArrayList<Integer> a2) {
if (a1.get(0) < a2.get(0))
return 1;
else if (a1.get(0) == a2.get(0) && a1.get(1) > a2.get(1))
return 1;
return -1;
}
}
public static void main(String[] args) throws IOException {
ArrayList<ArrayList<Integer>> a = new ArrayList<ArrayList<Integer>>();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] line = br.readLine().split(" ");
int n = Integer.parseInt(line[0]);
int k = Integer.parseInt(line[1]);
for (int i=0; i<n;i++) {
String[] newline = br.readLine().split(" ");
ArrayList<Integer> arr = new ArrayList<Integer>();
arr.add(Integer.parseInt(newline[0]));
arr.add(Integer.parseInt(newline[1]));
a.add(arr);
}
Collections.sort(a, new SortMarks());
ArrayList<Integer> v = a.get(k-1);
for (int i=0;i<n;i++) {
if (a.get(i).equals(v)) {
int c = 0;
while (i<n && a.get(i).equals(v)) {
c++;
i++;
}
System.out.println(c);
}
}
}
}
| Java | ["7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10", "5 4\n3 1\n3 1\n5 3\n3 1\n3 1"] | 2 seconds | ["3", "4"] | NoteThe final results' table for the first sample is: 1-3 places — 4 solved problems, the penalty time equals 10 4 place — 3 solved problems, the penalty time equals 20 5-6 places — 2 solved problems, the penalty time equals 1 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.The final table for the second sample is: 1 place — 5 solved problems, the penalty time equals 3 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams. | Java 11 | standard input | [
"sortings",
"binary search",
"implementation"
] | 63e03361531999db408dc0d02de93579 | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 50). Then n lines contain the description of the teams: the i-th line contains two integers pi and ti (1 ≤ pi, ti ≤ 50) — the number of solved problems and the total penalty time of the i-th team, correspondingly. All numbers in the lines are separated by spaces. | 1,100 | In the only line print the sought number of teams that got the k-th place in the final results' table. | standard output | |
PASSED | fa78c78cec1f7fa94641a4be45f99aab | train_001.jsonl | 1332516600 | Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.You know the rules of comparing the results of two given teams very well. Let's say that team a solved pa problems with total penalty time ta and team b solved pb problems with total penalty time tb. Team a gets a higher place than team b in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team a gets a higher place than team b in the final results' table if either pa > pb, or pa = pb and ta < tb. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of x teams that solved the same number of problems with the same penalty time. Let's also say that y teams performed better than the teams from this group. In this case all teams from the group share places y + 1, y + 2, ..., y + x. The teams that performed worse than the teams from this group, get their places in the results table starting from the y + x + 1-th place.Your task is to count what number of teams from the given list shared the k-th place. | 256 megabytes |
import java.util.*;
import java.io.*;
public class Codeforces {
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();
}
}
static class Comb {
static long nCr(int n, int k) {
long C[] = new long[k + 1];
// nC0 is 1
C[0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = Math.min(i, k); j > 0; j--) {
C[j] = C[j] + C[j - 1];
}
}
return C[k];
}
}
static void radixSort(int[]A){
int j=0;
int d;
int k=10;
int n=A.length;
while(j<noOfDigit(A)){
int B[]=new int[n];//sorted array
int C[]=new int[k+1];//keeps count(frequency)of each array elements
for(int i=0;i<=k;i++){
C[i]=0;
}
for(int i=0;i<n;i++){
d=(A[i]/(int)Math.pow(10, j))%10;
C[d]=C[d]+1;
}
for(int i=1;i<=k;i++){
C[i]=C[i]+C[i-1];
}
for(int i=n-1;i>=0;i--)//operated in reverse to make it a stable sort
{
d=(A[i]/(int)Math.pow(10, j))%10;
B[C[d]-1]=A[i];
C[d]=C[d]-1;
}
j++;
System.arraycopy(B, 0, A, 0, n);
}
}
static int maxElement(int[]A){
int max=A[0];
for(int i=1;i<A.length;i++){
if(max<A[i]){
max=A[i];
}
}
return max;
}
static int noOfDigit(int[]A){
int max=maxElement(A);
int f=0;
while(max>0){
max=max/10;
f++;
}
return f;
}
public static void main(String[] args) throws IOException {
int mod = 1000000007;
Reader sc =new Reader();
int n=sc.nextInt();
int k=n-sc.nextInt();
int a[]=new int [n];
Map<Integer,Integer> map=new HashMap<>();
for (int i = 0; i < n; i++) {
int p=sc.nextInt()*100;
int t=(int )Math.abs(50-sc.nextInt())+p;
map.put(t, map.getOrDefault(t, 0)+1);
a[i]=t;
}
radixSort(a);
System.out.println(map.get(a[k]));
}
}
| Java | ["7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10", "5 4\n3 1\n3 1\n5 3\n3 1\n3 1"] | 2 seconds | ["3", "4"] | NoteThe final results' table for the first sample is: 1-3 places — 4 solved problems, the penalty time equals 10 4 place — 3 solved problems, the penalty time equals 20 5-6 places — 2 solved problems, the penalty time equals 1 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.The final table for the second sample is: 1 place — 5 solved problems, the penalty time equals 3 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams. | Java 11 | standard input | [
"sortings",
"binary search",
"implementation"
] | 63e03361531999db408dc0d02de93579 | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 50). Then n lines contain the description of the teams: the i-th line contains two integers pi and ti (1 ≤ pi, ti ≤ 50) — the number of solved problems and the total penalty time of the i-th team, correspondingly. All numbers in the lines are separated by spaces. | 1,100 | In the only line print the sought number of teams that got the k-th place in the final results' table. | standard output | |
PASSED | d55c0b09ffbfdb6de78ff43f033443e7 | train_001.jsonl | 1332516600 | Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.You know the rules of comparing the results of two given teams very well. Let's say that team a solved pa problems with total penalty time ta and team b solved pb problems with total penalty time tb. Team a gets a higher place than team b in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team a gets a higher place than team b in the final results' table if either pa > pb, or pa = pb and ta < tb. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of x teams that solved the same number of problems with the same penalty time. Let's also say that y teams performed better than the teams from this group. In this case all teams from the group share places y + 1, y + 2, ..., y + x. The teams that performed worse than the teams from this group, get their places in the results table starting from the y + x + 1-th place.Your task is to count what number of teams from the given list shared the k-th place. | 256 megabytes |
import java.util.*;
import java.io.*;
public class Codeforces {
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();
}
}
static class Comb {
static long nCr(int n, int k) {
long C[] = new long[k + 1];
// nC0 is 1
C[0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = Math.min(i, k); j > 0; j--) {
C[j] = C[j] + C[j - 1];
}
}
return C[k];
}
}
static void radixSort(int[]A){
int j=0;
int d;
int k=10;
int n=A.length;
while(j<noOfDigit(A)){
int B[]=new int[n];//sorted array
int C[]=new int[k+1];//keeps count(frequency)of each array elements
for(int i=0;i<=k;i++){
C[i]=0;
}
for(int i=0;i<n;i++){
d=(A[i]/(int)Math.pow(10, j))%10;
C[d]=C[d]+1;
}
for(int i=1;i<=k;i++){
C[i]=C[i]+C[i-1];
}
for(int i=n-1;i>=0;i--)//operated in reverse to make it a stable sort
{
d=(A[i]/(int)Math.pow(10, j))%10;
B[C[d]-1]=A[i];
C[d]=C[d]-1;
}
j++;
System.arraycopy(B, 0, A, 0, n);
}
}
static int maxElement(int[]A){
int max=A[0];
for(int i=1;i<A.length;i++){
if(max<A[i]){
max=A[i];
}
}
return max;
}
static int noOfDigit(int[]A){
int max=maxElement(A);
int f=0;
while(max>0){
max=max/10;
f++;
}
return f;
}
public static void main(String[] args) throws IOException {
int mod = 1000000007;
Reader sc =new Reader();
int n=sc.nextInt();
int k=n-sc.nextInt();
int a[]=new int [n];
Map<Integer,Integer> map=new HashMap<>();
for (int i = 0; i < n; i++) {
int p=sc.nextInt()*100;
int t=(int )Math.abs(50-sc.nextInt())+p;
map.put(t, map.getOrDefault(t, 0)+1);
a[i]=t;
}
Arrays.sort(a);
//radixSort(a);
System.out.println(map.get(a[k]));
}
}
| Java | ["7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10", "5 4\n3 1\n3 1\n5 3\n3 1\n3 1"] | 2 seconds | ["3", "4"] | NoteThe final results' table for the first sample is: 1-3 places — 4 solved problems, the penalty time equals 10 4 place — 3 solved problems, the penalty time equals 20 5-6 places — 2 solved problems, the penalty time equals 1 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.The final table for the second sample is: 1 place — 5 solved problems, the penalty time equals 3 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams. | Java 11 | standard input | [
"sortings",
"binary search",
"implementation"
] | 63e03361531999db408dc0d02de93579 | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 50). Then n lines contain the description of the teams: the i-th line contains two integers pi and ti (1 ≤ pi, ti ≤ 50) — the number of solved problems and the total penalty time of the i-th team, correspondingly. All numbers in the lines are separated by spaces. | 1,100 | In the only line print the sought number of teams that got the k-th place in the final results' table. | standard output | |
PASSED | 6ac5aa3541d6e472d7b3efef37a9f7ec | train_001.jsonl | 1332516600 | Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.You know the rules of comparing the results of two given teams very well. Let's say that team a solved pa problems with total penalty time ta and team b solved pb problems with total penalty time tb. Team a gets a higher place than team b in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team a gets a higher place than team b in the final results' table if either pa > pb, or pa = pb and ta < tb. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of x teams that solved the same number of problems with the same penalty time. Let's also say that y teams performed better than the teams from this group. In this case all teams from the group share places y + 1, y + 2, ..., y + x. The teams that performed worse than the teams from this group, get their places in the results table starting from the y + x + 1-th place.Your task is to count what number of teams from the given list shared the k-th place. | 256 megabytes | import java.util.*;
import java.io.*;
import java.math.*;
import java.awt.geom.*;
import static java.lang.Math.*;
public class Solution implements Runnable {
public void solve() throws Exception {
// int t=sc.nextInt();
// long mod=(long)1e9+7;
//
// while(t-->0)
// {
int n=sc.nextInt();
int k=sc.nextInt();
int arr[][]=new int[n][2];
for(int i=0;i<n;i++)
{
arr[i][0]=sc.nextInt();
arr[i][1]=sc.nextInt();
}
Arrays.parallelSort(arr,(a,b)->(a[0]==b[0]?a[1]-b[1]:b[0]-a[0]));
int first1=arr[k-1][0];
int first2=arr[k-1][1];
int count=1;
int result=1;
for(int i=k;i<n;i++)
{
if(arr[i][0]==first1 && arr[i][1]==first2)
result++;
else break;
}
for(int i=k-2;i>=0;i--)
{
if(arr[i][0]==first1 && arr[i][1]==first2)
result++;
else break;
}
out.println(result);
}
static long power(long x, long y, long p)
{
long res = 1;
x = x % p;
if (x == 0) return 0;
while (y > 0)
{
if((y & 1)==1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
static Throwable uncaught;
BufferedReader in;
FastScanner sc;
PrintWriter out;
@Override
public void run() {
try {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
sc = new FastScanner(in);
solve();
} catch (Throwable uncaught) {
Solution.uncaught = uncaught;
} finally {
out.close();
}
}
public static void main(String[] args) throws Throwable {
Thread thread = new Thread(null, new Solution(), "", (1 << 26));
thread.start();
thread.join();
if (Solution.uncaught != null) {
throw Solution.uncaught;
}
}
}
class FastScanner {
BufferedReader in;
StringTokenizer st;
public FastScanner(BufferedReader in) {
this.in = in;
}
public String nextToken() throws Exception {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(in.readLine());
}
return st.nextToken();
}
public int nextInt() throws Exception {
return Integer.parseInt(nextToken());
}
public int[] readArray(int n) throws Exception {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
public long nextLong() throws Exception {
return Long.parseLong(nextToken());
}
public double nextDouble() throws Exception {
return Double.parseDouble(nextToken());
}
} | Java | ["7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10", "5 4\n3 1\n3 1\n5 3\n3 1\n3 1"] | 2 seconds | ["3", "4"] | NoteThe final results' table for the first sample is: 1-3 places — 4 solved problems, the penalty time equals 10 4 place — 3 solved problems, the penalty time equals 20 5-6 places — 2 solved problems, the penalty time equals 1 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.The final table for the second sample is: 1 place — 5 solved problems, the penalty time equals 3 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams. | Java 11 | standard input | [
"sortings",
"binary search",
"implementation"
] | 63e03361531999db408dc0d02de93579 | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 50). Then n lines contain the description of the teams: the i-th line contains two integers pi and ti (1 ≤ pi, ti ≤ 50) — the number of solved problems and the total penalty time of the i-th team, correspondingly. All numbers in the lines are separated by spaces. | 1,100 | In the only line print the sought number of teams that got the k-th place in the final results' table. | standard output | |
PASSED | baced0dbeb84647674fcbd790099c728 | train_001.jsonl | 1332516600 | Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.You know the rules of comparing the results of two given teams very well. Let's say that team a solved pa problems with total penalty time ta and team b solved pb problems with total penalty time tb. Team a gets a higher place than team b in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team a gets a higher place than team b in the final results' table if either pa > pb, or pa = pb and ta < tb. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of x teams that solved the same number of problems with the same penalty time. Let's also say that y teams performed better than the teams from this group. In this case all teams from the group share places y + 1, y + 2, ..., y + x. The teams that performed worse than the teams from this group, get their places in the results table starting from the y + x + 1-th place.Your task is to count what number of teams from the given list shared the k-th place. | 256 megabytes |
import java.io.*;
import java.util.*;
public class Test {
public static void main(String[] args)throws IOException {
Reader sc= new Reader();
PrintWriter w= new PrintWriter(System.out);
int n=sc.nextInt();
int k=sc.nextInt();
int a[]= new int[n];
for(int i=0;i<n;i++) {
a[i]= sc.nextInt() * 10 -sc.nextInt();
}
Arrays.sort(a);
int ct=0;
for(int i=0;i<n;i++) {
if(a[i]==a[n-k]) {
ct++;
}
}
w.println(ct);
w.close();
}
static class Reader // here reader class is defined.
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
}
| Java | ["7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10", "5 4\n3 1\n3 1\n5 3\n3 1\n3 1"] | 2 seconds | ["3", "4"] | NoteThe final results' table for the first sample is: 1-3 places — 4 solved problems, the penalty time equals 10 4 place — 3 solved problems, the penalty time equals 20 5-6 places — 2 solved problems, the penalty time equals 1 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.The final table for the second sample is: 1 place — 5 solved problems, the penalty time equals 3 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams. | Java 11 | standard input | [
"sortings",
"binary search",
"implementation"
] | 63e03361531999db408dc0d02de93579 | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 50). Then n lines contain the description of the teams: the i-th line contains two integers pi and ti (1 ≤ pi, ti ≤ 50) — the number of solved problems and the total penalty time of the i-th team, correspondingly. All numbers in the lines are separated by spaces. | 1,100 | In the only line print the sought number of teams that got the k-th place in the final results' table. | standard output | |
PASSED | 1199583f7a46e3d2291b714881ce3960 | train_001.jsonl | 1332516600 | Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.You know the rules of comparing the results of two given teams very well. Let's say that team a solved pa problems with total penalty time ta and team b solved pb problems with total penalty time tb. Team a gets a higher place than team b in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team a gets a higher place than team b in the final results' table if either pa > pb, or pa = pb and ta < tb. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of x teams that solved the same number of problems with the same penalty time. Let's also say that y teams performed better than the teams from this group. In this case all teams from the group share places y + 1, y + 2, ..., y + x. The teams that performed worse than the teams from this group, get their places in the results table starting from the y + x + 1-th place.Your task is to count what number of teams from the given list shared the k-th place. | 256 megabytes | import java.io.*;
import java.util.*;
/**
* 03/05/20
* Created by Himanshu
**/
public class RankList {
static class pair implements Comparator<pair>{
int a,b;
pair(int a , int b) {
this.a = a;
this.b = b;
}
pair() {}
public int hash() {
String str = this.a + "0000" + this.b;
return Integer.parseInt(str);
}
public int compare(pair p1 , pair p2) {
if (p1.a == p2.a) return p1.b - p2.b;
return p2.a - p1.a;
}
}
public static void main(String[] args) {
Scanner s = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
int n = s.nextInt();
int k = s.nextInt();
ArrayList<pair> list = new ArrayList<>();
Map<Integer,Integer> map = new HashMap<>();
for (int i=0;i<n;i++) {
int p = s.nextInt();
int t = s.nextInt();
pair P = new pair(p,t);
int h = P.hash();
list.add(P);
if (map.containsKey(h)) {
int x = map.get(h);
map.put(h,x+1);
} else map.put(h,1);
}
Collections.sort(list,new pair());
// for (pair p : list) {
// System.out.println(p.a + " " + p.b);
// }
pair p = list.get(k-1);
int h = p.hash();
System.out.println(map.get(h));
}
}
| Java | ["7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10", "5 4\n3 1\n3 1\n5 3\n3 1\n3 1"] | 2 seconds | ["3", "4"] | NoteThe final results' table for the first sample is: 1-3 places — 4 solved problems, the penalty time equals 10 4 place — 3 solved problems, the penalty time equals 20 5-6 places — 2 solved problems, the penalty time equals 1 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.The final table for the second sample is: 1 place — 5 solved problems, the penalty time equals 3 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams. | Java 11 | standard input | [
"sortings",
"binary search",
"implementation"
] | 63e03361531999db408dc0d02de93579 | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 50). Then n lines contain the description of the teams: the i-th line contains two integers pi and ti (1 ≤ pi, ti ≤ 50) — the number of solved problems and the total penalty time of the i-th team, correspondingly. All numbers in the lines are separated by spaces. | 1,100 | In the only line print the sought number of teams that got the k-th place in the final results' table. | standard output | |
PASSED | c5dcbd470f028e00dac5b7ea198ca24c | train_001.jsonl | 1332516600 | Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.You know the rules of comparing the results of two given teams very well. Let's say that team a solved pa problems with total penalty time ta and team b solved pb problems with total penalty time tb. Team a gets a higher place than team b in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team a gets a higher place than team b in the final results' table if either pa > pb, or pa = pb and ta < tb. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of x teams that solved the same number of problems with the same penalty time. Let's also say that y teams performed better than the teams from this group. In this case all teams from the group share places y + 1, y + 2, ..., y + x. The teams that performed worse than the teams from this group, get their places in the results table starting from the y + x + 1-th place.Your task is to count what number of teams from the given list shared the k-th place. | 256 megabytes |
import java.util.*;
import java.io.*;
public class codf {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int k = s.nextInt();
ArrayList<ArrayList<Integer>> A = new ArrayList<>();
for (int i = 0; i < n; i++) {
int p = s.nextInt();
int t = s.nextInt();
ArrayList<Integer> B = new ArrayList<>();
B.add(p);
B.add(t);
A.add(B);
}
Collections.sort(A, new sort());
int count = 0;
for (int i = 0; i < n; i++) {
if (A.get(i).get(0) == A.get(k - 1).get(0) && A.get(i).get(1) == A.get(k - 1).get(1)) {
count++;
}
}
System.out.println(count);
}
static class sort implements Comparator<ArrayList<Integer>> {
@Override
public int compare(ArrayList<Integer> o1, ArrayList<Integer> o2) {
int c = o2.get(0).compareTo(o1.get(0));
if(c == 0){
c = o1.get(1).compareTo(o2.get(1));
}
return c;
}
}
} | Java | ["7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10", "5 4\n3 1\n3 1\n5 3\n3 1\n3 1"] | 2 seconds | ["3", "4"] | NoteThe final results' table for the first sample is: 1-3 places — 4 solved problems, the penalty time equals 10 4 place — 3 solved problems, the penalty time equals 20 5-6 places — 2 solved problems, the penalty time equals 1 7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.The final table for the second sample is: 1 place — 5 solved problems, the penalty time equals 3 2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams. | Java 11 | standard input | [
"sortings",
"binary search",
"implementation"
] | 63e03361531999db408dc0d02de93579 | The first line contains two integers n and k (1 ≤ k ≤ n ≤ 50). Then n lines contain the description of the teams: the i-th line contains two integers pi and ti (1 ≤ pi, ti ≤ 50) — the number of solved problems and the total penalty time of the i-th team, correspondingly. All numbers in the lines are separated by spaces. | 1,100 | In the only line print the sought number of teams that got the k-th place in the final results' table. | standard output |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.