exec_outcome stringclasses 1 value | code_uid stringlengths 32 32 | file_name stringclasses 111 values | prob_desc_created_at stringlengths 10 10 | prob_desc_description stringlengths 63 3.8k | prob_desc_memory_limit stringclasses 18 values | source_code stringlengths 117 65.5k | lang_cluster stringclasses 1 value | prob_desc_sample_inputs stringlengths 2 802 | prob_desc_time_limit stringclasses 27 values | prob_desc_sample_outputs stringlengths 2 796 | prob_desc_notes stringlengths 4 3k β | lang stringclasses 5 values | prob_desc_input_from stringclasses 3 values | tags listlengths 0 11 | src_uid stringlengths 32 32 | prob_desc_input_spec stringlengths 28 2.37k β | difficulty int64 -1 3.5k β | prob_desc_output_spec stringlengths 17 1.47k β | prob_desc_output_to stringclasses 3 values | hidden_unit_tests stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PASSED | 7741441a304ded11eb413bd30665c1e9 | train_003.jsonl | 1416590400 | Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right.Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: Each piece should contain at least l numbers. The difference between the maximal and the minimal number on the piece should be at most s.Please help Alexandra to find the minimal number of pieces meeting the condition above. | 256 megabytes |
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.ArrayDeque;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.StringTokenizer;
/*
public class _488D {
}
*/
public class _488D {
class num
{
int i;
int num;
public num(int i, int num) {
super();
this.i = i;
this.num = num;
}
}
final int NP = 1000000;
int[] tp;
public void solve() throws FileNotFoundException {
InputStream inputStream = System.in;
InputHelper inputHelper = new InputHelper(inputStream);
PrintStream out = System.out;
//actual solution
int n = inputHelper.readInteger();
int s = inputHelper.readInteger();
int l = inputHelper.readInteger();
if(l > n)
{
System.out.println("-1");
return;
}
int[] a = new int[n];
for(int i = 0; i < n; i++)
{
a[i] = inputHelper.readInteger();
}
ArrayDeque<num> mnq = new ArrayDeque<num>();
ArrayDeque<num> mxq = new ArrayDeque<num>();
int[] dp = new int[n];
for(int i = 0; i < l; i++)
{
while(mnq.size() > 0 && mnq.getLast().num > a[i])
{
mnq.pollLast();
}
mnq.add(new num(i, a[i]));
while(mxq.size() > 0 && mxq.getLast().num < a[i])
{
mxq.pollLast();
}
mxq.add(new num(i, a[i]));
int diff = mxq.getFirst().num - mnq.getFirst().num;
if(diff > s)
{
System.out.println("-1");
return;
}
dp[i] = NP;
}
dp[l - 1] = 1;
int li = -1;
for(int i = l; i < n; i++)
{
while(mnq.size() > 0 && mnq.getLast().num > a[i])
{
mnq.pollLast();
}
mnq.add(new num(i, a[i]));
while(mxq.size() > 0 && mxq.getLast().num < a[i])
{
mxq.pollLast();
}
mxq.add(new num(i, a[i]));
int diff = mxq.getFirst().num - mnq.getFirst().num;
dp[i] = NP;
if(diff <= s)
{
int pv = 0;
if(li != -1)
{
pv = dp[li];
while(pv >= NP && i - li >= l)
{
System.err.println("//");
li++;
if(mnq.getFirst().i == li)
{
mnq.pollFirst();
}
if(mxq.getFirst().i == li)
{
mxq.pollFirst();
}
pv = dp[li];
}
}
if(i - li >= l)
dp[i] = pv + 1;
}
else
{
while(i - li >= l)
{
++li;
if(mnq.getFirst().i == li)
{
mnq.pollFirst();
}
if(mxq.getFirst().i == li)
{
mxq.pollFirst();
}
if((mxq.getFirst().num - mnq.getFirst().num <= s) && dp[li] < NP)
break;
}
if(i - li >= l)
dp[i] = Math.min(dp[i], dp[li] + 1);
}
}
if(dp[n - 1] >= NP)
System.out.println("-1");
else
System.out.println(dp[n - 1]);
}
private int rec(int ci, long[][] mn, long[][] mx, int logMx, int n, int[] dp, int l, int s, int[] a) {
if(ci >= n)
return 0;
if(dp[ci] != -1)
{
return dp[ci];
}
int mxi = n;
long cs = mx[ci][logMx] - mn[ci][logMx];
long cmn = mn[ci][logMx];
long cmx = mx[ci][logMx];
int cl = logMx;
while(true)
{
if(cs < s && rec(mxi, mn, mx, logMx, n, dp, l, s, a) < NP && (ci == n || Math.max(a[ci], cmx) - Math.min(a[ci], cmn) > s))
{
return (dp[ci] = 1 + rec(mxi, mn, mx, logMx, n, dp, l, s, a));
}
cl = cl - 1;
if(cl < 0)
break;
if(cs > s || rec(mxi, mn, mx, logMx, n, dp, l, s, a) >= NP)
{
cmn = mn[ci][cl];
cmx = mx[ci][cl];
cs = mx[ci][cl] - mn[ci][cl];
mxi = ci + tp[cl];
}
else if(cs < s)
{
cmn = mn[ci][cl];
cmx = mx[ci][cl];
cs = mx[ci][cl] - mn[ci][cl];
mxi = ci + tp[cl];
}
}
return (dp[ci] = NP);
}
public static void main(String[] args) throws FileNotFoundException {
(new _488D()).solve();
}
class InputHelper {
StringTokenizer tokenizer = null;
private BufferedReader bufferedReader;
public InputHelper(InputStream inputStream) {
InputStreamReader inputStreamReader = new InputStreamReader(
inputStream);
bufferedReader = new BufferedReader(inputStreamReader, 16384);
}
public String read() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
String line = bufferedReader.readLine();
if (line == null) {
return null;
}
tokenizer = new StringTokenizer(line);
} catch (IOException e) {
e.printStackTrace();
}
}
return tokenizer.nextToken();
}
public Integer readInteger() {
return Integer.parseInt(read());
}
public Long readLong() {
return Long.parseLong(read());
}
}
} | Java | ["7 2 2\n1 3 1 2 4 1 2", "7 2 2\n1 100 1 100 1 100 1"] | 1 second | ["3", "-1"] | NoteFor the first sample, we can split the strip into 3 pieces: [1,β3,β1],β[2,β4],β[1,β2].For the second sample, we can't let 1 and 100 be on the same piece, so no solution exists. | Java 7 | standard input | [
"dp",
"two pointers",
"binary search",
"data structures"
] | 3d670528c82a7d8dcd187b7304d36f96 | The first line contains three space-separated integers n,βs,βl (1ββ€βnββ€β105,β0ββ€βsββ€β109,β1ββ€βlββ€β105). The second line contains n integers ai separated by spaces (β-β109ββ€βaiββ€β109). | 2,000 | Output the minimal number of strip pieces. If there are no ways to split the strip, output -1. | standard output | |
PASSED | def8262889390ab1bc8b6a391c30204b | train_003.jsonl | 1416590400 | Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right.Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: Each piece should contain at least l numbers. The difference between the maximal and the minimal number on the piece should be at most s.Please help Alexandra to find the minimal number of pieces meeting the condition above. | 256 megabytes |
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.ArrayDeque;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.StringTokenizer;
/*
public class _488D {
}
*/
public class _488D {
class num
{
int i;
int num;
public num(int i, int num) {
super();
this.i = i;
this.num = num;
}
}
final int NP = 1000000;
int[] tp;
public void solve() throws FileNotFoundException {
InputStream inputStream = System.in;
InputHelper inputHelper = new InputHelper(inputStream);
PrintStream out = System.out;
//actual solution
int n = inputHelper.readInteger();
int s = inputHelper.readInteger();
int l = inputHelper.readInteger();
if(l > n)
{
System.out.println("-1");
return;
}
int[] a = new int[n];
for(int i = 0; i < n; i++)
{
a[i] = inputHelper.readInteger();
}
ArrayDeque<num> mnq = new ArrayDeque<num>();
ArrayDeque<num> mxq = new ArrayDeque<num>();
int[] dp = new int[n];
for(int i = 0; i < l; i++)
{
while(mnq.size() > 0 && mnq.getLast().num > a[i])
{
mnq.pollLast();
}
mnq.add(new num(i, a[i]));
while(mxq.size() > 0 && mxq.getLast().num < a[i])
{
mxq.pollLast();
}
mxq.add(new num(i, a[i]));
int diff = mxq.getFirst().num - mnq.getFirst().num;
if(diff > s)
{
System.out.println("-1");
return;
}
dp[i] = NP;
}
dp[l - 1] = 1;
int li = -1;
for(int i = l; i < n; i++)
{
while(mnq.size() > 0 && mnq.getLast().num > a[i])
{
mnq.pollLast();
}
mnq.add(new num(i, a[i]));
while(mxq.size() > 0 && mxq.getLast().num < a[i])
{
mxq.pollLast();
}
mxq.add(new num(i, a[i]));
int diff = mxq.getFirst().num - mnq.getFirst().num;
dp[i] = NP;
if(diff <= s)
{
int pv = 0;
if(li != -1)
{
pv = dp[li];
while(pv >= NP && i - li >= l)
{
li++;
if(mnq.getFirst().i == li)
{
mnq.pollFirst();
}
if(mxq.getFirst().i == li)
{
mxq.pollFirst();
}
pv = dp[li];
}
}
if(i - li >= l)
dp[i] = pv + 1;
}
else
{
while(i - li >= l)
{
++li;
if(mnq.getFirst().i == li)
{
mnq.pollFirst();
}
if(mxq.getFirst().i == li)
{
mxq.pollFirst();
}
if((mxq.getFirst().num - mnq.getFirst().num <= s) && dp[li] < NP)
break;
}
if(i - li >= l)
dp[i] = Math.min(dp[i], dp[li] + 1);
}
}
if(dp[n - 1] >= NP)
System.out.println("-1");
else
System.out.println(dp[n - 1]);
}
private int rec(int ci, long[][] mn, long[][] mx, int logMx, int n, int[] dp, int l, int s, int[] a) {
if(ci >= n)
return 0;
if(dp[ci] != -1)
{
return dp[ci];
}
int mxi = n;
long cs = mx[ci][logMx] - mn[ci][logMx];
long cmn = mn[ci][logMx];
long cmx = mx[ci][logMx];
int cl = logMx;
while(true)
{
if(cs < s && rec(mxi, mn, mx, logMx, n, dp, l, s, a) < NP && (ci == n || Math.max(a[ci], cmx) - Math.min(a[ci], cmn) > s))
{
return (dp[ci] = 1 + rec(mxi, mn, mx, logMx, n, dp, l, s, a));
}
cl = cl - 1;
if(cl < 0)
break;
if(cs > s || rec(mxi, mn, mx, logMx, n, dp, l, s, a) >= NP)
{
cmn = mn[ci][cl];
cmx = mx[ci][cl];
cs = mx[ci][cl] - mn[ci][cl];
mxi = ci + tp[cl];
}
else if(cs < s)
{
cmn = mn[ci][cl];
cmx = mx[ci][cl];
cs = mx[ci][cl] - mn[ci][cl];
mxi = ci + tp[cl];
}
}
return (dp[ci] = NP);
}
public static void main(String[] args) throws FileNotFoundException {
(new _488D()).solve();
}
class InputHelper {
StringTokenizer tokenizer = null;
private BufferedReader bufferedReader;
public InputHelper(InputStream inputStream) {
InputStreamReader inputStreamReader = new InputStreamReader(
inputStream);
bufferedReader = new BufferedReader(inputStreamReader, 16384);
}
public String read() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
String line = bufferedReader.readLine();
if (line == null) {
return null;
}
tokenizer = new StringTokenizer(line);
} catch (IOException e) {
e.printStackTrace();
}
}
return tokenizer.nextToken();
}
public Integer readInteger() {
return Integer.parseInt(read());
}
public Long readLong() {
return Long.parseLong(read());
}
}
} | Java | ["7 2 2\n1 3 1 2 4 1 2", "7 2 2\n1 100 1 100 1 100 1"] | 1 second | ["3", "-1"] | NoteFor the first sample, we can split the strip into 3 pieces: [1,β3,β1],β[2,β4],β[1,β2].For the second sample, we can't let 1 and 100 be on the same piece, so no solution exists. | Java 7 | standard input | [
"dp",
"two pointers",
"binary search",
"data structures"
] | 3d670528c82a7d8dcd187b7304d36f96 | The first line contains three space-separated integers n,βs,βl (1ββ€βnββ€β105,β0ββ€βsββ€β109,β1ββ€βlββ€β105). The second line contains n integers ai separated by spaces (β-β109ββ€βaiββ€β109). | 2,000 | Output the minimal number of strip pieces. If there are no ways to split the strip, output -1. | standard output | |
PASSED | a470b479b4fc1b4fc254215a179ef554 | train_003.jsonl | 1416590400 | Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right.Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: Each piece should contain at least l numbers. The difference between the maximal and the minimal number on the piece should be at most s.Please help Alexandra to find the minimal number of pieces meeting the condition above. | 256 megabytes |
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.ArrayDeque;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.StringTokenizer;
/*
public class _488D {
}
*/
public class _488D {
class num
{
int i;
int num;
public num(int i, int num) {
super();
this.i = i;
this.num = num;
}
}
final int NP = 1000000;
int[] tp;
public void solve() throws FileNotFoundException {
InputStream inputStream = System.in;
InputHelper inputHelper = new InputHelper(inputStream);
PrintStream out = System.out;
//actual solution
int n = inputHelper.readInteger();
int s = inputHelper.readInteger();
int l = inputHelper.readInteger();
if(l > n)
{
System.out.println("-1");
return;
}
int[] a = new int[n];
for(int i = 0; i < n; i++)
{
a[i] = inputHelper.readInteger();
}
ArrayDeque<num> mnq = new ArrayDeque<num>();
ArrayDeque<num> mxq = new ArrayDeque<num>();
int[] dp = new int[n];
for(int i = 0; i < l; i++)
{
while(mnq.size() > 0 && mnq.getLast().num > a[i])
{
mnq.pollLast();
}
mnq.add(new num(i, a[i]));
while(mxq.size() > 0 && mxq.getLast().num < a[i])
{
mxq.pollLast();
}
mxq.add(new num(i, a[i]));
int diff = mxq.getFirst().num - mnq.getFirst().num;
if(diff > s)
{
System.out.println("-1");
return;
}
dp[i] = NP;
}
dp[l - 1] = 1;
int li = -1;
for(int i = l; i < n; i++)
{
while(mnq.size() > 0 && mnq.getLast().num > a[i])
{
mnq.pollLast();
}
mnq.add(new num(i, a[i]));
while(mxq.size() > 0 && mxq.getLast().num < a[i])
{
mxq.pollLast();
}
mxq.add(new num(i, a[i]));
int diff = mxq.getFirst().num - mnq.getFirst().num;
dp[i] = NP;
if(diff <= s)
{
int pv = 0;
if(li != -1)
{
pv = dp[li];
}
dp[i] = pv + 1;
}
else
{
while(i - li >= l)
{
++li;
if(mnq.getFirst().i == li)
{
mnq.pollFirst();
}
if(mxq.getFirst().i == li)
{
mxq.pollFirst();
}
if((mxq.getFirst().num - mnq.getFirst().num <= s) && dp[li] < NP)
break;
}
if(i - li >= l)
dp[i] = Math.min(dp[i], dp[li] + 1);
}
}
if(dp[n - 1] >= NP)
System.out.println("-1");
else
System.out.println(dp[n - 1]);
}
private int rec(int ci, long[][] mn, long[][] mx, int logMx, int n, int[] dp, int l, int s, int[] a) {
if(ci >= n)
return 0;
if(dp[ci] != -1)
{
return dp[ci];
}
int mxi = n;
long cs = mx[ci][logMx] - mn[ci][logMx];
long cmn = mn[ci][logMx];
long cmx = mx[ci][logMx];
int cl = logMx;
while(true)
{
if(cs < s && rec(mxi, mn, mx, logMx, n, dp, l, s, a) < NP && (ci == n || Math.max(a[ci], cmx) - Math.min(a[ci], cmn) > s))
{
return (dp[ci] = 1 + rec(mxi, mn, mx, logMx, n, dp, l, s, a));
}
cl = cl - 1;
if(cl < 0)
break;
if(cs > s || rec(mxi, mn, mx, logMx, n, dp, l, s, a) >= NP)
{
cmn = mn[ci][cl];
cmx = mx[ci][cl];
cs = mx[ci][cl] - mn[ci][cl];
mxi = ci + tp[cl];
}
else if(cs < s)
{
cmn = mn[ci][cl];
cmx = mx[ci][cl];
cs = mx[ci][cl] - mn[ci][cl];
mxi = ci + tp[cl];
}
}
return (dp[ci] = NP);
}
public static void main(String[] args) throws FileNotFoundException {
(new _488D()).solve();
}
class InputHelper {
StringTokenizer tokenizer = null;
private BufferedReader bufferedReader;
public InputHelper(InputStream inputStream) {
InputStreamReader inputStreamReader = new InputStreamReader(
inputStream);
bufferedReader = new BufferedReader(inputStreamReader, 16384);
}
public String read() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
String line = bufferedReader.readLine();
if (line == null) {
return null;
}
tokenizer = new StringTokenizer(line);
} catch (IOException e) {
e.printStackTrace();
}
}
return tokenizer.nextToken();
}
public Integer readInteger() {
return Integer.parseInt(read());
}
public Long readLong() {
return Long.parseLong(read());
}
}
} | Java | ["7 2 2\n1 3 1 2 4 1 2", "7 2 2\n1 100 1 100 1 100 1"] | 1 second | ["3", "-1"] | NoteFor the first sample, we can split the strip into 3 pieces: [1,β3,β1],β[2,β4],β[1,β2].For the second sample, we can't let 1 and 100 be on the same piece, so no solution exists. | Java 7 | standard input | [
"dp",
"two pointers",
"binary search",
"data structures"
] | 3d670528c82a7d8dcd187b7304d36f96 | The first line contains three space-separated integers n,βs,βl (1ββ€βnββ€β105,β0ββ€βsββ€β109,β1ββ€βlββ€β105). The second line contains n integers ai separated by spaces (β-β109ββ€βaiββ€β109). | 2,000 | Output the minimal number of strip pieces. If there are no ways to split the strip, output -1. | standard output | |
PASSED | 7d335544fae0ee93c90c17cd33c5cc6f | train_003.jsonl | 1416590400 | Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right.Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: Each piece should contain at least l numbers. The difference between the maximal and the minimal number on the piece should be at most s.Please help Alexandra to find the minimal number of pieces meeting the condition above. | 256 megabytes | import java.util.*;
public class Main {
static int[][] min, max;
public static void main(String[] args) throws Exception {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int s = scanner.nextInt();
int l = scanner.nextInt();
int mp = (int) Math.ceil(Math.log(n) / Math.log(2)) + 1;
min = new int[mp][n];
max = new int[mp][n];
for (int i = 0; i < n; i++) {
min[0][i] = scanner.nextInt();
max[0][i] = min[0][i];
}
for (int i = 1; 1 << i <= n; i++) {
for (int j = 0; j < n - (1 << i) + 1; j++) {
min[i][j] = Math.min(min[i - 1][j],
min[i - 1][j + (1 << i - 1)]);
max[i][j] = Math.max(max[i - 1][j],
max[i - 1][j + (1 << i - 1)]);
}
}
int[] dp = new int[n + 1];
ArrayDeque<Integer> ad = new ArrayDeque<Integer>();
for (int i = 1; i < n + 1; i++) {
if (i >= l) {
while (!ad.isEmpty() && dp[ad.peekLast()] >= dp[i - l]) {
ad.pollLast();
}
ad.addLast(i - l);
}
while (!ad.isEmpty() && q(ad.peekFirst(), i - 1) > s) {
ad.pollFirst();
}
dp[i] = ad.isEmpty() ? Integer.MAX_VALUE >> 1
: dp[ad.peekFirst()] + 1;
}
System.out.println(dp[n] < Integer.MAX_VALUE >> 2 ? dp[n] : -1);
scanner.close();
}
public static int q(int l, int r) {
int mp = (int) Math.floor(Math.log(r - l + 1) / Math.log(2));
int a = Math.min(min[mp][l], min[mp][r - (1 << mp) + 1]);
int b = Math.max(max[mp][l], max[mp][r - (1 << mp) + 1]);
return b - a;
}
}
| Java | ["7 2 2\n1 3 1 2 4 1 2", "7 2 2\n1 100 1 100 1 100 1"] | 1 second | ["3", "-1"] | NoteFor the first sample, we can split the strip into 3 pieces: [1,β3,β1],β[2,β4],β[1,β2].For the second sample, we can't let 1 and 100 be on the same piece, so no solution exists. | Java 7 | standard input | [
"dp",
"two pointers",
"binary search",
"data structures"
] | 3d670528c82a7d8dcd187b7304d36f96 | The first line contains three space-separated integers n,βs,βl (1ββ€βnββ€β105,β0ββ€βsββ€β109,β1ββ€βlββ€β105). The second line contains n integers ai separated by spaces (β-β109ββ€βaiββ€β109). | 2,000 | Output the minimal number of strip pieces. If there are no ways to split the strip, output -1. | standard output | |
PASSED | 2440e10f34f3300c6dd6f34ce4108517 | train_003.jsonl | 1416590400 | Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right.Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: Each piece should contain at least l numbers. The difference between the maximal and the minimal number on the piece should be at most s.Please help Alexandra to find the minimal number of pieces meeting the condition above. | 256 megabytes | import java.util.*;
public class Main {
static int[][] min, max;
public static void main(String[] args) throws Exception {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int s = scanner.nextInt();
int l = scanner.nextInt();
int mp = (int) Math.ceil(Math.log(n) / Math.log(2)) + 1;
min = new int[mp][n];
max = new int[mp][n];
for (int i = 0; i < n; i++) {
min[0][i] = scanner.nextInt();
max[0][i] = min[0][i];
}
for (int i = 1; 1 << i <= n; i++) {
for (int j = 0; j < n - (1 << i) + 1; j++) {
min[i][j] = Math.min(min[i - 1][j],
min[i - 1][j + (1 << i - 1)]);
max[i][j] = Math.max(max[i - 1][j],
max[i - 1][j + (1 << i - 1)]);
}
}
int[] dp = new int[n + 1];
ArrayDeque<Integer> ad = new ArrayDeque<Integer>();
for (int i = 1; i < n + 1; i++) {
if (i >= l) {
while (!ad.isEmpty() && dp[ad.peekLast()] >= dp[i - l]) {
ad.pollLast();
}
ad.addLast(i - l);
}
while (!ad.isEmpty() && q(ad.peekFirst(), i - 1) > s) {
ad.pollFirst();
}
dp[i] = ad.isEmpty() ? Integer.MAX_VALUE >> 1
: dp[ad.peekFirst()] + 1;
}
System.out.println(dp[n] < Integer.MAX_VALUE >> 2 ? dp[n] : -1);
scanner.close();
}
public static int q(int l, int r) {
int mp = (int) Math.floor(Math.log(r - l + 1) / Math.log(2));
int a = Math.min(min[mp][l], min[mp][r - (1 << mp) + 1]);
int b = Math.max(max[mp][l], max[mp][r - (1 << mp) + 1]);
return b - a;
}
} | Java | ["7 2 2\n1 3 1 2 4 1 2", "7 2 2\n1 100 1 100 1 100 1"] | 1 second | ["3", "-1"] | NoteFor the first sample, we can split the strip into 3 pieces: [1,β3,β1],β[2,β4],β[1,β2].For the second sample, we can't let 1 and 100 be on the same piece, so no solution exists. | Java 7 | standard input | [
"dp",
"two pointers",
"binary search",
"data structures"
] | 3d670528c82a7d8dcd187b7304d36f96 | The first line contains three space-separated integers n,βs,βl (1ββ€βnββ€β105,β0ββ€βsββ€β109,β1ββ€βlββ€β105). The second line contains n integers ai separated by spaces (β-β109ββ€βaiββ€β109). | 2,000 | Output the minimal number of strip pieces. If there are no ways to split the strip, output -1. | standard output | |
PASSED | 4033f4f5a056569ee89981d89496e1bc | train_003.jsonl | 1416590400 | Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right.Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: Each piece should contain at least l numbers. The difference between the maximal and the minimal number on the piece should be at most s.Please help Alexandra to find the minimal number of pieces meeting the condition above. | 256 megabytes | //package round278;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class B {
InputStream is;
PrintWriter out;
String INPUT = "";
void solve()
{
int n = ni(), s = ni(), L = ni();
int[] a = na(n);
int[] b = new int[n];
for(int i = 0;i < n;i++){
b[i] = -a[i];
}
SegmentTreeRMQ dp = new SegmentTreeRMQ(n+1);
dp.update(0,0);
SegmentTreeRMQ stmax = new SegmentTreeRMQ(b);
SegmentTreeRMQ stmin = new SegmentTreeRMQ(a);
for(int i = 0;i < n;i++){
int low = -1, high = i;
while(high - low > 1){
int h = high+low>>>1;
int sub = -stmax.min(h, i+1) - stmin.min(h, i+1);
if(sub <= s){
high = h;
}else{
low = h;
}
}
if(high >= i+1+1-L){
dp.update(i+1, 999999);
}else{
int min = dp.min(high, i+1+1-L);
dp.update(i+1, min+1);
}
}
int ret = dp.min(n, n+1);
out.println(ret > 100000 ? -1 : ret);
}
public static class SegmentTreeRMQ {
public int M, H, N;
public int[] st;
public SegmentTreeRMQ(int n)
{
N = n;
M = Integer.highestOneBit(Math.max(N-1, 1))<<2;
H = M>>>1;
st = new int[M];
Arrays.fill(st, 0, M, Integer.MAX_VALUE);
}
public SegmentTreeRMQ(int[] a)
{
N = a.length;
M = Integer.highestOneBit(Math.max(N-1, 1))<<2;
H = M>>>1;
st = new int[M];
for(int i = 0;i < N;i++){
st[H+i] = a[i];
}
Arrays.fill(st, H+N, M, Integer.MAX_VALUE);
for(int i = H-1;i >= 1;i--)propagate(i);
}
public void update(int pos, int x)
{
st[H+pos] = x;
for(int i = (H+pos)>>>1;i >= 1;i >>>= 1)propagate(i);
}
private void propagate(int i)
{
st[i] = Math.min(st[2*i], st[2*i+1]);
}
public int min(int l, int r){ return l >= r ? 0 : min(l, r, 0, H, 1);}
private int min(int l, int r, int cl, int cr, int cur)
{
if(l <= cl && cr <= r){
return st[cur];
}else{
int mid = cl+cr>>>1;
int ret = Integer.MAX_VALUE;
if(cl < r && l < mid){
ret = Math.min(ret, min(l, r, cl, mid, 2*cur));
}
if(mid < r && l < cr){
ret = Math.min(ret, min(l, r, mid, cr, 2*cur+1));
}
return ret;
}
}
public int firstle(int l, int v) {
int cur = H+l;
while(true){
if(st[cur] <= v){
if(cur < H){
cur = 2*cur;
}else{
return cur-H;
}
}else{
cur++;
if((cur&cur-1) == 0)return -1;
if((cur&1)==0)cur>>>=1;
}
}
}
public int lastle(int l, int v) {
int cur = H+l;
while(true){
if(st[cur] <= v){
if(cur < H){
cur = 2*cur+1;
}else{
return cur-H;
}
}else{
if((cur&cur-1) == 0)return -1;
cur--;
if((cur&1)==1)cur>>>=1;
}
}
}
}
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 B().run(); }
private byte[] inbuf = new byte[1024];
private 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 | ["7 2 2\n1 3 1 2 4 1 2", "7 2 2\n1 100 1 100 1 100 1"] | 1 second | ["3", "-1"] | NoteFor the first sample, we can split the strip into 3 pieces: [1,β3,β1],β[2,β4],β[1,β2].For the second sample, we can't let 1 and 100 be on the same piece, so no solution exists. | Java 7 | standard input | [
"dp",
"two pointers",
"binary search",
"data structures"
] | 3d670528c82a7d8dcd187b7304d36f96 | The first line contains three space-separated integers n,βs,βl (1ββ€βnββ€β105,β0ββ€βsββ€β109,β1ββ€βlββ€β105). The second line contains n integers ai separated by spaces (β-β109ββ€βaiββ€β109). | 2,000 | Output the minimal number of strip pieces. If there are no ways to split the strip, output -1. | standard output | |
PASSED | 7dc04885951b1f7d505f9cff9e59f581 | train_003.jsonl | 1416590400 | Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right.Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: Each piece should contain at least l numbers. The difference between the maximal and the minimal number on the piece should be at most s.Please help Alexandra to find the minimal number of pieces meeting the condition above. | 256 megabytes | import java.util.*;
public class Main {
static int[][] min, max;
public static void main(String[] args) throws Exception {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int s = scanner.nextInt();
int l = scanner.nextInt();
int mp = (int) Math.ceil(Math.log(n) / Math.log(2)) + 1;
min = new int[mp][n];
max = new int[mp][n];
for (int i = 0; i < n; i++) {
min[0][i] = scanner.nextInt();
max[0][i] = min[0][i];
}
for (int i = 1; 1 << i <= n; i++) {
for (int j = 0; j < n - (1 << i) + 1; j++) {
min[i][j] = Math.min(min[i - 1][j],
min[i - 1][j + (1 << i - 1)]);
max[i][j] = Math.max(max[i - 1][j],
max[i - 1][j + (1 << i - 1)]);
}
}
int[] dp = new int[n + 1];
ArrayDeque<Integer> ad = new ArrayDeque<Integer>();
for (int i = 1; i < n + 1; i++) {
if (i >= l) {
while (!ad.isEmpty() && dp[ad.peekLast()] >= dp[i - l]) {
ad.pollLast();
}
ad.addLast(i - l);
}
while (!ad.isEmpty() && q(ad.peekFirst(), i - 1) > s) {
ad.pollFirst();
}
dp[i] = ad.isEmpty() ? Integer.MAX_VALUE >> 1
: dp[ad.peekFirst()] + 1;
}
System.out.println(dp[n] < Integer.MAX_VALUE >> 2 ? dp[n] : -1);
scanner.close();
}
public static int q(int l, int r) {
int mp = (int) Math.floor(Math.log(r - l + 1) / Math.log(2));
int a = Math.min(min[mp][l], min[mp][r - (1 << mp) + 1]);
int b = Math.max(max[mp][l], max[mp][r - (1 << mp) + 1]);
return b - a;
}
} | Java | ["7 2 2\n1 3 1 2 4 1 2", "7 2 2\n1 100 1 100 1 100 1"] | 1 second | ["3", "-1"] | NoteFor the first sample, we can split the strip into 3 pieces: [1,β3,β1],β[2,β4],β[1,β2].For the second sample, we can't let 1 and 100 be on the same piece, so no solution exists. | Java 7 | standard input | [
"dp",
"two pointers",
"binary search",
"data structures"
] | 3d670528c82a7d8dcd187b7304d36f96 | The first line contains three space-separated integers n,βs,βl (1ββ€βnββ€β105,β0ββ€βsββ€β109,β1ββ€βlββ€β105). The second line contains n integers ai separated by spaces (β-β109ββ€βaiββ€β109). | 2,000 | Output the minimal number of strip pieces. If there are no ways to split the strip, output -1. | standard output | |
PASSED | 74d7eeb5972be447f0bf48b8eb532afb | train_003.jsonl | 1416590400 | Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right.Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: Each piece should contain at least l numbers. The difference between the maximal and the minimal number on the piece should be at most s.Please help Alexandra to find the minimal number of pieces meeting the condition above. | 256 megabytes | import sun.reflect.generics.tree.Tree;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
//@SuppressWarnings("unused")
public class Solution {
public static void main(String[] args) throws IOException {
boolean isDebugMode = Arrays.asList(args).contains("DEBUG_MODE");
InputStream inputStream;
OutputStream outputStream;
if (isDebugMode) {
// inputStream = new ConsoleInputStream();
inputStream = new FileInputStream();
// outputStream = new FileOutputStream();
outputStream = new ConsoleOutputStream();
} else {
inputStream = new ConsoleInputStream();
outputStream = new ConsoleOutputStream();
}
inputStream.open();
outputStream.open();
new Solution().run(inputStream, outputStream, isDebugMode);
outputStream.close();
inputStream.close();
}
@SuppressWarnings("FieldCanBeLocal")
private InputStream in;
private OutputStream out;
private boolean isDebugMode;
private Timer timer = new Timer();
private void printInDebug(String s) throws IOException {
if (isDebugMode) {
out.println(s);
out.flush();
}
}
private void printTimer(String mark) throws IOException {
printInDebug(mark + ": " + timer.getMillisAndReset() + " ms.");
}
private static String formatDouble(double n, int precision) {
return String.format(Locale.ENGLISH, "%." + precision + "f", n);
}
private void run(InputStream in, OutputStream out, boolean isDebugMode) throws IOException {
this.in = in;
this.out = out;
this.isDebugMode = isDebugMode;
// int t = in.nextInt();
// for (int i = 0; i < t; i++) {
solve();
// out.flush();
// }
}
private void solve() throws IOException {
int n = in.nextInt();
int s = in.nextInt();
int l = in.nextInt();
int[] a = in.nextIntArray(n);
FSegmentTree tree = new FSegmentTree(a);
int[] tmp = new int[n + 1];
tmp[0] = 0;
for (int i = 1; i <= n; i++) tmp[i] = Integer.MAX_VALUE;
FSegmentTreeMin aans = new FSegmentTreeMin(tmp);
for (int i = l - 1; i < n; i++) {
int l0 = 0, r0 = i - l + 1;
while (l0 + 1 < r0) {
int m0 = (l0 + r0) / 2;
P p = new P();
tree.get(1, 0, n - 1, m0, i, p);
if (p.diff() <= s) {
r0 = m0;
} else {
l0 = m0;
}
}
while (r0 >= 0) {
P p = new P();
tree.get(1, 0, n - 1, r0, i, p);
if (p.diff() > s) {
break;
}
r0--;
}
r0++;
int mn = aans.get(1, 0, n, r0, i - l + 1);
if (mn < Integer.MAX_VALUE) {
if (tmp[i + 1] > mn + 1) {
aans.update(1, 0, n, i + 1, mn + 1);
tmp[i + 1] = mn + 1;
}
}
}
int mm = tmp[n];
out.println(mm == Integer.MAX_VALUE ? -1 : mm);
printTimer("time");
}
private static class FSegmentTree {
private int[] tmn;
private int[] tmx;
private FSegmentTree(int[] a) {
this.tmn = new int[a.length * 4];
this.tmx = new int[a.length * 4];
build(a, 1, 0, a.length - 1);
}
private void build(int a[], int v, int tl, int tr) {
if (tl == tr) {
tmn[v] = a[tl];
tmx[v] = a[tl];
} else {
int tm = (tl + tr) / 2;
build(a, v * 2, tl, tm);
build(a, v * 2 + 1, tm + 1, tr);
tmn[v] = Math.min(tmn[v * 2], tmn[v * 2 + 1]);
tmx[v] = Math.max(tmx[v * 2], tmx[v * 2 + 1]);
}
}
private void get(int v, int tl, int tr, int l, int r, P p) {
if (l > r)
return;
if (l == tl && r == tr) {
p.mn = Math.min(p.mn, tmn[v]);
p.mx = Math.max(p.mx, tmx[v]);
return;
}
int tm = (tl + tr) / 2;
get(v * 2, tl, tm, l, Math.min(r, tm), p);
get(v * 2 + 1, tm + 1, tr, Math.max(l, tm + 1), r, p);
}
}
private static class FSegmentTreeMin {
private int[] t;
private FSegmentTreeMin(int[] a) {
this.t = new int[a.length * 4];
build(a, 1, 0, a.length - 1);
}
private void build(int a[], int v, int tl, int tr) {
if (tl == tr)
t[v] = a[tl];
else {
int tm = (tl + tr) / 2;
build(a, v * 2, tl, tm);
build(a, v * 2 + 1, tm + 1, tr);
t[v] = Math.min(t[v * 2], t[v * 2 + 1]);
}
}
private int get(int v, int tl, int tr, int l, int r) {
if (l > r)
return Integer.MAX_VALUE;
if (l == tl && r == tr)
return t[v];
int tm = (tl + tr) / 2;
return Math.min(get(v * 2, tl, tm, l, Math.min(r, tm)), get(v * 2 + 1, tm + 1, tr, Math.max(l, tm + 1), r));
}
private void update(int v, int tl, int tr, int pos, int newVal) {
if (tl == tr)
t[v] = newVal;
else {
int tm = (tl + tr) / 2;
if (pos <= tm) {
update(v * 2, tl, tm, pos, newVal);
} else {
update(v * 2 + 1, tm + 1, tr, pos, newVal);
}
t[v] = Math.min(t[v * 2], t[v * 2 + 1]);
}
}
}
private static class P {
int mn, mx;
private P() {
this.mn = Integer.MAX_VALUE;
this.mx = Integer.MIN_VALUE;
}
private int diff() {
return mx - mn;
}
}
/*
* Template classes
* Author: Andrey Siunov
* Date: 29.08.2013
* Note: all classes are inner, because some testing servers do not run code with several classes
*/
private static class SegmentTree {
private static class Value {
private HashMap<Integer, Integer> vals;
private long res = 0;
private int firstX = -1;
private int lastX = -1;
private long diff = 0;
private Value() {
}
private Value(int val) {
this.vals = new HashMap<Integer, Integer>();
vals.put(val + 1, 1);
}
private void init(Value val1, Value val2) {
this.vals = new HashMap<Integer, Integer>(val1.vals);
for (Map.Entry<Integer, Integer> e : val2.vals.entrySet()) {
Integer p = vals.get(e.getKey());
vals.put(e.getKey(), (p == null ? 0 : p) + e.getValue());
}
}
}
private int n;
private Value[] values;
public SegmentTree(int n) {
this.n = n;
values = new Value[n * 4];
build(1, 0, n - 1);
}
private void build(int v, int tl, int tr) {
if (tl == tr) {
values[v] = new Value(tl);
} else {
int tm = (tl + tr) >> 1;
build(v << 1, tl, tm);
build((v << 1) + 1, tm + 1, tr);
values[v] = new Value();
pull(v);
}
}
public void update(int l, int r, int x) {
update(1, 0, n - 1, l, r, x);
}
private void update(int v, int tl, int tr, int l, int r, int x) {
if (tl == l && tr == r) {
Value pVal = values[v];
if (pVal.firstX < 0) {
pVal.firstX = x;
pVal.lastX = x;
for (Map.Entry<Integer, Integer> e : pVal.vals.entrySet()) {
pVal.res += Math.abs(e.getKey() - x) * (long) e.getValue();
}
pVal.vals.clear();
pVal.vals.put(x, r - l + 1);
} else {
pVal.res += (r - l + 1) * Math.abs(pVal.lastX - x);
pVal.vals.clear();
pVal.vals.put(x, r - l + 1);
pVal.diff += Math.abs(pVal.lastX - x);
pVal.lastX = x;
}
return;
}
int tm = (tl + tr) >> 1;
push(v, tl, tm, tr);
if (l <= tm) {
update(v << 1, tl, tm, l, Math.min(tm, r), x);
}
if (r >= tm + 1) {
update((v << 1) + 1, tm + 1, tr, Math.max(l, tm + 1), r, x);
}
pull(v);
}
public long get(int l, int r) {
return get(1, 0, n - 1, l, r);
}
private Long get(int v, int tl, int tr, int l, int r) {
if (l > r) {
return null;
}
int tm = (tl + tr) >> 1;
push(v, tl, tm, tr);
if (l == tl && r == tr) {
return values[v].res;
}
int leftTo = Math.min(r, tm);
Long leftValue = get(v << 1, tl, tm, l, leftTo);
int rightFrom = Math.max(l, tm + 1);
Long rightValue = get((v << 1) + 1, tm + 1, tr, rightFrom, r);
return leftValue == null ? rightValue :
(rightValue == null ? leftValue :
leftValue + rightValue);
}
private void pull(int v) {
Value pVal = values[v];
Value val1 = values[v << 1];
Value val2 = values[(v << 1) + 1];
pVal.lastX = -1;
pVal.firstX = -1;
pVal.diff = 0;
pVal.res = val1.res + val2.res;
pVal.init(val1, val2);
}
private void push(int v, int from, int mid, int to) {
if (from < to) {
push(values[v << 1], values[v], from, mid);
push(values[(v << 1) + 1], values[v], mid + 1, to);
}
}
private void push(Value val, Value pVal, int from, int to) {
if (from > to) return;
if (pVal.firstX >= 0) {
long d;
if (val.firstX >= 0) {
d = pVal.diff + Math.abs(pVal.firstX - val.lastX);
val.diff = d + val.diff;
val.lastX = pVal.lastX;
val.res += (to - from + 1) * d;
val.vals.clear();
val.vals.put(val.lastX, to - from + 1);
} else {
val.lastX = pVal.lastX;
val.firstX = pVal.firstX;
val.diff = pVal.diff;
val.res += (to - from + 1) * pVal.diff;
for (Map.Entry<Integer, Integer> e : val.vals.entrySet()) {
val.res += Math.abs(e.getKey() - val.firstX) * (long) e.getValue();
}
val.vals.clear();
val.vals.put(val.lastX, to - from + 1);
}
}
}
}
private static class Pair<K, V> {
private K key;
private V value;
Pair(K key, V value) {
this.key = key;
this.value = value;
}
K getKey() {
return key;
}
V getValue() {
return value;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Pair pair = (Pair) o;
return !(key != null ? !key.equals(pair.key) : pair.key != null) && !(value != null ? !value.equals(pair.value) : pair.value != null);
}
@Override
public int hashCode() {
int result = key != null ? key.hashCode() : 0;
result = 31 * result + (value != null ? value.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "Pair{" +
"key=" + key +
", value=" + value +
'}';
}
}
private static class Timer {
private long lastTime = 0;
private Timer() {
lastTime = System.currentTimeMillis();
}
public void reset() {
lastTime = System.currentTimeMillis();
}
public long getMillisAndReset() {
long current = System.currentTimeMillis();
long result = current - lastTime;
lastTime = current;
return result;
}
}
// IO template {
private static class FileInputStream extends InputStream {
private String inputFileName;
public FileInputStream() throws IOException {
this("input.txt");
}
public FileInputStream(String inputFileName) throws IOException {
this.inputFileName = inputFileName;
}
@Override
protected Reader getReader() throws IOException {
return new FileReader(inputFileName);
}
}
private static class ConsoleInputStream extends InputStream {
@Override
protected Reader getReader() throws IOException {
return new InputStreamReader(System.in);
}
}
private static abstract class InputStream {
private static String DELIMITERS = " \t\n\r\f";
private BufferedReader in;
public InputStream open() throws IOException {
in = new BufferedReader(getReader());
return this;
}
private class Line {
private Line(String inputLine) {
this.inputLine = inputLine;
stringTokenizer = new StringTokenizer(this.inputLine, DELIMITERS);
readCharacters = 0;
}
private int readCharacters;
private String inputLine = null;
private StringTokenizer stringTokenizer = null;
public String nextToken() {
String result = stringTokenizer.nextToken();
readCharacters += result.length();
return result;
}
boolean hasNextToken() {
return stringTokenizer.hasMoreTokens();
}
String getLineRest() {
int position = 0;
for (int remain = readCharacters; remain > 0; position++) {
if (DELIMITERS.indexOf(inputLine.charAt(position)) < 0) {
remain--;
}
}
return inputLine.substring(position);
}
}
private Line currentLine = null;
abstract protected Reader getReader() throws IOException;
/**
* Note: may be incorrect behavior if use this method with hasNextToken method
*/
public String nextLine() throws IOException {
setInputLine();
if (currentLine == null) {
return null;
}
String result = currentLine.getLineRest();
currentLine = null;
return result;
}
public boolean hasNextLine() throws IOException {
setInputLine();
return currentLine != null;
}
public String nextToken() throws IOException {
return hasNextToken() ? currentLine.nextToken() : null;
}
/**
* Note: may be incorrect behavior if use this method with nextLine method
*/
public boolean hasNextToken() throws IOException {
while (true) {
setInputLine();
if (currentLine == null || currentLine.hasNextToken()) {
break;
} else {
currentLine = null;
}
}
return currentLine != null;
}
public int nextInt() throws IOException {
return Integer.valueOf(this.nextToken());
}
public long nextLong() throws IOException {
return Long.valueOf(this.nextToken());
}
public double nextDouble() throws IOException {
return Double.valueOf(this.nextToken());
}
public BigInteger nextBigInteger() throws IOException {
return new BigInteger(this.nextToken());
}
public String[] nextTokensArray(int n) throws IOException {
String[] result = new String[n];
for (int i = 0; i < n; i++) {
result[i] = this.nextToken();
}
return result;
}
public int[] nextIntArray(int n) throws IOException {
int[] result = new int[n];
for (int i = 0; i < n; i++) {
result[i] = this.nextInt();
}
return result;
}
public long[] nextLongArray(int n) throws IOException {
long[] result = new long[n];
for (int i = 0; i < n; i++) {
result[i] = this.nextLong();
}
return result;
}
public BigInteger[] nextBigIntegerArray(int n) throws IOException {
BigInteger[] result = new BigInteger[n];
for (int i = 0; i < n; i++) {
result[i] = this.nextBigInteger();
}
return result;
}
public void close() throws IOException {
currentLine = null;
in.close();
}
private void setInputLine() throws IOException {
if (currentLine == null) {
String line = in.readLine();
if (line != null) {
currentLine = new Line(line);
}
}
}
}
private static class FileOutputStream extends OutputStream {
private String outputFileName;
public FileOutputStream() throws IOException {
this("output.txt");
}
public FileOutputStream(String outputFileName) throws IOException {
this.outputFileName = outputFileName;
}
@Override
protected Writer getWriter() throws IOException {
return new FileWriter(outputFileName);
}
}
private static class ConsoleOutputStream extends OutputStream {
@Override
protected Writer getWriter() throws IOException {
return new OutputStreamWriter(System.out);
}
}
private static abstract class OutputStream {
private PrintWriter out;
public OutputStream open() throws IOException {
out = new PrintWriter(getWriter());
return this;
}
abstract protected Writer getWriter() throws IOException;
public void print(Object... s) {
for (Object token : s) {
out.print(token);
}
}
public void println(Object... s) {
print(s);
out.println();
}
public void println() {
out.println();
}
public void flush() throws IOException {
out.flush();
}
public void close() throws IOException {
out.flush();
out.close();
}
}
// } IO template
} | Java | ["7 2 2\n1 3 1 2 4 1 2", "7 2 2\n1 100 1 100 1 100 1"] | 1 second | ["3", "-1"] | NoteFor the first sample, we can split the strip into 3 pieces: [1,β3,β1],β[2,β4],β[1,β2].For the second sample, we can't let 1 and 100 be on the same piece, so no solution exists. | Java 7 | standard input | [
"dp",
"two pointers",
"binary search",
"data structures"
] | 3d670528c82a7d8dcd187b7304d36f96 | The first line contains three space-separated integers n,βs,βl (1ββ€βnββ€β105,β0ββ€βsββ€β109,β1ββ€βlββ€β105). The second line contains n integers ai separated by spaces (β-β109ββ€βaiββ€β109). | 2,000 | Output the minimal number of strip pieces. If there are no ways to split the strip, output -1. | standard output | |
PASSED | 07f8488d32fe78baf595dfcaaff6b57b | train_003.jsonl | 1416590400 | Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right.Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: Each piece should contain at least l numbers. The difference between the maximal and the minimal number on the piece should be at most s.Please help Alexandra to find the minimal number of pieces meeting the condition above. | 256 megabytes | import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Deque;
import java.util.LinkedList;
import java.util.Collection;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author thnkndblv
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskB solver = new TaskB();
solver.solve(1, in, out);
out.close();
}
}
class TaskB {
private final int oo = (int)1e9;
public void solve(int testNumber, Scanner in, PrintWriter out) {
int n = in.nextInt();
int s = in.nextInt();
int l = in.nextInt();
int[] a = new int[n + 1];
for (int i = 1; i <= n; i++) a[i] = in.nextInt();
Deque<Integer> dqMax = new LinkedList<>();
Deque<Integer> dqMin = new LinkedList<>();
int[] b = new int[n + 1];
for (int i = 1, k = 1; i <= n; i++) {
while (dqMin.size() != 0 && a[dqMin.getLast()] >= a[i]) dqMin.removeLast();
dqMin.addLast(i);
while (dqMax.size() != 0 && a[dqMax.getLast()] <= a[i]) dqMax.removeLast();
dqMax.addLast(i);
while (a[dqMax.getFirst()] - a[dqMin.getFirst()] > s) {
if (dqMin.getFirst() == k) dqMin.removeFirst();
if (dqMax.getFirst() == k) dqMax.removeFirst();
k++;
}
b[i] = k - 1;
}
dqMin.clear();
int[] dp = new int[n + 1];
for (int i = 1, k = 0; i <= n; i++) {
for (; k <= i - l; k++) {
if (dp[k] == oo) continue;
while (dqMin.size() != 0 && dp[dqMin.getLast()] >= dp[k]) dqMin.removeLast();
dqMin.addLast(k);
//out.println(k + " " + dp[k] + " ADDED");
}
while (dqMin.size() != 0 && dqMin.getFirst() < b[i]) dqMin.removeFirst();
dp[ i ] = (dqMin.size() == 0) ? oo : dp[dqMin.getFirst()] + 1;
//out.println("==> " + i + " " + dp[i]);
}
out.println( dp[n] == oo ? -1 : dp[n] );
}
}
| Java | ["7 2 2\n1 3 1 2 4 1 2", "7 2 2\n1 100 1 100 1 100 1"] | 1 second | ["3", "-1"] | NoteFor the first sample, we can split the strip into 3 pieces: [1,β3,β1],β[2,β4],β[1,β2].For the second sample, we can't let 1 and 100 be on the same piece, so no solution exists. | Java 7 | standard input | [
"dp",
"two pointers",
"binary search",
"data structures"
] | 3d670528c82a7d8dcd187b7304d36f96 | The first line contains three space-separated integers n,βs,βl (1ββ€βnββ€β105,β0ββ€βsββ€β109,β1ββ€βlββ€β105). The second line contains n integers ai separated by spaces (β-β109ββ€βaiββ€β109). | 2,000 | Output the minimal number of strip pieces. If there are no ways to split the strip, output -1. | standard output | |
PASSED | f9e5d8bddf2a26cea721fc01610233c5 | train_003.jsonl | 1416590400 | Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right.Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: Each piece should contain at least l numbers. The difference between the maximal and the minimal number on the piece should be at most s.Please help Alexandra to find the minimal number of pieces meeting the condition above. | 256 megabytes | import java.io.*;
import java.util.*;
public class strip {
private static Reader in;
private static PrintWriter out;
static class SegmentTree {
public SegmentTree left, right;
public int start, end, max;
public SegmentTree(int start, int end) {
this.start = start;
this.end = end;
max = -(1 << 29);
if (start != end) {
int mid = (start + end) >> 1;
left = new SegmentTree(start,mid);
right = new SegmentTree(mid+1, end);
}
}
public void update(int p, int v) {
if (start == p && end == p) {
this.max = v;
return;
}
int mid = (start + end) >> 1;
if (mid >= p) left.update(p, v);
else right.update(p, v);
this.max = Math.max(left.max, right.max);
}
public int query(int s, int e) {
if (start == s && end == e) {
return max;
}
int mid = (start + end) >> 1;
if (mid >= e) return left.query(s, e);
else if (mid < s) return right.query(s, e);
else {
return Math.max(left.query(s, mid), right.query(mid+1, e));
}
}
}
public static void main(String[] args) throws IOException {
in = new Reader();
out = new PrintWriter(System.out, true);
int N = in.nextInt();
int S = in.nextInt();
int L = in.nextInt();
int[] arr = new int[N+1];
for (int i = 1; i <= N; i++)
arr[i] = in.nextInt();
SegmentTree max = new SegmentTree(0, N);
SegmentTree min = new SegmentTree(0, N);
for (int i = 1; i <= N; i++) {
max.update(i, arr[i]);
min.update(i, -arr[i]);
}
SegmentTree res = new SegmentTree(0, N);
res.update(0, 0);
for (int i = 1; i <= N; i++) {
int lo = 1, hi = i;
while (lo < hi) {
int mid = (lo + hi) >> 1;
if (max.query(mid, i)+min.query(mid, i) > S) {
lo = mid+1;
} else {
hi = mid;
}
}
int ans = (1 << 29);
if (lo-1 <= i-L) ans = -res.query(lo-1, i-L)+1;
res.update(i, -ans);
}
int ans = -res.query(N, N);
out.println(ans > N ? -1 : ans);
out.close();
System.exit(0);
}
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[1024];
int cnt = 0;
byte c = read();
while (c <= ' ')
c = read();
do {
buf[cnt++] = c;
} while ((c = read()) != '\n');
return new String(buf, 0, cnt);
}
public String next() throws IOException {
byte[] buf = new byte[1024];
int cnt = 0;
byte c = read();
while (c <= ' ')
c = read();
do {
buf[cnt++] = c;
} while ((c = read()) > ' ');
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 2\n1 3 1 2 4 1 2", "7 2 2\n1 100 1 100 1 100 1"] | 1 second | ["3", "-1"] | NoteFor the first sample, we can split the strip into 3 pieces: [1,β3,β1],β[2,β4],β[1,β2].For the second sample, we can't let 1 and 100 be on the same piece, so no solution exists. | Java 7 | standard input | [
"dp",
"two pointers",
"binary search",
"data structures"
] | 3d670528c82a7d8dcd187b7304d36f96 | The first line contains three space-separated integers n,βs,βl (1ββ€βnββ€β105,β0ββ€βsββ€β109,β1ββ€βlββ€β105). The second line contains n integers ai separated by spaces (β-β109ββ€βaiββ€β109). | 2,000 | Output the minimal number of strip pieces. If there are no ways to split the strip, output -1. | standard output | |
PASSED | 98be92e500234b28d6a4a1c034dde153 | train_003.jsonl | 1416590400 | Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right.Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: Each piece should contain at least l numbers. The difference between the maximal and the minimal number on the piece should be at most s.Please help Alexandra to find the minimal number of pieces meeting the condition above. | 256 megabytes | import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
/**
* @author Jens Staahl
*/
public class Prac {
// some local config
// static boolean test = false ;
private boolean test = System.getProperty("ONLINE_JUDGE") == null;
static String testDataFile = "testdata.txt";
// static String testDataFile = "testdata.txt";
private static String ENDL = "\n";
// Just solves the acutal kattis-problem
ZKattio io;
class SegmentTree {
public SegmentTree left, right;
public int start, end, max;
public SegmentTree(int start, int end) {
this. start = start;
this.end = end;
max = -(1<<29);
if(start != end) {
int mid = (start+end)>>1;
left = new SegmentTree(start, mid);
right = new SegmentTree(mid+1, end);
}
}
//p = pos, v = value
public void update(int p, int v) {
if(start == p && end == p){
this.max = v;
return;
}
int mid = (start + end) >> 1;
if (mid >= p) {
left.update(p, v);
} else {
right.update(p, v);
}
this.max = Math.max(left.max, right.max);
}
public int query(int s, int e) {
if (start == s && end == e) {
return max;
}
int mid = (start + end) >> 1;
if ( mid >= e) return left.query(s, e);
else if(mid < s) return right.query(s, e);
else {
return Math.max(left.query(s, mid), right.query(mid+1, e));
}
}
}
private void solve() throws Throwable {
io = new ZKattio(stream);
int n = io.getInt(), s = io.getInt(), l = io.getInt();
int[] r = new int[n+1];
for (int i = 0; i < n; i++) {
r[i+1] = io.getInt();
}
SegmentTree max = new SegmentTree(0, n);
SegmentTree min = new SegmentTree(0, n);
for (int i = 1; i <= n; i++) {
max.update(i, r[i]);
min.update(i, -r[i]);
}
SegmentTree res = new SegmentTree(0, n);
res.update(0, 0);
for (int i = 1; i <= n; i++) {
int lo = 1, hi = i;
while(lo < hi) {
int mid = (lo + hi) >> 1;
if (max.query(mid, i) + min.query(mid, i) > s) {
lo = mid + 1;
} else {
hi = mid;
}
}
int ans = (1<<29);
if (lo - 1 <= i - l) ans = -res.query(lo-1, i-l) + 1;
res.update(i, -ans);
}
int ans = -res.query(n, n);
System.out.println(ans > n ? -1 : ans);
}
public static void main(String[] args) throws Throwable {
new Prac().solve();
}
public Prac() throws Throwable {
if (test) {
stream = new FileInputStream(testDataFile);
}
}
InputStream stream = System.in;
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));// outStream
public class ZKattio extends PrintWriter {
public ZKattio(InputStream i) {
super(new BufferedOutputStream(System.out));
r = new BufferedReader(new InputStreamReader(i));
}
public ZKattio(InputStream i, OutputStream o) {
super(new BufferedOutputStream(o));
r = new BufferedReader(new InputStreamReader(i));
}
public boolean hasMoreTokens() {
return peekToken() != null;
}
public int getInt() {
return Integer.parseInt(nextToken());
}
public double getDouble() {
return Double.parseDouble(nextToken());
}
public long getLong() {
return Long.parseLong(nextToken());
}
public String getWord() {
return nextToken();
}
private BufferedReader r;
private String line;
private StringTokenizer st;
private String token;
private String peekToken() {
if (token == null)
try {
while (st == null || !st.hasMoreTokens()) {
line = r.readLine();
if (line == null)
return null;
st = new StringTokenizer(line);
}
token = st.nextToken();
} catch (IOException e) {
}
return token;
}
private String nextToken() {
String ans = peekToken();
token = null;
return ans;
}
}
// System.out;
} | Java | ["7 2 2\n1 3 1 2 4 1 2", "7 2 2\n1 100 1 100 1 100 1"] | 1 second | ["3", "-1"] | NoteFor the first sample, we can split the strip into 3 pieces: [1,β3,β1],β[2,β4],β[1,β2].For the second sample, we can't let 1 and 100 be on the same piece, so no solution exists. | Java 7 | standard input | [
"dp",
"two pointers",
"binary search",
"data structures"
] | 3d670528c82a7d8dcd187b7304d36f96 | The first line contains three space-separated integers n,βs,βl (1ββ€βnββ€β105,β0ββ€βsββ€β109,β1ββ€βlββ€β105). The second line contains n integers ai separated by spaces (β-β109ββ€βaiββ€β109). | 2,000 | Output the minimal number of strip pieces. If there are no ways to split the strip, output -1. | standard output | |
PASSED | 5a568cd6927fab6ae22207f5d3a5d8c2 | train_003.jsonl | 1416590400 | Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right.Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: Each piece should contain at least l numbers. The difference between the maximal and the minimal number on the piece should be at most s.Please help Alexandra to find the minimal number of pieces meeting the condition above. | 256 megabytes | import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;
/**
* @author Jens Staahl
*/
public class Prac {
// some local config
// static boolean test = false ;
private boolean test = System.getProperty("ONLINE_JUDGE") == null;
static String testDataFile = "testdata.txt";
// static String testDataFile = "testdata.txt";
private static String ENDL = "\n";
public long GCD(long a, long b){ if (b==0) return a; return GCD(b,a%b); }
public long LCM(long a, long b) {return a * b / GCD(a, b);}
// Just solves the acutal kattis-problem
ZKattio io;
class SegmentTree {
public SegmentTree left, right;
public int start, end, max;
public SegmentTree(int start, int end) {
this. start = start;
this.end = end;
max = -(1<<29);
if(start != end) {
int mid = (start+end)>>1;
left = new SegmentTree(start, mid);
right = new SegmentTree(mid+1, end);
}
}
//p = pos, v = value
public void update(int p, int v) {
if(start == p && end == p){
this.max = v;
return;
}
int mid = (start + end) >> 1;
if (mid >= p) {
left.update(p, v);
} else {
right.update(p, v);
}
this.max = Math.max(left.max, right.max);
}
public int query(int s, int e) {
if (start == s && end == e) {
return max;
}
int mid = (start + end) >> 1;
if ( mid >= e) return left.query(s, e);
else if(mid < s) return right.query(s, e);
else {
return Math.max(left.query(s, mid), right.query(mid+1, e));
}
}
}
private void solve() throws Throwable {
io = new ZKattio(stream);
int n = io.getInt(), limit = io.getInt(), minLen = io.getInt();
SegmentTree min = new SegmentTree(0, n);
SegmentTree max = new SegmentTree(0, n);
for (int i = 0; i < n; i++) {
int val = io.getInt();
min.update(i+1, -val);
max.update(i+1, val);
}
SegmentTree ans = new SegmentTree(0, n);
ans.update(0, 0);
for (int i = 1; i <= n; i++) {
int lo = 1, hi = i;
while(lo < hi) {
int mid = (lo + hi) >>1;
int minq = min.query(mid, i);
int maxq = max.query(mid, i);
if(maxq + minq > limit) {
lo = mid + 1;
} else {
hi = mid;
}
}
int minval = lo - 1;
int bestPrev = 1 << 29;
if(minval <= i-minLen) {
bestPrev = -ans.query(minval, i-minLen);
}
if(bestPrev == 1<<29) {
bestPrev = 1 << 29;
} else {
bestPrev ++;
}
ans.update(i, -bestPrev);
}
int ret = -ans.query(n, n);
if(ret == 1<<29) {
System.out.println(-1);
} else {
System.out.println(ret);
}
}
public static void main(String[] args) throws Throwable {
new Prac().solve();
}
public Prac() throws Throwable {
if (test) {
stream = new FileInputStream(testDataFile);
}
}
InputStream stream = System.in;
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));// outStream
public class ZKattio extends PrintWriter {
public ZKattio(InputStream i) {
super(new BufferedOutputStream(System.out));
r = new BufferedReader(new InputStreamReader(i));
}
public ZKattio(InputStream i, OutputStream o) {
super(new BufferedOutputStream(o));
r = new BufferedReader(new InputStreamReader(i));
}
public boolean hasMoreTokens() {
return peekToken() != null;
}
public int getInt() {
return Integer.parseInt(nextToken());
}
public double getDouble() {
return Double.parseDouble(nextToken());
}
public long getLong() {
return Long.parseLong(nextToken());
}
public String getWord() {
return nextToken();
}
private BufferedReader r;
private String line;
private StringTokenizer st;
private String token;
private String peekToken() {
if (token == null)
try {
while (st == null || !st.hasMoreTokens()) {
line = r.readLine();
if (line == null)
return null;
st = new StringTokenizer(line);
}
token = st.nextToken();
} catch (IOException e) {
}
return token;
}
private String nextToken() {
String ans = peekToken();
token = null;
return ans;
}
}
// System.out;
} | Java | ["7 2 2\n1 3 1 2 4 1 2", "7 2 2\n1 100 1 100 1 100 1"] | 1 second | ["3", "-1"] | NoteFor the first sample, we can split the strip into 3 pieces: [1,β3,β1],β[2,β4],β[1,β2].For the second sample, we can't let 1 and 100 be on the same piece, so no solution exists. | Java 7 | standard input | [
"dp",
"two pointers",
"binary search",
"data structures"
] | 3d670528c82a7d8dcd187b7304d36f96 | The first line contains three space-separated integers n,βs,βl (1ββ€βnββ€β105,β0ββ€βsββ€β109,β1ββ€βlββ€β105). The second line contains n integers ai separated by spaces (β-β109ββ€βaiββ€β109). | 2,000 | Output the minimal number of strip pieces. If there are no ways to split the strip, output -1. | standard output | |
PASSED | 2bdd0fb5ee8dc4cdeaeb65ecffe32f94 | train_003.jsonl | 1416590400 | Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right.Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: Each piece should contain at least l numbers. The difference between the maximal and the minimal number on the piece should be at most s.Please help Alexandra to find the minimal number of pieces meeting the condition above. | 256 megabytes | import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
/**
* @author Jens Staahl
*/
public class Prac {
// some local config
// static boolean test = false ;
private boolean test = System.getProperty("ONLINE_JUDGE") == null;
static String testDataFile = "testdata.txt";
// static String testDataFile = "testdata.txt";
private static String ENDL = "\n";
// Just solves the acutal kattis-problem
ZKattio io;
class SegmentTree {
public SegmentTree left, right;
public int start, end, max;
public SegmentTree(int start, int end) {
this. start = start;
this.end = end;
max = -(1<<29);
if(start != end) {
int mid = (start+end)>>1;
left = new SegmentTree(start, mid);
right = new SegmentTree(mid+1, end);
}
}
//p = pos, v = value
public void update(int p, int v) {
if(start == p && end == p){
this.max = v;
return;
}
int mid = (start + end) >> 1;
if (mid >= p) {
left.update(p, v);
} else {
right.update(p, v);
}
this.max = Math.max(left.max, right.max);
}
public int query(int s, int e) {
if (start == s && end == e) {
return max;
}
int mid = (start + end) >> 1;
if ( mid >= e) return left.query(s, e);
else if(mid < s) return right.query(s, e);
else {
return Math.max(left.query(s, mid), right.query(mid+1, e));
}
}
}
private void solve() throws Throwable {
io = new ZKattio(stream);
int n = io.getInt(), s = io.getInt(), l = io.getInt();
int[] r = new int[n+1];
for (int i = 0; i < n; i++) {
r[i+1] = io.getInt();
}
SegmentTree min = new SegmentTree(0, n);
SegmentTree max = new SegmentTree(0, n);
for (int i = 1; i <= n; i++) {
min.update(i, -r[i]);
max.update(i, r[i]);
}
SegmentTree result = new SegmentTree(0, n);
result.update(0, 0);
for (int i = 1; i <= n; i++) {
int lo = 1, hi = i;
int rightmostOk = i - l;
while(lo < hi) {
int mid = (lo + hi)>>1;
int minQ = min.query(mid, i);
int maxQ = max.query(mid, i);
if(minQ + maxQ > s) {
lo = mid + 1;
} else {
hi = mid;
}
}
int ans = (1<<29);
if(lo - 1 <= rightmostOk) {
ans = -result.query(lo-1, rightmostOk) + 1;
}
result.update(i, -ans);
}
int query = -result.query(n, n);
if(query < 1<<29){
System.out.println(query);
} else {
System.out.println(-1);
}
}
public static void main(String[] args) throws Throwable {
new Prac().solve();
}
public Prac() throws Throwable {
if (test) {
stream = new FileInputStream(testDataFile);
}
}
InputStream stream = System.in;
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));// outStream
public class ZKattio extends PrintWriter {
public ZKattio(InputStream i) {
super(new BufferedOutputStream(System.out));
r = new BufferedReader(new InputStreamReader(i));
}
public ZKattio(InputStream i, OutputStream o) {
super(new BufferedOutputStream(o));
r = new BufferedReader(new InputStreamReader(i));
}
public boolean hasMoreTokens() {
return peekToken() != null;
}
public int getInt() {
return Integer.parseInt(nextToken());
}
public double getDouble() {
return Double.parseDouble(nextToken());
}
public long getLong() {
return Long.parseLong(nextToken());
}
public String getWord() {
return nextToken();
}
private BufferedReader r;
private String line;
private StringTokenizer st;
private String token;
private String peekToken() {
if (token == null)
try {
while (st == null || !st.hasMoreTokens()) {
line = r.readLine();
if (line == null)
return null;
st = new StringTokenizer(line);
}
token = st.nextToken();
} catch (IOException e) {
}
return token;
}
private String nextToken() {
String ans = peekToken();
token = null;
return ans;
}
}
// System.out;
} | Java | ["7 2 2\n1 3 1 2 4 1 2", "7 2 2\n1 100 1 100 1 100 1"] | 1 second | ["3", "-1"] | NoteFor the first sample, we can split the strip into 3 pieces: [1,β3,β1],β[2,β4],β[1,β2].For the second sample, we can't let 1 and 100 be on the same piece, so no solution exists. | Java 7 | standard input | [
"dp",
"two pointers",
"binary search",
"data structures"
] | 3d670528c82a7d8dcd187b7304d36f96 | The first line contains three space-separated integers n,βs,βl (1ββ€βnββ€β105,β0ββ€βsββ€β109,β1ββ€βlββ€β105). The second line contains n integers ai separated by spaces (β-β109ββ€βaiββ€β109). | 2,000 | Output the minimal number of strip pieces. If there are no ways to split the strip, output -1. | standard output | |
PASSED | 2a899b19a1b2e71d61a90c2dde8f80c5 | train_003.jsonl | 1416590400 | Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right.Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: Each piece should contain at least l numbers. The difference between the maximal and the minimal number on the piece should be at most s.Please help Alexandra to find the minimal number of pieces meeting the condition above. | 256 megabytes | import java.io.*;
import java.util.*;
public final class strip
{
static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
static FastScanner sc=new FastScanner(br);
static PrintWriter out=new PrintWriter(System.out);
static int[][] st,st2;
static int[] log,a,first;
static long[] dp;
static int maxn=100004;
static long[] tree;
static int rmq1(int l,int r)
{
int val=log[r-l];
int x=st[val][l],y=st[val][r-(1<<val)+1];
return Math.min(a[x],a[y]);
}
static int rmq2(int l,int r)
{
int val=log[r-l];
int x=st2[val][l],y=st2[val][r-(1<<val)+1];
return Math.max(a[x],a[y]);
}
static void update(int node,int s,int e,int l,int r,long val)
{
if(s>e || l>e || r<s)
{
return;
}
if(s==e)
{
tree[node]=val;
}
else
{
int mid=(s+e)>>1;
update(node<<1,s,mid,l,r,val);update(node<<1|1,mid+1,e,l,r,val);
tree[node]=Math.min(tree[node<<1],tree[node<<1|1]);
}
}
static long get(int node,int s,int e,int l,int r)
{
if(s>e || l>e || r<s)
{
return Integer.MAX_VALUE;
}
if(l<=s && r>=e)
{
return tree[node];
}
else
{
int mid=(s+e)>>1;
long q1=get(node<<1,s,mid,l,r),q2=get(node<<1|1,mid+1,e,l,r);
return Math.min(q1,q2);
}
}
public static void main(String args[]) throws Exception
{
int n=sc.nextInt(),s=sc.nextInt(),l=sc.nextInt();a=new int[n];log=new int[maxn];first=new int[n];dp=new long[n];tree=new long[4*n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
for(int i=2;i<maxn;i++)
{
log[i]=log[i>>1]+1;
}
st=new int[log[n]+1][n];st2=new int[log[n]+1][n];
for(int i=0;i<n;i++)
{
st[0][i]=i;
st2[0][i]=i;
}
for(int mask=1;(1<<mask)<=n;mask++)
{
for(int i=0;i+(1<<mask)<=n;i++)
{
int x=st[mask-1][i],y=st[mask-1][i+(1<<(mask-1))];
st[mask][i]=(a[x]<=a[y])?x:y;
int x1=st2[mask-1][i],y1=st2[mask-1][i+(1<<(mask-1))];
st2[mask][i]=(a[x1]>=a[y1])?x1:y1;
}
}
for(int i=0;i<n;i++)
{
int low=0,high=i;
while(low<high)
{
int mid=(low+high+1)>>1,val1=rmq1(i-mid,i),val2=rmq2(i-mid,i);
if(Math.abs(a[i]-val1)<=s && Math.abs(a[i]-val2)<=s)
{
low=mid;
}
else
{
high=mid-1;
}
}
first[i]=i-low;
}
int max=-1;
for(int i=0;i<n;i++)
{
max=Math.max(max,first[i]);
first[i]=max;
}
for(int i=0;i<n;i++)
{
if(i<l-1 || i-first[i]+1<l)
{
dp[i]=Integer.MAX_VALUE;
}
else if(first[i]==0)
{
dp[i]=1;
}
else
{
long val=get(1,0,n-1,first[i]-1,i-l)+1;
dp[i]=val;
}
update(1,0,n-1,i,i,dp[i]);
}
//out.println(Arrays.toString(first)+"\n"+Arrays.toString(dp));
out.println(dp[n-1]<=n?dp[n-1]:-1);
out.close();
}
}
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 String next() throws Exception {
return nextToken().toString();
}
public int nextInt() throws Exception {
return Integer.parseInt(nextToken());
}
public long nextLong() throws Exception {
return Long.parseLong(nextToken());
}
public double nextDouble() throws Exception {
return Double.parseDouble(nextToken());
}
} | Java | ["7 2 2\n1 3 1 2 4 1 2", "7 2 2\n1 100 1 100 1 100 1"] | 1 second | ["3", "-1"] | NoteFor the first sample, we can split the strip into 3 pieces: [1,β3,β1],β[2,β4],β[1,β2].For the second sample, we can't let 1 and 100 be on the same piece, so no solution exists. | Java 7 | standard input | [
"dp",
"two pointers",
"binary search",
"data structures"
] | 3d670528c82a7d8dcd187b7304d36f96 | The first line contains three space-separated integers n,βs,βl (1ββ€βnββ€β105,β0ββ€βsββ€β109,β1ββ€βlββ€β105). The second line contains n integers ai separated by spaces (β-β109ββ€βaiββ€β109). | 2,000 | Output the minimal number of strip pieces. If there are no ways to split the strip, output -1. | standard output | |
PASSED | eb181dbdab32ba50dcbc9c80add518a6 | train_003.jsonl | 1416590400 | Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right.Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: Each piece should contain at least l numbers. The difference between the maximal and the minimal number on the piece should be at most s.Please help Alexandra to find the minimal number of pieces meeting the condition above. | 256 megabytes | import java.io.*;
import java.util.*;
public class cf278D {
static int[][] min, max;
public static void main(String[] args) throws Exception {
// BufferedReader in = new BufferedReader(new FileReader("cf278D.in"));
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String str = in.readLine();
int n = Integer.parseInt(str.substring(0, str.indexOf(" ")));
int s = Integer.parseInt(str.substring(str.indexOf(" ") + 1, str.lastIndexOf(" ")));
int l = Integer.parseInt(str.substring(str.lastIndexOf(" ") + 1));
int mp = (int) Math.ceil(Math.log(n) / Math.log(2)) + 1;
min = new int[mp][n];
max = new int[mp][n];
String[] arr = in.readLine().split(" ");
for(int i = 0; i < n; i++) {
min[0][i] = Integer.parseInt(arr[i]);
max[0][i] = min[0][i];
}
for(int i = 1; 1 << i <= n; i++) {
for(int j = 0; j < n - (1 << i) + 1; j++) {
min[i][j] = Math.min(min[i - 1][j], min[i - 1][j + (1 << i - 1)]);
max[i][j] = Math.max(max[i - 1][j], max[i - 1][j + (1 << i - 1)]);
}
}
int[] dp = new int[n + 1];
ArrayDeque<Integer> ad = new ArrayDeque<Integer>();
for(int i = 1; i < n + 1; i++) {
if(i >= l) {
while(!ad.isEmpty() && dp[ad.peekLast()] >= dp[i - l]) {
ad.pollLast();
}
ad.addLast(i - l);
}
while(!ad.isEmpty() && q(ad.peekFirst(), i - 1) > s) {
ad.pollFirst();
}
dp[i] = ad.isEmpty() ? Integer.MAX_VALUE >> 1 : dp[ad.peekFirst()] + 1;
}
System.out.println(dp[n] < Integer.MAX_VALUE >> 2 ? dp[n] : -1);
}
public static int q(int l, int r) {
int mp = (int) Math.floor(Math.log(r - l + 1) / Math.log(2));
int a = Math.min(min[mp][l], min[mp][r - (1 << mp) + 1]);
int b = Math.max(max[mp][l], max[mp][r - (1 << mp) + 1]);
return b - a;
}
} | Java | ["7 2 2\n1 3 1 2 4 1 2", "7 2 2\n1 100 1 100 1 100 1"] | 1 second | ["3", "-1"] | NoteFor the first sample, we can split the strip into 3 pieces: [1,β3,β1],β[2,β4],β[1,β2].For the second sample, we can't let 1 and 100 be on the same piece, so no solution exists. | Java 7 | standard input | [
"dp",
"two pointers",
"binary search",
"data structures"
] | 3d670528c82a7d8dcd187b7304d36f96 | The first line contains three space-separated integers n,βs,βl (1ββ€βnββ€β105,β0ββ€βsββ€β109,β1ββ€βlββ€β105). The second line contains n integers ai separated by spaces (β-β109ββ€βaiββ€β109). | 2,000 | Output the minimal number of strip pieces. If there are no ways to split the strip, output -1. | standard output | |
PASSED | 68b99143ea6fd61206c2b036db39ba0a | train_003.jsonl | 1416590400 | Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right.Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: Each piece should contain at least l numbers. The difference between the maximal and the minimal number on the piece should be at most s.Please help Alexandra to find the minimal number of pieces meeting the condition above. | 256 megabytes | import java.io.*;
import java.util.*;
public class cf278D {
static int[][] min;
static int[][] max;
public static void main(String[] args) throws Exception {
// BufferedReader in = new BufferedReader(new FileReader("cf278D.in"));
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String str = in.readLine();
int n = Integer.parseInt(str.substring(0, str.indexOf(" ")));
int s = Integer.parseInt(str.substring(str.indexOf(" ") + 1, str.lastIndexOf(" ")));
int l = Integer.parseInt(str.substring(str.lastIndexOf(" ") + 1));
int maxpow = (int) Math.ceil(Math.log(n) / Math.log(2)) + 1;
min = new int[maxpow][n];
max = new int[maxpow][n];
String[] arr = in.readLine().split(" ");
int[] a = new int[arr.length];
for(int i = 0; i < a.length; i++) {
a[i] = Integer.parseInt(arr[i]);
min[0][i] = a[i];
max[0][i] = a[i];
}
for(int i = 1; 1 << i <= n; i++) {
for(int j = 0; j < n - (1 << i) + 1; j++) {
min[i][j] = Math.min(min[i - 1][j], min[i - 1][j + (1 << i - 1)]);
max[i][j] = Math.max(max[i - 1][j], max[i - 1][j + (1 << i - 1)]);
}
}
int[] dp = new int[n + 1];
ArrayDeque<Integer> ad = new ArrayDeque<Integer>();
for(int i = 1; i < n + 1; i++) {
if(i >= l) {
while(!ad.isEmpty() && dp[ad.peekLast()] >= dp[i - l]) {
ad.pollLast();
}
ad.addLast(i - l);
}
while(!ad.isEmpty() && q(ad.peekFirst(), i - 1) > s) {
ad.pollFirst();
}
if(ad.isEmpty()) {
dp[i] = Integer.MAX_VALUE >> 1;
} else {
dp[i] = dp[ad.peekFirst()] + 1;
}
}
System.out.println(dp[n] < Integer.MAX_VALUE >> 2 ? dp[n] : -1);
}
public static int q(int l, int r) {
int maxpow = (int) Math.floor(Math.log(r - l + 1) / Math.log(2));
int a = Math.min(min[maxpow][l], min[maxpow][r - (1 << maxpow) + 1]);
int b = Math.max(max[maxpow][l], max[maxpow][r - (1 << maxpow) + 1]);
return b - a;
}
} | Java | ["7 2 2\n1 3 1 2 4 1 2", "7 2 2\n1 100 1 100 1 100 1"] | 1 second | ["3", "-1"] | NoteFor the first sample, we can split the strip into 3 pieces: [1,β3,β1],β[2,β4],β[1,β2].For the second sample, we can't let 1 and 100 be on the same piece, so no solution exists. | Java 7 | standard input | [
"dp",
"two pointers",
"binary search",
"data structures"
] | 3d670528c82a7d8dcd187b7304d36f96 | The first line contains three space-separated integers n,βs,βl (1ββ€βnββ€β105,β0ββ€βsββ€β109,β1ββ€βlββ€β105). The second line contains n integers ai separated by spaces (β-β109ββ€βaiββ€β109). | 2,000 | Output the minimal number of strip pieces. If there are no ways to split the strip, output -1. | standard output | |
PASSED | 49438ad8904e1260465a7431b040497a | train_003.jsonl | 1416590400 | Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right.Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: Each piece should contain at least l numbers. The difference between the maximal and the minimal number on the piece should be at most s.Please help Alexandra to find the minimal number of pieces meeting the condition above. | 256 megabytes | import java.io.*;
import java.util.*;
public class cf278D {
static int[][] min;
static int[][] max;
public static void main(String[] args) throws Exception {
// BufferedReader in = new BufferedReader(new FileReader("cf278D.in"));
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String str = in.readLine();
int n = Integer.parseInt(str.substring(0, str.indexOf(" ")));
int s = Integer.parseInt(str.substring(str.indexOf(" ") + 1, str.lastIndexOf(" ")));
int l = Integer.parseInt(str.substring(str.lastIndexOf(" ") + 1));
int maxpow = (int) Math.ceil(Math.log(n) / Math.log(2)) + 1;
min = new int[maxpow][n];
max = new int[maxpow][n];
String[] arr = in.readLine().split(" ");
int[] a = new int[arr.length];
for(int i = 0; i < a.length; i++) {
a[i] = Integer.parseInt(arr[i]);
min[0][i] = a[i];
max[0][i] = a[i];
}
for(int i = 1; 1 << i <= n; i++) {
for(int j = 0; j < n - (1 << i) + 1; j++) {
min[i][j] = Math.min(min[i - 1][j], min[i - 1][j + (1 << i - 1)]);
max[i][j] = Math.max(max[i - 1][j], max[i - 1][j + (1 << i - 1)]);
}
}
int[] dp = new int[n + 1];
ArrayDeque<Integer> ad = new ArrayDeque<Integer>();
for(int i = 1; i < n + 1; i++) {
if(i >= l) {
while(!ad.isEmpty() && dp[ad.peekLast()] >= dp[i - l]) {
ad.pollLast();
}
ad.addLast(i - l);
}
while(!ad.isEmpty() && q(ad.peekFirst(), i - 1) > s) {
ad.pollFirst();
}
dp[i] = ad.isEmpty() ? Integer.MAX_VALUE >> 1 : dp[ad.peekFirst()] + 1;
}
System.out.println(dp[n] < Integer.MAX_VALUE >> 2 ? dp[n] : -1);
}
public static int q(int l, int r) {
int maxpow = (int) Math.floor(Math.log(r - l + 1) / Math.log(2));
int a = Math.min(min[maxpow][l], min[maxpow][r - (1 << maxpow) + 1]);
int b = Math.max(max[maxpow][l], max[maxpow][r - (1 << maxpow) + 1]);
return b - a;
}
} | Java | ["7 2 2\n1 3 1 2 4 1 2", "7 2 2\n1 100 1 100 1 100 1"] | 1 second | ["3", "-1"] | NoteFor the first sample, we can split the strip into 3 pieces: [1,β3,β1],β[2,β4],β[1,β2].For the second sample, we can't let 1 and 100 be on the same piece, so no solution exists. | Java 7 | standard input | [
"dp",
"two pointers",
"binary search",
"data structures"
] | 3d670528c82a7d8dcd187b7304d36f96 | The first line contains three space-separated integers n,βs,βl (1ββ€βnββ€β105,β0ββ€βsββ€β109,β1ββ€βlββ€β105). The second line contains n integers ai separated by spaces (β-β109ββ€βaiββ€β109). | 2,000 | Output the minimal number of strip pieces. If there are no ways to split the strip, output -1. | standard output | |
PASSED | ae34c121349f41a40fe484151cbac314 | train_003.jsonl | 1416590400 | Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right.Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: Each piece should contain at least l numbers. The difference between the maximal and the minimal number on the piece should be at most s.Please help Alexandra to find the minimal number of pieces meeting the condition above. | 256 megabytes | import java.io.*;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
public class B {
final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
BufferedReader in;
PrintWriter out;
StringTokenizer tok = new StringTokenizer("");
Random rg = new Random(322);
class Treap {
class Node {
Node left, right;
long prior;
int key;
int value;
int minValue;
Node(int key, int value) {
this.key = key;
this.value = value;
this.minValue = value;
prior = rg.nextLong();
}
}
Node root;
void update(Node node){
if(node != null) {
node.minValue = Math.min(node.value, Math.min(getValue(node.left), getValue(node.right)));
}
}
int getValue(Node node) {
return node == null ? 1000000 : node.minValue;
}
Node merge(Node left, Node right) {
if(left == null) {
return right;
}
if(right == null) {
return left;
}
Node res;
if(left.prior > right.prior) {
res = merge(left.right, right);
left.right = res;
res = left;
} else {
res = merge(left, right.left);
right.left = res;
res = right;
}
update(res);
return res;
}
Node[] split(Node t, int key) {
if(t == null) {
return new Node[2];
}
Node[] res;
if(key < t.key) {
res = split(t.left, key);
t.left = res[1];
res[1] = t;
} else {
res = split(t.right, key);
t.right = res[0];
res[0] = t;
}
update(res[0]);
update(res[1]);
return res;
}
void add(int index, int value) {
root = merge(root, new Node(index, value));
}
int getMinValueOnInterval(int left, int right) {
Node[] parts = split(root, right);
Node r = parts[1];
parts = split(parts[0], left-1);
int res = getValue(parts[1]);
root = merge(parts[0], merge(parts[1], r));
return res;
}
}
void solve() throws IOException {
int n = readInt();
int s = readInt();
int l = readInt();
int[] a = readArr(n);
int[] left = new int[n];
int j = 0;
TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
for(int i = 0; i < n; i++) {
Integer cur = map.get(a[i]);
map.put(a[i], cur == null ? 1 : cur + 1);
while (true) {
int min = map.firstKey();
int max = map.lastKey();
int d = max - min;
if(d <= s) break;
int z = map.get(a[j])-1;
if(z == 0) {
map.remove(a[j]);
} else {
map.put(a[j], z);
}
j++;
}
left[i] = j;
}
Treap treap = new Treap();
int[] mins = new int[n];
for(int i = 0; i < n; i++) {
int x = left[i];
int y = i - l + 1;
if(x > y) {
mins[i] = Integer.MAX_VALUE / 2;
treap.add(i, mins[i]);
continue;
}
if(x == 0) {
mins[i] = 1;
treap.add(i, 1);
continue;
}
int min = treap.getMinValueOnInterval(x-1, y-1);
mins[i] = min + 1;
treap.add(i, mins[i]);
}
out.print(mins[n-1] > n ? -1 : mins[n-1]);
}
void init() throws FileNotFoundException {
if (ONLINE_JUDGE) {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
} else {
in = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
}
}
String readString() throws IOException {
while (!tok.hasMoreTokens()) {
tok = new StringTokenizer(in.readLine());
}
return tok.nextToken();
}
int readInt() throws IOException {
return Integer.parseInt(readString());
}
long readLong() throws IOException {
return Long.parseLong(readString());
}
double readDouble() throws IOException {
return Double.parseDouble(readString());
}
int[] readArr(int n) throws IOException {
int[] res = new int[n];
for (int i = 0; i < n; i++) {
res[i] = readInt();
}
return res;
}
long[] readArrL(int n) throws IOException {
long[] res = new long[n];
for (int i = 0; i < n; i++) {
res[i] = readLong();
}
return res;
}
public static void main(String[] args) {
new B().run();
}
public void run() {
try {
long t1 = System.currentTimeMillis();
init();
solve();
out.close();
long t2 = System.currentTimeMillis();
System.err.println("Time = " + (t2 - t1));
} catch (Exception e) {
e.printStackTrace(System.err);
System.exit(-1);
}
}
} | Java | ["7 2 2\n1 3 1 2 4 1 2", "7 2 2\n1 100 1 100 1 100 1"] | 1 second | ["3", "-1"] | NoteFor the first sample, we can split the strip into 3 pieces: [1,β3,β1],β[2,β4],β[1,β2].For the second sample, we can't let 1 and 100 be on the same piece, so no solution exists. | Java 7 | standard input | [
"dp",
"two pointers",
"binary search",
"data structures"
] | 3d670528c82a7d8dcd187b7304d36f96 | The first line contains three space-separated integers n,βs,βl (1ββ€βnββ€β105,β0ββ€βsββ€β109,β1ββ€βlββ€β105). The second line contains n integers ai separated by spaces (β-β109ββ€βaiββ€β109). | 2,000 | Output the minimal number of strip pieces. If there are no ways to split the strip, output -1. | standard output | |
PASSED | 58b1ac3dd532274f9c4c25d2b1743028 | train_003.jsonl | 1416590400 | Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right.Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: Each piece should contain at least l numbers. The difference between the maximal and the minimal number on the piece should be at most s.Please help Alexandra to find the minimal number of pieces meeting the condition above. | 256 megabytes | //package codeforces;
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeMap;
/**
* Created by nitin.s on 25/03/16.
*/
public class Strip {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
int n = in.nextInt();
int maxDiff = in.nextInt();
int minSize = in.nextInt();
int[] list = new int[n];
for(int i = 0; i < n; ++i) {
list[i] = in.nextInt();
}
int[] dp = new int[n + 1];
Arrays.fill(dp, 1 << 25);
dp[0] = 0;
int left = 0;
for(int i = 0; i < n; ++i) {
change(map, list[i], 1);
while(!map.isEmpty() && (map.lastKey() - map.firstKey() > maxDiff || dp[left] == 1 << 25)) {
change(map, list[left++], -1);
}
if(dp[left] == 1 << 25 || map.isEmpty()) {
break;
}
if(i - left + 1 >= minSize) {
dp[i + 1] = dp[left] + 1;
}
}
int ret = dp[n];
if(ret == 1 << 25) {
ret = -1;
}
System.out.println(ret);
}
private static void change(TreeMap<Integer, Integer> map, int key, int value) {
if(!map.containsKey(key)) {
map.put(key, 0);
}
Integer next = map.get(key) + value;
if(next == 0) {
map.remove(key);
} else {
map.put(key, next);
}
}
}
| Java | ["7 2 2\n1 3 1 2 4 1 2", "7 2 2\n1 100 1 100 1 100 1"] | 1 second | ["3", "-1"] | NoteFor the first sample, we can split the strip into 3 pieces: [1,β3,β1],β[2,β4],β[1,β2].For the second sample, we can't let 1 and 100 be on the same piece, so no solution exists. | Java 7 | standard input | [
"dp",
"two pointers",
"binary search",
"data structures"
] | 3d670528c82a7d8dcd187b7304d36f96 | The first line contains three space-separated integers n,βs,βl (1ββ€βnββ€β105,β0ββ€βsββ€β109,β1ββ€βlββ€β105). The second line contains n integers ai separated by spaces (β-β109ββ€βaiββ€β109). | 2,000 | Output the minimal number of strip pieces. If there are no ways to split the strip, output -1. | standard output | |
PASSED | b5896820a9bca65b1a2ca735a906fe0b | train_003.jsonl | 1335614400 | The Smart Beaver from ABBYY has a long history of cooperating with the "Institute of Cytology and Genetics". Recently, the Institute staff challenged the Beaver with a new problem. The problem is as follows.There is a collection of n proteins (not necessarily distinct). Each protein is a string consisting of lowercase Latin letters. The problem that the scientists offered to the Beaver is to select a subcollection of size k from the initial collection of proteins so that the representativity of the selected subset of proteins is maximum possible.The Smart Beaver from ABBYY did some research and came to the conclusion that the representativity of a collection of proteins can be evaluated by a single number, which is simply calculated. Let's suppose we have a collection {a1,β...,βak} consisting of k strings describing proteins. The representativity of this collection is the following value: where f(x,βy) is the length of the longest common prefix of strings x and y; for example, f("abc", "abd")β=β2, and f("ab", "bcd")β=β0.Thus, the representativity of collection of proteins {"abc", "abd", "abe"} equals 6, and the representativity of collection {"aaa", "ba", "ba"} equals 2.Having discovered that, the Smart Beaver from ABBYY asked the Cup contestants to write a program that selects, from the given collection of proteins, a subcollection of size k which has the largest possible value of representativity. Help him to solve this problem! | 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 F implements Runnable {
private MyScanner in;
private PrintWriter out;
final int ALPH = 26;
int[][] trie;
int states;
int[] wasInState;
int[] finishInState;
void addToTrie(char[] s, int pos, int state) {
wasInState[state]++;
if (pos == s.length) {
finishInState[state]++;
return;
}
int c = s[pos] - 'a';
if (trie[c][state] == -1) {
trie[c][state] = states++;
}
addToTrie(s, pos + 1, trie[c][state]);
}
private void solve() {
int n = in.nextInt();
int k = in.nextInt();
char[][] proteins = new char[n][];
int sumLen = 0;
for (int i = 0; i < n; ++i) {
proteins[i] = in.next().toCharArray();
sumLen += proteins[i].length;
}
trie = new int[ALPH][sumLen + 1];
for (int[] a : trie) {
Arrays.fill(a, -1);
}
states = 1;
wasInState = new int[sumLen + 1];
finishInState = new int[sumLen + 1];
for (int i = 0; i < n; ++i) {
addToTrie(proteins[i], 0, 0);
}
int[][] maxScore = new int[states][];
int[][] innerDP = new int[ALPH + 1][k + 1];
for (int i = states - 1; i >= 0; --i) {
for (int[] a : innerDP) {
Arrays.fill(a, -1);
}
int max = Math.min(k, wasInState[i]);
for (int j = 0; j <= Math.min(max, finishInState[i]); ++j) {
innerDP[0][j] = 0;
}
for (int j = 0; j < ALPH; ++j) {
for (int t = 0; t <= max; ++t) {
int cur = innerDP[j][t];
if (cur < 0) {
continue;
}
int nextState = trie[j][i];
if (nextState == -1) {
innerDP[j + 1][t] = cur;
continue;
}
int maxAdd = Math.min(k, wasInState[nextState]);
for (int add = 0; add <= maxAdd && t + add <= max; ++add) {
innerDP[j + 1][t + add] = Math.max(innerDP[j + 1][t
+ add], cur + add * (add - 1) / 2
+ maxScore[nextState][add]);
}
}
}
int[] curScore = maxScore[i] = new int[max + 1];
for (int j = 0; j <= max; ++j) {
curScore[j] = innerDP[ALPH][j];
}
}
out.println(maxScore[0][k]);
}
@Override
public void run() {
in = new MyScanner();
out = new PrintWriter(System.out);
solve();
in.close();
out.close();
}
public static void main(String[] args) {
new F().run();
}
class MyScanner {
private BufferedReader br;
private StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
public void close() {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public boolean hasNext() {
while (st == null || !st.hasMoreTokens()) {
try {
String s = br.readLine();
if (s == null) {
return false;
}
st = new StringTokenizer(s);
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
return st != null && st.hasMoreTokens();
}
private String next() {
while (st == null || !st.hasMoreTokens()) {
try {
String s = br.readLine();
if (s == null) {
return null;
}
st = new StringTokenizer(s);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
return st.nextToken();
}
public String nextLine() {
try {
st = null;
return br.readLine();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
} | Java | ["3 2\naba\nbzd\nabq", "4 3\neee\nrrr\nttt\nqqq", "4 3\naaa\nabba\nabbc\nabbd"] | 2 seconds | ["2", "0", "9"] | null | Java 6 | standard input | [
"dp",
"sortings",
"strings"
] | 637ba13f9d567f5bac92853e3ee1824c | The first input line contains two integers n and k (1ββ€βkββ€βn), separated by a single space. The following n lines contain the descriptions of proteins, one per line. Each protein is a non-empty string of no more than 500 characters consisting of only lowercase Latin letters (a...z). Some of the strings may be equal. The input limitations for getting 20 points are: 1ββ€βnββ€β20 The input limitations for getting 50 points are: 1ββ€βnββ€β100 The input limitations for getting 100 points are: 1ββ€βnββ€β2000 | 2,200 | Print a single number denoting the largest possible value of representativity that a subcollection of size k of the given collection of proteins can have. | standard output | |
PASSED | a050cddd873ad02e1e21212aca3540a7 | train_003.jsonl | 1335614400 | The Smart Beaver from ABBYY has a long history of cooperating with the "Institute of Cytology and Genetics". Recently, the Institute staff challenged the Beaver with a new problem. The problem is as follows.There is a collection of n proteins (not necessarily distinct). Each protein is a string consisting of lowercase Latin letters. The problem that the scientists offered to the Beaver is to select a subcollection of size k from the initial collection of proteins so that the representativity of the selected subset of proteins is maximum possible.The Smart Beaver from ABBYY did some research and came to the conclusion that the representativity of a collection of proteins can be evaluated by a single number, which is simply calculated. Let's suppose we have a collection {a1,β...,βak} consisting of k strings describing proteins. The representativity of this collection is the following value: where f(x,βy) is the length of the longest common prefix of strings x and y; for example, f("abc", "abd")β=β2, and f("ab", "bcd")β=β0.Thus, the representativity of collection of proteins {"abc", "abd", "abe"} equals 6, and the representativity of collection {"aaa", "ba", "ba"} equals 2.Having discovered that, the Smart Beaver from ABBYY asked the Cup contestants to write a program that selects, from the given collection of proteins, a subcollection of size k which has the largest possible value of representativity. Help him to solve this problem! | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution {
private StringTokenizer st;
private BufferedReader in;
private PrintWriter out;
static int k;
static class Node {
int count;
List<Node> nodes = new ArrayList<Node>();
int[] din() {
int[] ret = new int[Math.min(k, count) + 1];
int c = 0;
for (Node n : nodes) {
int[] d = n.din();
for (int i = Math.min(k, c); i >= 0; --i) {
for (int j = 1; j < d.length && i + j <= k; ++j) {
ret[i + j] = Math.max(ret[i + j], ret[i] + d[j]);
}
}
c += n.count;
}
for (int i = c + 1; i < ret.length; ++i) {
ret[i] = ret[i - 1];
}
for (int i = 0; i < ret.length; ++i) {
ret[i] += i * (i - 1) / 2;
}
return ret;
}
}
Node build(int l, int r, int level, String[] ar) {
Node ret = new Node();
ret.count = r - l;
while (l < r && ar[l].length() == level) {
++l;
}
while (l < r) {
int t = l;
while (t < r && ar[t].charAt(level) == ar[l].charAt(level)) {
++t;
}
ret.nodes.add(build(l, t, level + 1, ar));
l = t;
}
return ret;
}
public void solve() throws IOException {
int n = nextInt();
k = nextInt();
String[] strs = new String[n];
for (int i = 0; i < n; ++i) {
strs[i] = next();
}
Arrays.sort(strs);
Node root = build(0, n, 0, strs);
// System.err.println(Arrays.toString(root.din()));
out.println(root.din()[k] - k * (k - 1) / 2);
}
public void run() throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
eat("");
solve();
out.close();
}
void eat(String s) {
st = new StringTokenizer(s);
}
String next() throws IOException {
while (!st.hasMoreTokens()) {
String line = in.readLine();
if (line == null) {
return null;
}
eat(line);
}
return st.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
double nextDouble() throws IOException {
return Double.parseDouble(next());
}
static boolean failed = false;
public static void main(String[] args) throws IOException {
Locale.setDefault(Locale.US);
new Solution().run();
}
} | Java | ["3 2\naba\nbzd\nabq", "4 3\neee\nrrr\nttt\nqqq", "4 3\naaa\nabba\nabbc\nabbd"] | 2 seconds | ["2", "0", "9"] | null | Java 6 | standard input | [
"dp",
"sortings",
"strings"
] | 637ba13f9d567f5bac92853e3ee1824c | The first input line contains two integers n and k (1ββ€βkββ€βn), separated by a single space. The following n lines contain the descriptions of proteins, one per line. Each protein is a non-empty string of no more than 500 characters consisting of only lowercase Latin letters (a...z). Some of the strings may be equal. The input limitations for getting 20 points are: 1ββ€βnββ€β20 The input limitations for getting 50 points are: 1ββ€βnββ€β100 The input limitations for getting 100 points are: 1ββ€βnββ€β2000 | 2,200 | Print a single number denoting the largest possible value of representativity that a subcollection of size k of the given collection of proteins can have. | standard output | |
PASSED | dbc13bb0f7f369008915116009d93379 | train_003.jsonl | 1335614400 | The Smart Beaver from ABBYY has a long history of cooperating with the "Institute of Cytology and Genetics". Recently, the Institute staff challenged the Beaver with a new problem. The problem is as follows.There is a collection of n proteins (not necessarily distinct). Each protein is a string consisting of lowercase Latin letters. The problem that the scientists offered to the Beaver is to select a subcollection of size k from the initial collection of proteins so that the representativity of the selected subset of proteins is maximum possible.The Smart Beaver from ABBYY did some research and came to the conclusion that the representativity of a collection of proteins can be evaluated by a single number, which is simply calculated. Let's suppose we have a collection {a1,β...,βak} consisting of k strings describing proteins. The representativity of this collection is the following value: where f(x,βy) is the length of the longest common prefix of strings x and y; for example, f("abc", "abd")β=β2, and f("ab", "bcd")β=β0.Thus, the representativity of collection of proteins {"abc", "abd", "abe"} equals 6, and the representativity of collection {"aaa", "ba", "ba"} equals 2.Having discovered that, the Smart Beaver from ABBYY asked the Cup contestants to write a program that selects, from the given collection of proteins, a subcollection of size k which has the largest possible value of representativity. Help him to solve this problem! | 256 megabytes | import java.io.*;
import java.util.*;
public class F {
final String filename = new String("F").toLowerCase();
final int MAX = 100 * 500 + 1;
final int ALPHA = 26;
int[][] next = new int[MAX][ALPHA];
int[] depth = new int[MAX];
int[] count = new int[MAX];
int countV ;
void init() {
countV = 1;
for (int[] i : next) {
Arrays.fill(i, -1);
}
Arrays.fill(count, 0);
Arrays.fill(depth, 0);
}
void add(String s) {
int curV = 0;
count[0]++;
for (int i = 0; i < s.length(); i++) {
int c = (int) (s.charAt(i) - 'a');
if (next[curV][c] == -1) {
next[curV][c] = countV;
depth[countV] = depth[curV] + 1;
countV++;
}
curV = next[curV][c];
count[curV]++;
}
}
int k;
int[] get(int v) {
int[] res = new int[k + 1];
for (int i = 0; i < ALPHA; i++) {
if (next[v][i] != -1) {
int[] b = get(next[v][i]);
int[] newRes = new int[k + 1];
for (int j = 0; j <= k && j <= count[v]; j++) {
for (int t = 0; t <= j && t <= count[next[v][i]]; t++) {
newRes[j] = Math.max(newRes[j], res[j - t] + b[t] + t * (t - 1) / 2);
}
}
res = newRes;
}
}
return res;
}
int solve(int n, int k, String[] s) throws Exception {
this.k = k;
init();
Arrays.sort(s);
for (String t : s) {
add(t);
}
return get(0)[k];
}
int lcp(String a, String b) {
int l = 0;
while (l < a.length() && l < b.length() && a.charAt(l) == b.charAt(l)) {
l++;
}
return l;
}
int solveStupid(int n, int k, String[] s) throws Exception {
Arrays.sort(s);
int best = 0;
int[] a = new int[k];
int[][] lcp = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
lcp[i][j] = lcp(s[i], s[j]);
}
}
for (int mask = 0; mask < 1 << n; mask++) {
if (Integer.bitCount(mask) != k) {
continue;
}
int temp = 0;
int cur = 0;
for (int i = 0; i < n; i++) {
if ((mask & (1 << i)) != 0) {
a[temp++] = i;
for (int j = 0; j < temp - 1; j++) {
cur += lcp[a[j]][i];
}
}
}
best = Math.max(best, cur);
}
return best;
}
void run() {
try {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
// in = new BufferedReader(new FileReader("input.txt"));
// out = new PrintWriter("output.txt");
// int n = 10;
// int len = 6;
// String[] s = new String[n];
// Random rnd = new Random(123);
// for (int IT = 0; IT < 100; IT++) {
// int k = rnd.nextInt(n) + 1;
// for (int i = 0; i < n; i++) {
// char[] c = new char[len];
// for (int j = 0; j < len; j++) {
// c[j] = (char) (rnd.nextInt(4) + 'a');
// }
// s[i] = new String(c);
// }
// int ans2 = solve(n, k, s);
// int ans1 = solveStupid(n, k, s);
// if (ans1 != ans2) {
// System.err.println(n + " " + k);
// System.err.println(ans1 + " " + ans2);
// System.err.println(Arrays.toString(s));
// }
// }
int n= nextInt();
int k = nextInt();
String[] s = new String[n];
for (int i = 0; i < s.length; i++) {
s[i] = nextToken();
}
out.println(solve(n, k, s));
out.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
BufferedReader in;
StringTokenizer st;
PrintWriter out;
String nextToken() throws Exception {
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(in.readLine());
return st.nextToken();
}
int nextInt() throws Exception {
return Integer.parseInt(nextToken());
}
long nextLong() throws Exception {
return Long.parseLong(nextToken());
}
double nextDouble() throws Exception {
return Double.parseDouble(nextToken());
}
public static void main(String[] args) {
new F().run();
}
}
| Java | ["3 2\naba\nbzd\nabq", "4 3\neee\nrrr\nttt\nqqq", "4 3\naaa\nabba\nabbc\nabbd"] | 2 seconds | ["2", "0", "9"] | null | Java 6 | standard input | [
"dp",
"sortings",
"strings"
] | 637ba13f9d567f5bac92853e3ee1824c | The first input line contains two integers n and k (1ββ€βkββ€βn), separated by a single space. The following n lines contain the descriptions of proteins, one per line. Each protein is a non-empty string of no more than 500 characters consisting of only lowercase Latin letters (a...z). Some of the strings may be equal. The input limitations for getting 20 points are: 1ββ€βnββ€β20 The input limitations for getting 50 points are: 1ββ€βnββ€β100 The input limitations for getting 100 points are: 1ββ€βnββ€β2000 | 2,200 | Print a single number denoting the largest possible value of representativity that a subcollection of size k of the given collection of proteins can have. | standard output | |
PASSED | 3e2efa7172caea46b4b1c7a5e21f8e22 | train_003.jsonl | 1335614400 | The Smart Beaver from ABBYY has a long history of cooperating with the "Institute of Cytology and Genetics". Recently, the Institute staff challenged the Beaver with a new problem. The problem is as follows.There is a collection of n proteins (not necessarily distinct). Each protein is a string consisting of lowercase Latin letters. The problem that the scientists offered to the Beaver is to select a subcollection of size k from the initial collection of proteins so that the representativity of the selected subset of proteins is maximum possible.The Smart Beaver from ABBYY did some research and came to the conclusion that the representativity of a collection of proteins can be evaluated by a single number, which is simply calculated. Let's suppose we have a collection {a1,β...,βak} consisting of k strings describing proteins. The representativity of this collection is the following value: where f(x,βy) is the length of the longest common prefix of strings x and y; for example, f("abc", "abd")β=β2, and f("ab", "bcd")β=β0.Thus, the representativity of collection of proteins {"abc", "abd", "abe"} equals 6, and the representativity of collection {"aaa", "ba", "ba"} equals 2.Having discovered that, the Smart Beaver from ABBYY asked the Cup contestants to write a program that selects, from the given collection of proteins, a subcollection of size k which has the largest possible value of representativity. Help him to solve this problem! | 256 megabytes | //package abbyy2.hard;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
public class FM2 {
InputStream is;
PrintWriter out;
// String INPUT = "17 8 ab baa aaba aaaab a bbbba abb b b aa baa ab aaaab abb aa bba ba";
String INPUT = "";
void solve()
{
int n = ni(), m = ni();
String[] ss = new String[n];
for(int i = 0;i < n;i++){
ss[i] = new String(ns(501));
}
Arrays.sort(ss);
int[] f = new int[n-1];
for(int i = 0;i < n-1;i++){
int k = 0;
for(;k < ss[i].length() && k < ss[i+1].length() && ss[i].charAt(k) == ss[i+1].charAt(k);k++);
f[i] = k;
}
out.println(rec(0, n-1, m, f, 0)[m]);
}
long[] rec(int s, int e, int m, int[] f, int p)
{
if(s == e){
long[] ret = new long[m+1];
Arrays.fill(ret, -999999999999999L);
ret[0] = 0; ret[1] = 0;
return ret;
}else{
int prev = s;
long[] ret = null;
for(int i = s;i <= e;i++){
if(i == e || f[i] <= p){
long[] res = rec(prev, i, m, f, p+1);
if(ret == null){
ret = res;
}else{
long[] nret = new long[m+1];
Arrays.fill(nret, -999999999999999L);
for(int j = 0;j <= m;j++){
for(int k = 0;j+k <= m;k++){
nret[j+k] = Math.max(nret[j+k], ret[j] + res[k]);
}
}
ret = nret;
}
prev = i+1;
}
}
if(p > 0){
for(int i = 0;i <= m;i++){
ret[i] += i*(i-1)/2;
}
}
return ret;
}
}
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 FM2().run();
}
public int ni()
{
try {
int num = 0;
boolean minus = false;
while((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));
if(num == '-'){
num = 0;
minus = true;
}else{
num -= '0';
}
while(true){
int b = is.read();
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
}
} catch (IOException e) {
}
return -1;
}
public long nl()
{
try {
long num = 0;
boolean minus = false;
while((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));
if(num == '-'){
num = 0;
minus = true;
}else{
num -= '0';
}
while(true){
int b = is.read();
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
}
} catch (IOException e) {
}
return -1;
}
public String ns()
{
try{
int b = 0;
StringBuilder sb = new StringBuilder();
while((b = is.read()) != -1 && (b == '\r' || b == '\n' || b == ' '));
if(b == -1)return "";
sb.append((char)b);
while(true){
b = is.read();
if(b == -1)return sb.toString();
if(b == '\r' || b == '\n' || b == ' ')return sb.toString();
sb.append((char)b);
}
} catch (IOException e) {
}
return "";
}
public char[] ns(int n)
{
char[] buf = new char[n];
try{
int b = 0, p = 0;
while((b = is.read()) != -1 && (b == ' ' || b == '\r' || b == '\n'));
if(b == -1)return null;
buf[p++] = (char)b;
while(p < n){
b = is.read();
if(b == -1 || b == ' ' || b == '\r' || b == '\n')break;
buf[p++] = (char)b;
}
return Arrays.copyOf(buf, p);
} catch (IOException e) {
}
return null;
}
double nd() { return Double.parseDouble(ns()); }
boolean oj = System.getProperty("ONLINE_JUDGE") != null;
void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}
| Java | ["3 2\naba\nbzd\nabq", "4 3\neee\nrrr\nttt\nqqq", "4 3\naaa\nabba\nabbc\nabbd"] | 2 seconds | ["2", "0", "9"] | null | Java 6 | standard input | [
"dp",
"sortings",
"strings"
] | 637ba13f9d567f5bac92853e3ee1824c | The first input line contains two integers n and k (1ββ€βkββ€βn), separated by a single space. The following n lines contain the descriptions of proteins, one per line. Each protein is a non-empty string of no more than 500 characters consisting of only lowercase Latin letters (a...z). Some of the strings may be equal. The input limitations for getting 20 points are: 1ββ€βnββ€β20 The input limitations for getting 50 points are: 1ββ€βnββ€β100 The input limitations for getting 100 points are: 1ββ€βnββ€β2000 | 2,200 | Print a single number denoting the largest possible value of representativity that a subcollection of size k of the given collection of proteins can have. | standard output | |
PASSED | 52d9fb2b412c5458759b30a27002924e | train_003.jsonl | 1593095700 | There are two rival donut shops.The first shop sells donuts at retail: each donut costs $$$a$$$ dollars.The second shop sells donuts only in bulk: box of $$$b$$$ donuts costs $$$c$$$ dollars. So if you want to buy $$$x$$$ donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to $$$x$$$.You want to determine two positive integer values: how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop? how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop? If any of these values doesn't exist then that value should be equal to $$$-1$$$. If there are multiple possible answers, then print any of them.The printed values should be less or equal to $$$10^9$$$. It can be shown that under the given constraints such values always exist if any values exist at all. | 256 megabytes | import java.util.*;
public class J {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
long t=sc.nextInt(),a,b,k,c;//a,b,m,x,u;//,x=0,n,j,v=2,g,m;
long y;
for(int r=0;r<t;r++)
{
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
if(a>c)
{
System.out.print(-1+" ");
System.out.println(1);
}
else
if(a==c)
{
System.out.print(-1+" ");
System.out.println(2);
}
else
{
y=b*a;
if(y>c)
{
System.out.print(1+" ");System.out.println(b);
}
else{System.out.print(1+" ");System.out.println(-1);}
}
// System.out.print(res);
}
}} | Java | ["4\n5 10 4\n4 5 20\n2 2 3\n1000000000 1000000000 1000000000"] | 2 seconds | ["-1 20\n8 -1\n1 2\n-1 1000000000"] | NoteIn the first testcase buying any number of donuts will be cheaper in the second shop. For example, for $$$3$$$ or $$$5$$$ donuts you'll have to buy a box of $$$10$$$ donuts for $$$4$$$ dollars. $$$3$$$ or $$$5$$$ donuts in the first shop would cost you $$$15$$$ or $$$25$$$ dollars, respectively, however. For $$$20$$$ donuts you'll have to buy two boxes for $$$8$$$ dollars total. Note that $$$3$$$ and $$$5$$$ are also valid answers for the second shop, along with many other answers.In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. $$$8$$$ donuts cost $$$32$$$ dollars in the first shop and $$$40$$$ dollars in the second shop (because you have to buy two boxes). $$$10$$$ donuts will cost $$$40$$$ dollars in both shops, so $$$10$$$ is not a valid answer for any of the shops.In the third testcase $$$1$$$ donut costs $$$2$$$ and $$$3$$$ dollars, respectively. $$$2$$$ donuts cost $$$4$$$ and $$$3$$$ dollars. Thus, $$$1$$$ is a valid answer for the first shop and $$$2$$$ is a valid answer for the second shop.In the fourth testcase $$$10^9$$$ donuts cost $$$10^{18}$$$ dollars in the first shop and $$$10^9$$$ dollars in the second shop. | Java 8 | standard input | [
"implementation",
"greedy",
"math"
] | 002801f26568a1b3524d8754207d32c1 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a \le 10^9$$$, $$$2 \le b \le 10^9$$$, $$$1 \le c \le 10^9$$$). | 1,000 | For each testcase print two positive integers. For both shops print such $$$x$$$ that buying $$$x$$$ donuts in this shop is strictly cheaper than buying $$$x$$$ donuts in the other shop. $$$x$$$ should be greater than $$$0$$$ and less or equal to $$$10^9$$$. If there is no such $$$x$$$, then print $$$-1$$$. If there are multiple answers, then print any of them. | standard output | |
PASSED | 82bc2c597fabf66335d9c0ab0efb2d0b | train_003.jsonl | 1593095700 | There are two rival donut shops.The first shop sells donuts at retail: each donut costs $$$a$$$ dollars.The second shop sells donuts only in bulk: box of $$$b$$$ donuts costs $$$c$$$ dollars. So if you want to buy $$$x$$$ donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to $$$x$$$.You want to determine two positive integer values: how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop? how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop? If any of these values doesn't exist then that value should be equal to $$$-1$$$. If there are multiple possible answers, then print any of them.The printed values should be less or equal to $$$10^9$$$. It can be shown that under the given constraints such values always exist if any values exist at all. | 256 megabytes | import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
int t=Integer.parseInt(br.readLine());
while(t-->0)
{
String[] s=br.readLine().split(" ");
int a=Integer.parseInt(s[0]);
int b=Integer.parseInt(s[1]);
int c=Integer.parseInt(s[2]);
if(a<c)
bw.write("1 ");
else
bw.write("-1 ");
long m=((long)a)*b;
if(m>(long)c)
bw.write(b+" ");
else
bw.write("-1 ");
bw.write("\n");
}
bw.flush();
}
} | Java | ["4\n5 10 4\n4 5 20\n2 2 3\n1000000000 1000000000 1000000000"] | 2 seconds | ["-1 20\n8 -1\n1 2\n-1 1000000000"] | NoteIn the first testcase buying any number of donuts will be cheaper in the second shop. For example, for $$$3$$$ or $$$5$$$ donuts you'll have to buy a box of $$$10$$$ donuts for $$$4$$$ dollars. $$$3$$$ or $$$5$$$ donuts in the first shop would cost you $$$15$$$ or $$$25$$$ dollars, respectively, however. For $$$20$$$ donuts you'll have to buy two boxes for $$$8$$$ dollars total. Note that $$$3$$$ and $$$5$$$ are also valid answers for the second shop, along with many other answers.In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. $$$8$$$ donuts cost $$$32$$$ dollars in the first shop and $$$40$$$ dollars in the second shop (because you have to buy two boxes). $$$10$$$ donuts will cost $$$40$$$ dollars in both shops, so $$$10$$$ is not a valid answer for any of the shops.In the third testcase $$$1$$$ donut costs $$$2$$$ and $$$3$$$ dollars, respectively. $$$2$$$ donuts cost $$$4$$$ and $$$3$$$ dollars. Thus, $$$1$$$ is a valid answer for the first shop and $$$2$$$ is a valid answer for the second shop.In the fourth testcase $$$10^9$$$ donuts cost $$$10^{18}$$$ dollars in the first shop and $$$10^9$$$ dollars in the second shop. | Java 8 | standard input | [
"implementation",
"greedy",
"math"
] | 002801f26568a1b3524d8754207d32c1 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a \le 10^9$$$, $$$2 \le b \le 10^9$$$, $$$1 \le c \le 10^9$$$). | 1,000 | For each testcase print two positive integers. For both shops print such $$$x$$$ that buying $$$x$$$ donuts in this shop is strictly cheaper than buying $$$x$$$ donuts in the other shop. $$$x$$$ should be greater than $$$0$$$ and less or equal to $$$10^9$$$. If there is no such $$$x$$$, then print $$$-1$$$. If there are multiple answers, then print any of them. | standard output | |
PASSED | 5aea3ad308e1e432c272efd9f3eb3716 | train_003.jsonl | 1593095700 | There are two rival donut shops.The first shop sells donuts at retail: each donut costs $$$a$$$ dollars.The second shop sells donuts only in bulk: box of $$$b$$$ donuts costs $$$c$$$ dollars. So if you want to buy $$$x$$$ donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to $$$x$$$.You want to determine two positive integer values: how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop? how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop? If any of these values doesn't exist then that value should be equal to $$$-1$$$. If there are multiple possible answers, then print any of them.The printed values should be less or equal to $$$10^9$$$. It can be shown that under the given constraints such values always exist if any values exist at all. | 256 megabytes | import java.util.*;
public class Helloworld
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt();
System.out.println((a >= c ? -1 : 1) + " " + ((long)a * b > c ? b : -1));
}
}
} | Java | ["4\n5 10 4\n4 5 20\n2 2 3\n1000000000 1000000000 1000000000"] | 2 seconds | ["-1 20\n8 -1\n1 2\n-1 1000000000"] | NoteIn the first testcase buying any number of donuts will be cheaper in the second shop. For example, for $$$3$$$ or $$$5$$$ donuts you'll have to buy a box of $$$10$$$ donuts for $$$4$$$ dollars. $$$3$$$ or $$$5$$$ donuts in the first shop would cost you $$$15$$$ or $$$25$$$ dollars, respectively, however. For $$$20$$$ donuts you'll have to buy two boxes for $$$8$$$ dollars total. Note that $$$3$$$ and $$$5$$$ are also valid answers for the second shop, along with many other answers.In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. $$$8$$$ donuts cost $$$32$$$ dollars in the first shop and $$$40$$$ dollars in the second shop (because you have to buy two boxes). $$$10$$$ donuts will cost $$$40$$$ dollars in both shops, so $$$10$$$ is not a valid answer for any of the shops.In the third testcase $$$1$$$ donut costs $$$2$$$ and $$$3$$$ dollars, respectively. $$$2$$$ donuts cost $$$4$$$ and $$$3$$$ dollars. Thus, $$$1$$$ is a valid answer for the first shop and $$$2$$$ is a valid answer for the second shop.In the fourth testcase $$$10^9$$$ donuts cost $$$10^{18}$$$ dollars in the first shop and $$$10^9$$$ dollars in the second shop. | Java 8 | standard input | [
"implementation",
"greedy",
"math"
] | 002801f26568a1b3524d8754207d32c1 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a \le 10^9$$$, $$$2 \le b \le 10^9$$$, $$$1 \le c \le 10^9$$$). | 1,000 | For each testcase print two positive integers. For both shops print such $$$x$$$ that buying $$$x$$$ donuts in this shop is strictly cheaper than buying $$$x$$$ donuts in the other shop. $$$x$$$ should be greater than $$$0$$$ and less or equal to $$$10^9$$$. If there is no such $$$x$$$, then print $$$-1$$$. If there are multiple answers, then print any of them. | standard output | |
PASSED | 7e24853f492865200a62be498b56bc08 | train_003.jsonl | 1593095700 | There are two rival donut shops.The first shop sells donuts at retail: each donut costs $$$a$$$ dollars.The second shop sells donuts only in bulk: box of $$$b$$$ donuts costs $$$c$$$ dollars. So if you want to buy $$$x$$$ donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to $$$x$$$.You want to determine two positive integer values: how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop? how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop? If any of these values doesn't exist then that value should be equal to $$$-1$$$. If there are multiple possible answers, then print any of them.The printed values should be less or equal to $$$10^9$$$. It can be shown that under the given constraints such values always exist if any values exist at all. | 256 megabytes | import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.util.*;
public class practicee{
public static void main(String args[]) {
Scanner s=new Scanner(System.in);
int t=s.nextInt();
while(t-->0) {
int a=s.nextInt();
int b=s.nextInt();
int c=s.nextInt();
if(a<c) {
System.out.print("1 ");
}else {
System.out.print("-1 ");
}
BigInteger d=BigInteger.valueOf(a).multiply(BigInteger.valueOf(b));
if(d.compareTo(BigInteger.valueOf(c))==1) {
System.out.print(b);
}else {
System.out.print("-1");
}
System.out.println();
}
}
} | Java | ["4\n5 10 4\n4 5 20\n2 2 3\n1000000000 1000000000 1000000000"] | 2 seconds | ["-1 20\n8 -1\n1 2\n-1 1000000000"] | NoteIn the first testcase buying any number of donuts will be cheaper in the second shop. For example, for $$$3$$$ or $$$5$$$ donuts you'll have to buy a box of $$$10$$$ donuts for $$$4$$$ dollars. $$$3$$$ or $$$5$$$ donuts in the first shop would cost you $$$15$$$ or $$$25$$$ dollars, respectively, however. For $$$20$$$ donuts you'll have to buy two boxes for $$$8$$$ dollars total. Note that $$$3$$$ and $$$5$$$ are also valid answers for the second shop, along with many other answers.In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. $$$8$$$ donuts cost $$$32$$$ dollars in the first shop and $$$40$$$ dollars in the second shop (because you have to buy two boxes). $$$10$$$ donuts will cost $$$40$$$ dollars in both shops, so $$$10$$$ is not a valid answer for any of the shops.In the third testcase $$$1$$$ donut costs $$$2$$$ and $$$3$$$ dollars, respectively. $$$2$$$ donuts cost $$$4$$$ and $$$3$$$ dollars. Thus, $$$1$$$ is a valid answer for the first shop and $$$2$$$ is a valid answer for the second shop.In the fourth testcase $$$10^9$$$ donuts cost $$$10^{18}$$$ dollars in the first shop and $$$10^9$$$ dollars in the second shop. | Java 8 | standard input | [
"implementation",
"greedy",
"math"
] | 002801f26568a1b3524d8754207d32c1 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a \le 10^9$$$, $$$2 \le b \le 10^9$$$, $$$1 \le c \le 10^9$$$). | 1,000 | For each testcase print two positive integers. For both shops print such $$$x$$$ that buying $$$x$$$ donuts in this shop is strictly cheaper than buying $$$x$$$ donuts in the other shop. $$$x$$$ should be greater than $$$0$$$ and less or equal to $$$10^9$$$. If there is no such $$$x$$$, then print $$$-1$$$. If there are multiple answers, then print any of them. | standard output | |
PASSED | bde9444cd00c40511cef899056033800 | train_003.jsonl | 1593095700 | There are two rival donut shops.The first shop sells donuts at retail: each donut costs $$$a$$$ dollars.The second shop sells donuts only in bulk: box of $$$b$$$ donuts costs $$$c$$$ dollars. So if you want to buy $$$x$$$ donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to $$$x$$$.You want to determine two positive integer values: how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop? how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop? If any of these values doesn't exist then that value should be equal to $$$-1$$$. If there are multiple possible answers, then print any of them.The printed values should be less or equal to $$$10^9$$$. It can be shown that under the given constraints such values always exist if any values exist at all. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class A_90 {
public static void main(String[] args) {
try {
FastScanner fs=new FastScanner();
int test=fs.nextInt();
while(test-->0)
{
long a=fs.nextLong();
long b=fs.nextLong();
long c=fs.nextLong();
long ans1=-1,ans2=-1;
if(a<c) ans1=1;
if(c<(b*a)) ans2=b;
System.out.println(ans1+" "+ans2);
}
}
catch(Exception e)
{return;}
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
public String next() {
while (!st.hasMoreElements())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) {
a[i]=nextInt();
}
return a;
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
} | Java | ["4\n5 10 4\n4 5 20\n2 2 3\n1000000000 1000000000 1000000000"] | 2 seconds | ["-1 20\n8 -1\n1 2\n-1 1000000000"] | NoteIn the first testcase buying any number of donuts will be cheaper in the second shop. For example, for $$$3$$$ or $$$5$$$ donuts you'll have to buy a box of $$$10$$$ donuts for $$$4$$$ dollars. $$$3$$$ or $$$5$$$ donuts in the first shop would cost you $$$15$$$ or $$$25$$$ dollars, respectively, however. For $$$20$$$ donuts you'll have to buy two boxes for $$$8$$$ dollars total. Note that $$$3$$$ and $$$5$$$ are also valid answers for the second shop, along with many other answers.In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. $$$8$$$ donuts cost $$$32$$$ dollars in the first shop and $$$40$$$ dollars in the second shop (because you have to buy two boxes). $$$10$$$ donuts will cost $$$40$$$ dollars in both shops, so $$$10$$$ is not a valid answer for any of the shops.In the third testcase $$$1$$$ donut costs $$$2$$$ and $$$3$$$ dollars, respectively. $$$2$$$ donuts cost $$$4$$$ and $$$3$$$ dollars. Thus, $$$1$$$ is a valid answer for the first shop and $$$2$$$ is a valid answer for the second shop.In the fourth testcase $$$10^9$$$ donuts cost $$$10^{18}$$$ dollars in the first shop and $$$10^9$$$ dollars in the second shop. | Java 8 | standard input | [
"implementation",
"greedy",
"math"
] | 002801f26568a1b3524d8754207d32c1 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a \le 10^9$$$, $$$2 \le b \le 10^9$$$, $$$1 \le c \le 10^9$$$). | 1,000 | For each testcase print two positive integers. For both shops print such $$$x$$$ that buying $$$x$$$ donuts in this shop is strictly cheaper than buying $$$x$$$ donuts in the other shop. $$$x$$$ should be greater than $$$0$$$ and less or equal to $$$10^9$$$. If there is no such $$$x$$$, then print $$$-1$$$. If there are multiple answers, then print any of them. | standard output | |
PASSED | 1fc9fb8558a591d204fa48b04ede507f | train_003.jsonl | 1593095700 | There are two rival donut shops.The first shop sells donuts at retail: each donut costs $$$a$$$ dollars.The second shop sells donuts only in bulk: box of $$$b$$$ donuts costs $$$c$$$ dollars. So if you want to buy $$$x$$$ donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to $$$x$$$.You want to determine two positive integer values: how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop? how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop? If any of these values doesn't exist then that value should be equal to $$$-1$$$. If there are multiple possible answers, then print any of them.The printed values should be less or equal to $$$10^9$$$. It can be shown that under the given constraints such values always exist if any values exist at all. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class A {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st;
static PrintWriter out = new PrintWriter(System.out);
static void solve() throws Exception {
int tests = nextInt();
for (int t = 0; t < tests; t++) {
long a = nextLong(), b = nextLong(), c = nextLong();
long r1;
if (a < c) {
r1 = 1;
} else {
r1 = -1;
}
long r2;
if (c < a * b) {
r2 = b;
} else {
r2 = -1;
}
out.println(r1 + " " + r2);
}
}
public static void main(String[] args) throws Exception {
solve();
out.close();
}
static String next() throws Exception {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
static int nextInt() throws Exception {
return Integer.parseInt(next());
}
static long nextLong() throws Exception {
return Long.parseLong(next());
}
}
| Java | ["4\n5 10 4\n4 5 20\n2 2 3\n1000000000 1000000000 1000000000"] | 2 seconds | ["-1 20\n8 -1\n1 2\n-1 1000000000"] | NoteIn the first testcase buying any number of donuts will be cheaper in the second shop. For example, for $$$3$$$ or $$$5$$$ donuts you'll have to buy a box of $$$10$$$ donuts for $$$4$$$ dollars. $$$3$$$ or $$$5$$$ donuts in the first shop would cost you $$$15$$$ or $$$25$$$ dollars, respectively, however. For $$$20$$$ donuts you'll have to buy two boxes for $$$8$$$ dollars total. Note that $$$3$$$ and $$$5$$$ are also valid answers for the second shop, along with many other answers.In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. $$$8$$$ donuts cost $$$32$$$ dollars in the first shop and $$$40$$$ dollars in the second shop (because you have to buy two boxes). $$$10$$$ donuts will cost $$$40$$$ dollars in both shops, so $$$10$$$ is not a valid answer for any of the shops.In the third testcase $$$1$$$ donut costs $$$2$$$ and $$$3$$$ dollars, respectively. $$$2$$$ donuts cost $$$4$$$ and $$$3$$$ dollars. Thus, $$$1$$$ is a valid answer for the first shop and $$$2$$$ is a valid answer for the second shop.In the fourth testcase $$$10^9$$$ donuts cost $$$10^{18}$$$ dollars in the first shop and $$$10^9$$$ dollars in the second shop. | Java 8 | standard input | [
"implementation",
"greedy",
"math"
] | 002801f26568a1b3524d8754207d32c1 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a \le 10^9$$$, $$$2 \le b \le 10^9$$$, $$$1 \le c \le 10^9$$$). | 1,000 | For each testcase print two positive integers. For both shops print such $$$x$$$ that buying $$$x$$$ donuts in this shop is strictly cheaper than buying $$$x$$$ donuts in the other shop. $$$x$$$ should be greater than $$$0$$$ and less or equal to $$$10^9$$$. If there is no such $$$x$$$, then print $$$-1$$$. If there are multiple answers, then print any of them. | standard output | |
PASSED | b408c3403caa1d975fe01ac3a796b4cc | train_003.jsonl | 1593095700 | There are two rival donut shops.The first shop sells donuts at retail: each donut costs $$$a$$$ dollars.The second shop sells donuts only in bulk: box of $$$b$$$ donuts costs $$$c$$$ dollars. So if you want to buy $$$x$$$ donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to $$$x$$$.You want to determine two positive integer values: how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop? how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop? If any of these values doesn't exist then that value should be equal to $$$-1$$$. If there are multiple possible answers, then print any of them.The printed values should be less or equal to $$$10^9$$$. It can be shown that under the given constraints such values always exist if any values exist at all. | 256 megabytes | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class A {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st;
static PrintWriter out = new PrintWriter(System.out);
static void solve() throws Exception {
int tests = nextInt();
for (int t = 0; t < tests; t++) {
long a = nextLong(), b = nextLong(), c = nextLong();
long r1;
if (a < c) {
r1 = 1;
} else {
r1 = -1;
}
long r2;
if (c < a * b) {
r2 = b;
// } else if (c < (b - 1) * a) {
// r2 = b - 1;
} else {
r2 = -1;
}
out.println(r1 + " " + r2);
}
}
public static void main(String[] args) throws Exception {
solve();
out.close();
}
static String next() throws Exception {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
static int nextInt() throws Exception {
return Integer.parseInt(next());
}
static long nextLong() throws Exception {
return Long.parseLong(next());
}
}
| Java | ["4\n5 10 4\n4 5 20\n2 2 3\n1000000000 1000000000 1000000000"] | 2 seconds | ["-1 20\n8 -1\n1 2\n-1 1000000000"] | NoteIn the first testcase buying any number of donuts will be cheaper in the second shop. For example, for $$$3$$$ or $$$5$$$ donuts you'll have to buy a box of $$$10$$$ donuts for $$$4$$$ dollars. $$$3$$$ or $$$5$$$ donuts in the first shop would cost you $$$15$$$ or $$$25$$$ dollars, respectively, however. For $$$20$$$ donuts you'll have to buy two boxes for $$$8$$$ dollars total. Note that $$$3$$$ and $$$5$$$ are also valid answers for the second shop, along with many other answers.In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. $$$8$$$ donuts cost $$$32$$$ dollars in the first shop and $$$40$$$ dollars in the second shop (because you have to buy two boxes). $$$10$$$ donuts will cost $$$40$$$ dollars in both shops, so $$$10$$$ is not a valid answer for any of the shops.In the third testcase $$$1$$$ donut costs $$$2$$$ and $$$3$$$ dollars, respectively. $$$2$$$ donuts cost $$$4$$$ and $$$3$$$ dollars. Thus, $$$1$$$ is a valid answer for the first shop and $$$2$$$ is a valid answer for the second shop.In the fourth testcase $$$10^9$$$ donuts cost $$$10^{18}$$$ dollars in the first shop and $$$10^9$$$ dollars in the second shop. | Java 8 | standard input | [
"implementation",
"greedy",
"math"
] | 002801f26568a1b3524d8754207d32c1 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a \le 10^9$$$, $$$2 \le b \le 10^9$$$, $$$1 \le c \le 10^9$$$). | 1,000 | For each testcase print two positive integers. For both shops print such $$$x$$$ that buying $$$x$$$ donuts in this shop is strictly cheaper than buying $$$x$$$ donuts in the other shop. $$$x$$$ should be greater than $$$0$$$ and less or equal to $$$10^9$$$. If there is no such $$$x$$$, then print $$$-1$$$. If there are multiple answers, then print any of them. | standard output | |
PASSED | 80b12feb2ccd278d5ec4dde50c5a6abb | train_003.jsonl | 1593095700 | There are two rival donut shops.The first shop sells donuts at retail: each donut costs $$$a$$$ dollars.The second shop sells donuts only in bulk: box of $$$b$$$ donuts costs $$$c$$$ dollars. So if you want to buy $$$x$$$ donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to $$$x$$$.You want to determine two positive integer values: how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop? how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop? If any of these values doesn't exist then that value should be equal to $$$-1$$$. If there are multiple possible answers, then print any of them.The printed values should be less or equal to $$$10^9$$$. It can be shown that under the given constraints such values always exist if any values exist at all. | 256 megabytes |
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class A {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st;
static PrintWriter out = new PrintWriter(System.out);
static void solve() throws Exception {
int tests = nextInt();
for (int t = 0; t < tests; t++) {
long a = nextLong(), b = nextLong(), c = nextLong();
long r1;
if (a < c) {
r1 = 1;
// } else if (a == c) {
// if (b - a > 1) {
// r1 = a + 1;
// } else {
// r1 = -1;
// }
} else {
r1 = -1;
}
long r2;
if (c < a * b) {
r2 = b;
} else if (c < (b - 1) * a) {
r2 = b - 1;
} else {
r2 = -1;
}
out.println(r1 + " " + r2);
}
}
public static void main(String[] args) throws Exception {
solve();
out.close();
}
static String next() throws Exception {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
static int nextInt() throws Exception {
return Integer.parseInt(next());
}
static long nextLong() throws Exception {
return Long.parseLong(next());
}
}
| Java | ["4\n5 10 4\n4 5 20\n2 2 3\n1000000000 1000000000 1000000000"] | 2 seconds | ["-1 20\n8 -1\n1 2\n-1 1000000000"] | NoteIn the first testcase buying any number of donuts will be cheaper in the second shop. For example, for $$$3$$$ or $$$5$$$ donuts you'll have to buy a box of $$$10$$$ donuts for $$$4$$$ dollars. $$$3$$$ or $$$5$$$ donuts in the first shop would cost you $$$15$$$ or $$$25$$$ dollars, respectively, however. For $$$20$$$ donuts you'll have to buy two boxes for $$$8$$$ dollars total. Note that $$$3$$$ and $$$5$$$ are also valid answers for the second shop, along with many other answers.In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. $$$8$$$ donuts cost $$$32$$$ dollars in the first shop and $$$40$$$ dollars in the second shop (because you have to buy two boxes). $$$10$$$ donuts will cost $$$40$$$ dollars in both shops, so $$$10$$$ is not a valid answer for any of the shops.In the third testcase $$$1$$$ donut costs $$$2$$$ and $$$3$$$ dollars, respectively. $$$2$$$ donuts cost $$$4$$$ and $$$3$$$ dollars. Thus, $$$1$$$ is a valid answer for the first shop and $$$2$$$ is a valid answer for the second shop.In the fourth testcase $$$10^9$$$ donuts cost $$$10^{18}$$$ dollars in the first shop and $$$10^9$$$ dollars in the second shop. | Java 8 | standard input | [
"implementation",
"greedy",
"math"
] | 002801f26568a1b3524d8754207d32c1 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a \le 10^9$$$, $$$2 \le b \le 10^9$$$, $$$1 \le c \le 10^9$$$). | 1,000 | For each testcase print two positive integers. For both shops print such $$$x$$$ that buying $$$x$$$ donuts in this shop is strictly cheaper than buying $$$x$$$ donuts in the other shop. $$$x$$$ should be greater than $$$0$$$ and less or equal to $$$10^9$$$. If there is no such $$$x$$$, then print $$$-1$$$. If there are multiple answers, then print any of them. | standard output | |
PASSED | e62560a9aac2ab511ae5d98c039014b3 | train_003.jsonl | 1593095700 | There are two rival donut shops.The first shop sells donuts at retail: each donut costs $$$a$$$ dollars.The second shop sells donuts only in bulk: box of $$$b$$$ donuts costs $$$c$$$ dollars. So if you want to buy $$$x$$$ donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to $$$x$$$.You want to determine two positive integer values: how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop? how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop? If any of these values doesn't exist then that value should be equal to $$$-1$$$. If there are multiple possible answers, then print any of them.The printed values should be less or equal to $$$10^9$$$. It can be shown that under the given constraints such values always exist if any values exist at all. | 256 megabytes | import java.util.*;
public class dougnuts {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int k=0;k<t;k++)
{
int count=0,r=0;
long a=sc.nextLong();
long b=sc.nextLong();
long c=sc.nextLong();
long c1=0;
long b1=b;
if(a<c)
System.out.print("1 ");
else
System.out.print("-1 ");
if(c<b*a)
System.out.println(b);
else
System.out.println("-1");
}
System.out.println("");}
}
| Java | ["4\n5 10 4\n4 5 20\n2 2 3\n1000000000 1000000000 1000000000"] | 2 seconds | ["-1 20\n8 -1\n1 2\n-1 1000000000"] | NoteIn the first testcase buying any number of donuts will be cheaper in the second shop. For example, for $$$3$$$ or $$$5$$$ donuts you'll have to buy a box of $$$10$$$ donuts for $$$4$$$ dollars. $$$3$$$ or $$$5$$$ donuts in the first shop would cost you $$$15$$$ or $$$25$$$ dollars, respectively, however. For $$$20$$$ donuts you'll have to buy two boxes for $$$8$$$ dollars total. Note that $$$3$$$ and $$$5$$$ are also valid answers for the second shop, along with many other answers.In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. $$$8$$$ donuts cost $$$32$$$ dollars in the first shop and $$$40$$$ dollars in the second shop (because you have to buy two boxes). $$$10$$$ donuts will cost $$$40$$$ dollars in both shops, so $$$10$$$ is not a valid answer for any of the shops.In the third testcase $$$1$$$ donut costs $$$2$$$ and $$$3$$$ dollars, respectively. $$$2$$$ donuts cost $$$4$$$ and $$$3$$$ dollars. Thus, $$$1$$$ is a valid answer for the first shop and $$$2$$$ is a valid answer for the second shop.In the fourth testcase $$$10^9$$$ donuts cost $$$10^{18}$$$ dollars in the first shop and $$$10^9$$$ dollars in the second shop. | Java 8 | standard input | [
"implementation",
"greedy",
"math"
] | 002801f26568a1b3524d8754207d32c1 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a \le 10^9$$$, $$$2 \le b \le 10^9$$$, $$$1 \le c \le 10^9$$$). | 1,000 | For each testcase print two positive integers. For both shops print such $$$x$$$ that buying $$$x$$$ donuts in this shop is strictly cheaper than buying $$$x$$$ donuts in the other shop. $$$x$$$ should be greater than $$$0$$$ and less or equal to $$$10^9$$$. If there is no such $$$x$$$, then print $$$-1$$$. If there are multiple answers, then print any of them. | standard output | |
PASSED | 61467cc6a9b3feb01c2e9d7063d3cd3b | train_003.jsonl | 1593095700 | There are two rival donut shops.The first shop sells donuts at retail: each donut costs $$$a$$$ dollars.The second shop sells donuts only in bulk: box of $$$b$$$ donuts costs $$$c$$$ dollars. So if you want to buy $$$x$$$ donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to $$$x$$$.You want to determine two positive integer values: how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop? how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop? If any of these values doesn't exist then that value should be equal to $$$-1$$$. If there are multiple possible answers, then print any of them.The printed values should be less or equal to $$$10^9$$$. It can be shown that under the given constraints such values always exist if any values exist at all. | 256 megabytes | // package com.company;
import java.util.*;
import java.lang.*;
import java.io.*;
//****Use Integer Wrapper Class for Arrays.sort()****
public class DP1 {
static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
public static void main(String[] Args)throws Exception{
FastReader scan=new FastReader(System.in);
int t=1;
t=scan.nextInt();
while(t-->0){
long a=scan.nextInt();
long b=scan.nextInt();
long c=scan.nextInt();
if(a*b<c){
out.println(1+" -1");
}else if(a*b==c){
out.println((b-1)+" -1");
}else{
if(a<c){
out.print(1);
}else{
out.print(-1);
}
out.println(" "+b);
}
}
out.flush();
out.close();
}
static class FastReader {
byte[] buf = new byte[2048];
int index, total;
InputStream in;
FastReader(InputStream is) {
in = is;
}
int scan() throws IOException {
if (index >= total) {
index = 0;
total = in.read(buf);
if (total <= 0) {
return -1;
}
}
return buf[index++];
}
String next() throws IOException {
int c;
for (c = scan(); c <= 32; c = scan()) ;
StringBuilder sb = new StringBuilder();
for (; c > 32; c = scan()) {
sb.append((char) c);
}
return sb.toString();
}
int nextInt() throws IOException {
int c, val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}
long nextLong() throws IOException {
int c;
long val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}
}
}
| Java | ["4\n5 10 4\n4 5 20\n2 2 3\n1000000000 1000000000 1000000000"] | 2 seconds | ["-1 20\n8 -1\n1 2\n-1 1000000000"] | NoteIn the first testcase buying any number of donuts will be cheaper in the second shop. For example, for $$$3$$$ or $$$5$$$ donuts you'll have to buy a box of $$$10$$$ donuts for $$$4$$$ dollars. $$$3$$$ or $$$5$$$ donuts in the first shop would cost you $$$15$$$ or $$$25$$$ dollars, respectively, however. For $$$20$$$ donuts you'll have to buy two boxes for $$$8$$$ dollars total. Note that $$$3$$$ and $$$5$$$ are also valid answers for the second shop, along with many other answers.In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. $$$8$$$ donuts cost $$$32$$$ dollars in the first shop and $$$40$$$ dollars in the second shop (because you have to buy two boxes). $$$10$$$ donuts will cost $$$40$$$ dollars in both shops, so $$$10$$$ is not a valid answer for any of the shops.In the third testcase $$$1$$$ donut costs $$$2$$$ and $$$3$$$ dollars, respectively. $$$2$$$ donuts cost $$$4$$$ and $$$3$$$ dollars. Thus, $$$1$$$ is a valid answer for the first shop and $$$2$$$ is a valid answer for the second shop.In the fourth testcase $$$10^9$$$ donuts cost $$$10^{18}$$$ dollars in the first shop and $$$10^9$$$ dollars in the second shop. | Java 8 | standard input | [
"implementation",
"greedy",
"math"
] | 002801f26568a1b3524d8754207d32c1 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a \le 10^9$$$, $$$2 \le b \le 10^9$$$, $$$1 \le c \le 10^9$$$). | 1,000 | For each testcase print two positive integers. For both shops print such $$$x$$$ that buying $$$x$$$ donuts in this shop is strictly cheaper than buying $$$x$$$ donuts in the other shop. $$$x$$$ should be greater than $$$0$$$ and less or equal to $$$10^9$$$. If there is no such $$$x$$$, then print $$$-1$$$. If there are multiple answers, then print any of them. | standard output | |
PASSED | 9abc01afadb73c6021122517d5029f41 | train_003.jsonl | 1593095700 | There are two rival donut shops.The first shop sells donuts at retail: each donut costs $$$a$$$ dollars.The second shop sells donuts only in bulk: box of $$$b$$$ donuts costs $$$c$$$ dollars. So if you want to buy $$$x$$$ donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to $$$x$$$.You want to determine two positive integer values: how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop? how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop? If any of these values doesn't exist then that value should be equal to $$$-1$$$. If there are multiple possible answers, then print any of them.The printed values should be less or equal to $$$10^9$$$. It can be shown that under the given constraints such values always exist if any values exist at all. | 256 megabytes | import java.util.*;
// System.out.println();
public class Main{
public static void main(String [] args) {
Scanner sc= new Scanner(System.in);
int t = sc.nextInt();
while(t>0){
long a = sc.nextLong();
long b = sc.nextLong();
long c = sc.nextLong();
if(a>=c)
System.out.print(-1+" ");
else
System.out.print(1+" ");
if(b*a > c)
System.out.print(b);
else
System.out.print(-1);
System.out.println("");
t--;
}
sc.close();
}
} | Java | ["4\n5 10 4\n4 5 20\n2 2 3\n1000000000 1000000000 1000000000"] | 2 seconds | ["-1 20\n8 -1\n1 2\n-1 1000000000"] | NoteIn the first testcase buying any number of donuts will be cheaper in the second shop. For example, for $$$3$$$ or $$$5$$$ donuts you'll have to buy a box of $$$10$$$ donuts for $$$4$$$ dollars. $$$3$$$ or $$$5$$$ donuts in the first shop would cost you $$$15$$$ or $$$25$$$ dollars, respectively, however. For $$$20$$$ donuts you'll have to buy two boxes for $$$8$$$ dollars total. Note that $$$3$$$ and $$$5$$$ are also valid answers for the second shop, along with many other answers.In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. $$$8$$$ donuts cost $$$32$$$ dollars in the first shop and $$$40$$$ dollars in the second shop (because you have to buy two boxes). $$$10$$$ donuts will cost $$$40$$$ dollars in both shops, so $$$10$$$ is not a valid answer for any of the shops.In the third testcase $$$1$$$ donut costs $$$2$$$ and $$$3$$$ dollars, respectively. $$$2$$$ donuts cost $$$4$$$ and $$$3$$$ dollars. Thus, $$$1$$$ is a valid answer for the first shop and $$$2$$$ is a valid answer for the second shop.In the fourth testcase $$$10^9$$$ donuts cost $$$10^{18}$$$ dollars in the first shop and $$$10^9$$$ dollars in the second shop. | Java 8 | standard input | [
"implementation",
"greedy",
"math"
] | 002801f26568a1b3524d8754207d32c1 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a \le 10^9$$$, $$$2 \le b \le 10^9$$$, $$$1 \le c \le 10^9$$$). | 1,000 | For each testcase print two positive integers. For both shops print such $$$x$$$ that buying $$$x$$$ donuts in this shop is strictly cheaper than buying $$$x$$$ donuts in the other shop. $$$x$$$ should be greater than $$$0$$$ and less or equal to $$$10^9$$$. If there is no such $$$x$$$, then print $$$-1$$$. If there are multiple answers, then print any of them. | standard output | |
PASSED | 36bdabac6deeae5b355b0ada4c2f9943 | train_003.jsonl | 1593095700 | There are two rival donut shops.The first shop sells donuts at retail: each donut costs $$$a$$$ dollars.The second shop sells donuts only in bulk: box of $$$b$$$ donuts costs $$$c$$$ dollars. So if you want to buy $$$x$$$ donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to $$$x$$$.You want to determine two positive integer values: how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop? how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop? If any of these values doesn't exist then that value should be equal to $$$-1$$$. If there are multiple possible answers, then print any of them.The printed values should be less or equal to $$$10^9$$$. It can be shown that under the given constraints such values always exist if any values exist at all. | 256 megabytes | import javax.print.DocFlavor;
import javax.print.attribute.HashAttributeSet;
import java.awt.event.MouseAdapter;
import java.io.*;
import java.math.BigInteger;
import java.nio.channels.FileChannel;
import java.util.*;
import java.util.ArrayList;
import java.util.Scanner;
public class adaking {
static class pair {
int first;
int second;
pair(int a, int b) {
first = a;
second = b;
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static final int mod = 1000000007;
public static int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
public static String findSubString(String str, String pat)
{
int len1 = str.length();
int len2 = pat.length();
// check if string's length is less than pattern's
// length. If yes then no such window can exist
if (len1 < len2)
{
System.out.println("No such window exists");
return "";
}
int hash_pat[] = new int[256];
int hash_str[] = new int[256];
// store occurrence ofs characters of pattern
for (int i = 0; i < len2; i++)
hash_pat[pat.charAt(i)]++;
int start = 0, start_index = -1, min_len = Integer.MAX_VALUE;
// start traversing the string
int count = 0; // count of characters
for (int j = 0; j < len1 ; j++)
{
// count occurrence of characters of string
hash_str[str.charAt(j)]++;
// If string's char matches with pattern's char
// then increment count
if (hash_pat[str.charAt(j)] != 0 &&
hash_str[str.charAt(j)] <= hash_pat[str.charAt(j)] )
count++;
// if all the characters are matched
if (count == len2)
{
// Try to minimize the window i.e., check if
// any character is occurring more no. of times
// than its occurrence in pattern, if yes
// then remove it from starting and also remove
// the useless characters.
while ( hash_str[str.charAt(start)] > hash_pat[str.charAt(start)]
|| hash_pat[str.charAt(start)] == 0)
{
if (hash_str[str.charAt(start)] > hash_pat[str.charAt(start)])
hash_str[str.charAt(start)]--;
start++;
}
// update window size
int len_window = j - start + 1;
if (min_len > len_window)
{
min_len = len_window;
start_index = start;
}
}
}
// If no window found
if (start_index == -1)
{
System.out.println("No such window exists");
return "";
}
// Return substring starting from start_index
// and length min_len
return str.substring(start_index, start_index + min_len);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
sc.nextLine();
for (int k = 0; k < t; k++)
{
long a=sc.nextLong();
long b=sc.nextLong();
long c=sc.nextLong();
if(c<=a)
{
System.out.println(-1+" "+b);
}
else if((c/(double)b)>=(double)a)
{
System.out.println(1+" "+-1);
}
else
{
System.out.println(1+" "+b);
}
}
}
}
| Java | ["4\n5 10 4\n4 5 20\n2 2 3\n1000000000 1000000000 1000000000"] | 2 seconds | ["-1 20\n8 -1\n1 2\n-1 1000000000"] | NoteIn the first testcase buying any number of donuts will be cheaper in the second shop. For example, for $$$3$$$ or $$$5$$$ donuts you'll have to buy a box of $$$10$$$ donuts for $$$4$$$ dollars. $$$3$$$ or $$$5$$$ donuts in the first shop would cost you $$$15$$$ or $$$25$$$ dollars, respectively, however. For $$$20$$$ donuts you'll have to buy two boxes for $$$8$$$ dollars total. Note that $$$3$$$ and $$$5$$$ are also valid answers for the second shop, along with many other answers.In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. $$$8$$$ donuts cost $$$32$$$ dollars in the first shop and $$$40$$$ dollars in the second shop (because you have to buy two boxes). $$$10$$$ donuts will cost $$$40$$$ dollars in both shops, so $$$10$$$ is not a valid answer for any of the shops.In the third testcase $$$1$$$ donut costs $$$2$$$ and $$$3$$$ dollars, respectively. $$$2$$$ donuts cost $$$4$$$ and $$$3$$$ dollars. Thus, $$$1$$$ is a valid answer for the first shop and $$$2$$$ is a valid answer for the second shop.In the fourth testcase $$$10^9$$$ donuts cost $$$10^{18}$$$ dollars in the first shop and $$$10^9$$$ dollars in the second shop. | Java 8 | standard input | [
"implementation",
"greedy",
"math"
] | 002801f26568a1b3524d8754207d32c1 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a \le 10^9$$$, $$$2 \le b \le 10^9$$$, $$$1 \le c \le 10^9$$$). | 1,000 | For each testcase print two positive integers. For both shops print such $$$x$$$ that buying $$$x$$$ donuts in this shop is strictly cheaper than buying $$$x$$$ donuts in the other shop. $$$x$$$ should be greater than $$$0$$$ and less or equal to $$$10^9$$$. If there is no such $$$x$$$, then print $$$-1$$$. If there are multiple answers, then print any of them. | standard output | |
PASSED | 34665d830c345dddce3f0dfe505315a8 | train_003.jsonl | 1593095700 | There are two rival donut shops.The first shop sells donuts at retail: each donut costs $$$a$$$ dollars.The second shop sells donuts only in bulk: box of $$$b$$$ donuts costs $$$c$$$ dollars. So if you want to buy $$$x$$$ donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to $$$x$$$.You want to determine two positive integer values: how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop? how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop? If any of these values doesn't exist then that value should be equal to $$$-1$$$. If there are multiple possible answers, then print any of them.The printed values should be less or equal to $$$10^9$$$. It can be shown that under the given constraints such values always exist if any values exist at all. | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class d{
public static void main (String[] args) {
PrintWriter pw=new PrintWriter(System.out);
Scanner sc=new Scanner(System.in);
int t=1;
t=sc.nextInt();
for(int i11=0;i11<t;i11++){
long a=sc.nextLong();
long b=sc.nextLong();
long c=sc.nextLong();
if(c<a)
pw.println(-1+" "+b);
else{
if(a*b==c)
pw.println(1+" "+-1);
else if(a*b>c){
if(a==c)
pw.println(-1+" "+b);
else
pw.println(1+" "+b);}
else
pw.println(1+" "+-1);
}
}
pw.close();
}
} | Java | ["4\n5 10 4\n4 5 20\n2 2 3\n1000000000 1000000000 1000000000"] | 2 seconds | ["-1 20\n8 -1\n1 2\n-1 1000000000"] | NoteIn the first testcase buying any number of donuts will be cheaper in the second shop. For example, for $$$3$$$ or $$$5$$$ donuts you'll have to buy a box of $$$10$$$ donuts for $$$4$$$ dollars. $$$3$$$ or $$$5$$$ donuts in the first shop would cost you $$$15$$$ or $$$25$$$ dollars, respectively, however. For $$$20$$$ donuts you'll have to buy two boxes for $$$8$$$ dollars total. Note that $$$3$$$ and $$$5$$$ are also valid answers for the second shop, along with many other answers.In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. $$$8$$$ donuts cost $$$32$$$ dollars in the first shop and $$$40$$$ dollars in the second shop (because you have to buy two boxes). $$$10$$$ donuts will cost $$$40$$$ dollars in both shops, so $$$10$$$ is not a valid answer for any of the shops.In the third testcase $$$1$$$ donut costs $$$2$$$ and $$$3$$$ dollars, respectively. $$$2$$$ donuts cost $$$4$$$ and $$$3$$$ dollars. Thus, $$$1$$$ is a valid answer for the first shop and $$$2$$$ is a valid answer for the second shop.In the fourth testcase $$$10^9$$$ donuts cost $$$10^{18}$$$ dollars in the first shop and $$$10^9$$$ dollars in the second shop. | Java 8 | standard input | [
"implementation",
"greedy",
"math"
] | 002801f26568a1b3524d8754207d32c1 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a \le 10^9$$$, $$$2 \le b \le 10^9$$$, $$$1 \le c \le 10^9$$$). | 1,000 | For each testcase print two positive integers. For both shops print such $$$x$$$ that buying $$$x$$$ donuts in this shop is strictly cheaper than buying $$$x$$$ donuts in the other shop. $$$x$$$ should be greater than $$$0$$$ and less or equal to $$$10^9$$$. If there is no such $$$x$$$, then print $$$-1$$$. If there are multiple answers, then print any of them. | standard output | |
PASSED | 5b9274bdd3fab9d5ea42027e829262b9 | train_003.jsonl | 1593095700 | There are two rival donut shops.The first shop sells donuts at retail: each donut costs $$$a$$$ dollars.The second shop sells donuts only in bulk: box of $$$b$$$ donuts costs $$$c$$$ dollars. So if you want to buy $$$x$$$ donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to $$$x$$$.You want to determine two positive integer values: how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop? how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop? If any of these values doesn't exist then that value should be equal to $$$-1$$$. If there are multiple possible answers, then print any of them.The printed values should be less or equal to $$$10^9$$$. It can be shown that under the given constraints such values always exist if any values exist at all. | 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 Test
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int i=0;i<t;i++)
{
long a=sc.nextLong();
long b=sc.nextLong();
long c=sc.nextLong();
long ans1=1;
long ans2=b;
if(c<=a)
ans1=-1;
long mul=a*b;
if(mul<=c)
ans2=-1;
System.out.println(ans1+" "+ans2);
}
}
}
| Java | ["4\n5 10 4\n4 5 20\n2 2 3\n1000000000 1000000000 1000000000"] | 2 seconds | ["-1 20\n8 -1\n1 2\n-1 1000000000"] | NoteIn the first testcase buying any number of donuts will be cheaper in the second shop. For example, for $$$3$$$ or $$$5$$$ donuts you'll have to buy a box of $$$10$$$ donuts for $$$4$$$ dollars. $$$3$$$ or $$$5$$$ donuts in the first shop would cost you $$$15$$$ or $$$25$$$ dollars, respectively, however. For $$$20$$$ donuts you'll have to buy two boxes for $$$8$$$ dollars total. Note that $$$3$$$ and $$$5$$$ are also valid answers for the second shop, along with many other answers.In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. $$$8$$$ donuts cost $$$32$$$ dollars in the first shop and $$$40$$$ dollars in the second shop (because you have to buy two boxes). $$$10$$$ donuts will cost $$$40$$$ dollars in both shops, so $$$10$$$ is not a valid answer for any of the shops.In the third testcase $$$1$$$ donut costs $$$2$$$ and $$$3$$$ dollars, respectively. $$$2$$$ donuts cost $$$4$$$ and $$$3$$$ dollars. Thus, $$$1$$$ is a valid answer for the first shop and $$$2$$$ is a valid answer for the second shop.In the fourth testcase $$$10^9$$$ donuts cost $$$10^{18}$$$ dollars in the first shop and $$$10^9$$$ dollars in the second shop. | Java 8 | standard input | [
"implementation",
"greedy",
"math"
] | 002801f26568a1b3524d8754207d32c1 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a \le 10^9$$$, $$$2 \le b \le 10^9$$$, $$$1 \le c \le 10^9$$$). | 1,000 | For each testcase print two positive integers. For both shops print such $$$x$$$ that buying $$$x$$$ donuts in this shop is strictly cheaper than buying $$$x$$$ donuts in the other shop. $$$x$$$ should be greater than $$$0$$$ and less or equal to $$$10^9$$$. If there is no such $$$x$$$, then print $$$-1$$$. If there are multiple answers, then print any of them. | standard output | |
PASSED | 9aca5cff076c11d4cce330a2ad2e3125 | train_003.jsonl | 1593095700 | There are two rival donut shops.The first shop sells donuts at retail: each donut costs $$$a$$$ dollars.The second shop sells donuts only in bulk: box of $$$b$$$ donuts costs $$$c$$$ dollars. So if you want to buy $$$x$$$ donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to $$$x$$$.You want to determine two positive integer values: how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop? how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop? If any of these values doesn't exist then that value should be equal to $$$-1$$$. If there are multiple possible answers, then print any of them.The printed values should be less or equal to $$$10^9$$$. It can be shown that under the given constraints such values always exist if any values exist at all. | 256 megabytes | import java.io.*;
import java.util.StringTokenizer;
public class DonutShops_1000 {
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
int t = sc.nextInt();
for(int i = 0; i < t; i++) {
double A = Double.parseDouble(sc.next());
double B = Double.parseDouble(sc.next());
double C = Double.parseDouble(sc.next());
int val1 = -1;
int val2 = -1;
if(C < A*B) {
val1 = (int)B;
}
if(A < C) {
val2 = 1;
}
System.out.println(val2 + " " + val1);
}
out.close();
}
public static PrintWriter out;
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int 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\n5 10 4\n4 5 20\n2 2 3\n1000000000 1000000000 1000000000"] | 2 seconds | ["-1 20\n8 -1\n1 2\n-1 1000000000"] | NoteIn the first testcase buying any number of donuts will be cheaper in the second shop. For example, for $$$3$$$ or $$$5$$$ donuts you'll have to buy a box of $$$10$$$ donuts for $$$4$$$ dollars. $$$3$$$ or $$$5$$$ donuts in the first shop would cost you $$$15$$$ or $$$25$$$ dollars, respectively, however. For $$$20$$$ donuts you'll have to buy two boxes for $$$8$$$ dollars total. Note that $$$3$$$ and $$$5$$$ are also valid answers for the second shop, along with many other answers.In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. $$$8$$$ donuts cost $$$32$$$ dollars in the first shop and $$$40$$$ dollars in the second shop (because you have to buy two boxes). $$$10$$$ donuts will cost $$$40$$$ dollars in both shops, so $$$10$$$ is not a valid answer for any of the shops.In the third testcase $$$1$$$ donut costs $$$2$$$ and $$$3$$$ dollars, respectively. $$$2$$$ donuts cost $$$4$$$ and $$$3$$$ dollars. Thus, $$$1$$$ is a valid answer for the first shop and $$$2$$$ is a valid answer for the second shop.In the fourth testcase $$$10^9$$$ donuts cost $$$10^{18}$$$ dollars in the first shop and $$$10^9$$$ dollars in the second shop. | Java 8 | standard input | [
"implementation",
"greedy",
"math"
] | 002801f26568a1b3524d8754207d32c1 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a \le 10^9$$$, $$$2 \le b \le 10^9$$$, $$$1 \le c \le 10^9$$$). | 1,000 | For each testcase print two positive integers. For both shops print such $$$x$$$ that buying $$$x$$$ donuts in this shop is strictly cheaper than buying $$$x$$$ donuts in the other shop. $$$x$$$ should be greater than $$$0$$$ and less or equal to $$$10^9$$$. If there is no such $$$x$$$, then print $$$-1$$$. If there are multiple answers, then print any of them. | standard output | |
PASSED | 3cf5d5c3c7db46726d596a7f7ce6df75 | train_003.jsonl | 1593095700 | There are two rival donut shops.The first shop sells donuts at retail: each donut costs $$$a$$$ dollars.The second shop sells donuts only in bulk: box of $$$b$$$ donuts costs $$$c$$$ dollars. So if you want to buy $$$x$$$ donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to $$$x$$$.You want to determine two positive integer values: how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop? how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop? If any of these values doesn't exist then that value should be equal to $$$-1$$$. If there are multiple possible answers, then print any of them.The printed values should be less or equal to $$$10^9$$$. It can be shown that under the given constraints such values always exist if any values exist at all. | 256 megabytes | import java.util.Scanner;
public class DonutShops {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
long numTestcases = scanner.nextLong();
while(numTestcases-- > 0) {
long a = scanner.nextLong();
long b = scanner.nextLong();
long c = scanner.nextLong();
System.out.print(a < c ? 1 : -1);
System.out.print(" " + ((c < a * b) ? b : -1));
System.out.println();
}
}
} | Java | ["4\n5 10 4\n4 5 20\n2 2 3\n1000000000 1000000000 1000000000"] | 2 seconds | ["-1 20\n8 -1\n1 2\n-1 1000000000"] | NoteIn the first testcase buying any number of donuts will be cheaper in the second shop. For example, for $$$3$$$ or $$$5$$$ donuts you'll have to buy a box of $$$10$$$ donuts for $$$4$$$ dollars. $$$3$$$ or $$$5$$$ donuts in the first shop would cost you $$$15$$$ or $$$25$$$ dollars, respectively, however. For $$$20$$$ donuts you'll have to buy two boxes for $$$8$$$ dollars total. Note that $$$3$$$ and $$$5$$$ are also valid answers for the second shop, along with many other answers.In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. $$$8$$$ donuts cost $$$32$$$ dollars in the first shop and $$$40$$$ dollars in the second shop (because you have to buy two boxes). $$$10$$$ donuts will cost $$$40$$$ dollars in both shops, so $$$10$$$ is not a valid answer for any of the shops.In the third testcase $$$1$$$ donut costs $$$2$$$ and $$$3$$$ dollars, respectively. $$$2$$$ donuts cost $$$4$$$ and $$$3$$$ dollars. Thus, $$$1$$$ is a valid answer for the first shop and $$$2$$$ is a valid answer for the second shop.In the fourth testcase $$$10^9$$$ donuts cost $$$10^{18}$$$ dollars in the first shop and $$$10^9$$$ dollars in the second shop. | Java 8 | standard input | [
"implementation",
"greedy",
"math"
] | 002801f26568a1b3524d8754207d32c1 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a \le 10^9$$$, $$$2 \le b \le 10^9$$$, $$$1 \le c \le 10^9$$$). | 1,000 | For each testcase print two positive integers. For both shops print such $$$x$$$ that buying $$$x$$$ donuts in this shop is strictly cheaper than buying $$$x$$$ donuts in the other shop. $$$x$$$ should be greater than $$$0$$$ and less or equal to $$$10^9$$$. If there is no such $$$x$$$, then print $$$-1$$$. If there are multiple answers, then print any of them. | standard output | |
PASSED | cc2c2e929e91f99615057665ce4ba174 | train_003.jsonl | 1593095700 | There are two rival donut shops.The first shop sells donuts at retail: each donut costs $$$a$$$ dollars.The second shop sells donuts only in bulk: box of $$$b$$$ donuts costs $$$c$$$ dollars. So if you want to buy $$$x$$$ donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to $$$x$$$.You want to determine two positive integer values: how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop? how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop? If any of these values doesn't exist then that value should be equal to $$$-1$$$. If there are multiple possible answers, then print any of them.The printed values should be less or equal to $$$10^9$$$. It can be shown that under the given constraints such values always exist if any values exist at all. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
MyScanner in = new MyScanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
int testCount = Integer.parseInt(in.next());
for (int i = 1; i <= testCount; i++)
solver.solve(i, in, out);
out.close();
}
static class TaskA {
public void solve(int testNumber, MyScanner in, PrintWriter out) {
long a, b, c;
a = in.nextInt();
// c1
b = in.nextInt();
c = in.nextInt();
if (c <= a) {
out.println("-1 " + b);
} else {
long x2 = -1, x1 = -1;
if (a * b > c) {
x2 = b;
}
if (a < c) {
x1 = 1;
}
out.println(x1 + " " + x2);
}
}
}
static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner(InputStream io) {
br = new BufferedReader(new InputStreamReader(io));
}
public String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| Java | ["4\n5 10 4\n4 5 20\n2 2 3\n1000000000 1000000000 1000000000"] | 2 seconds | ["-1 20\n8 -1\n1 2\n-1 1000000000"] | NoteIn the first testcase buying any number of donuts will be cheaper in the second shop. For example, for $$$3$$$ or $$$5$$$ donuts you'll have to buy a box of $$$10$$$ donuts for $$$4$$$ dollars. $$$3$$$ or $$$5$$$ donuts in the first shop would cost you $$$15$$$ or $$$25$$$ dollars, respectively, however. For $$$20$$$ donuts you'll have to buy two boxes for $$$8$$$ dollars total. Note that $$$3$$$ and $$$5$$$ are also valid answers for the second shop, along with many other answers.In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. $$$8$$$ donuts cost $$$32$$$ dollars in the first shop and $$$40$$$ dollars in the second shop (because you have to buy two boxes). $$$10$$$ donuts will cost $$$40$$$ dollars in both shops, so $$$10$$$ is not a valid answer for any of the shops.In the third testcase $$$1$$$ donut costs $$$2$$$ and $$$3$$$ dollars, respectively. $$$2$$$ donuts cost $$$4$$$ and $$$3$$$ dollars. Thus, $$$1$$$ is a valid answer for the first shop and $$$2$$$ is a valid answer for the second shop.In the fourth testcase $$$10^9$$$ donuts cost $$$10^{18}$$$ dollars in the first shop and $$$10^9$$$ dollars in the second shop. | Java 8 | standard input | [
"implementation",
"greedy",
"math"
] | 002801f26568a1b3524d8754207d32c1 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a \le 10^9$$$, $$$2 \le b \le 10^9$$$, $$$1 \le c \le 10^9$$$). | 1,000 | For each testcase print two positive integers. For both shops print such $$$x$$$ that buying $$$x$$$ donuts in this shop is strictly cheaper than buying $$$x$$$ donuts in the other shop. $$$x$$$ should be greater than $$$0$$$ and less or equal to $$$10^9$$$. If there is no such $$$x$$$, then print $$$-1$$$. If there are multiple answers, then print any of them. | standard output | |
PASSED | a1b0e0cab9e256dd3fb23776d03cbe75 | train_003.jsonl | 1593095700 | There are two rival donut shops.The first shop sells donuts at retail: each donut costs $$$a$$$ dollars.The second shop sells donuts only in bulk: box of $$$b$$$ donuts costs $$$c$$$ dollars. So if you want to buy $$$x$$$ donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to $$$x$$$.You want to determine two positive integer values: how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop? how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop? If any of these values doesn't exist then that value should be equal to $$$-1$$$. If there are multiple possible answers, then print any of them.The printed values should be less or equal to $$$10^9$$$. It can be shown that under the given constraints such values always exist if any values exist at all. | 256 megabytes | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
MyScanner in = new MyScanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
int testCount = Integer.parseInt(in.next());
for (int i = 1; i <= testCount; i++)
solver.solve(i, in, out);
out.close();
}
static class TaskA {
public void solve(int testNumber, MyScanner in, PrintWriter out) {
long a, b, c;
a = in.nextInt();
// c1
b = in.nextInt();
c = in.nextInt();
if (a < c) {
long x2 = -1;
if (a * b > c) x2 = b;
out.println("1 " + x2);
return;
}
if (a >= c) {
out.println("-1 " + b);
return;
}
}
}
static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner(InputStream io) {
br = new BufferedReader(new InputStreamReader(io));
}
public String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
| Java | ["4\n5 10 4\n4 5 20\n2 2 3\n1000000000 1000000000 1000000000"] | 2 seconds | ["-1 20\n8 -1\n1 2\n-1 1000000000"] | NoteIn the first testcase buying any number of donuts will be cheaper in the second shop. For example, for $$$3$$$ or $$$5$$$ donuts you'll have to buy a box of $$$10$$$ donuts for $$$4$$$ dollars. $$$3$$$ or $$$5$$$ donuts in the first shop would cost you $$$15$$$ or $$$25$$$ dollars, respectively, however. For $$$20$$$ donuts you'll have to buy two boxes for $$$8$$$ dollars total. Note that $$$3$$$ and $$$5$$$ are also valid answers for the second shop, along with many other answers.In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. $$$8$$$ donuts cost $$$32$$$ dollars in the first shop and $$$40$$$ dollars in the second shop (because you have to buy two boxes). $$$10$$$ donuts will cost $$$40$$$ dollars in both shops, so $$$10$$$ is not a valid answer for any of the shops.In the third testcase $$$1$$$ donut costs $$$2$$$ and $$$3$$$ dollars, respectively. $$$2$$$ donuts cost $$$4$$$ and $$$3$$$ dollars. Thus, $$$1$$$ is a valid answer for the first shop and $$$2$$$ is a valid answer for the second shop.In the fourth testcase $$$10^9$$$ donuts cost $$$10^{18}$$$ dollars in the first shop and $$$10^9$$$ dollars in the second shop. | Java 8 | standard input | [
"implementation",
"greedy",
"math"
] | 002801f26568a1b3524d8754207d32c1 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a \le 10^9$$$, $$$2 \le b \le 10^9$$$, $$$1 \le c \le 10^9$$$). | 1,000 | For each testcase print two positive integers. For both shops print such $$$x$$$ that buying $$$x$$$ donuts in this shop is strictly cheaper than buying $$$x$$$ donuts in the other shop. $$$x$$$ should be greater than $$$0$$$ and less or equal to $$$10^9$$$. If there is no such $$$x$$$, then print $$$-1$$$. If there are multiple answers, then print any of them. | standard output | |
PASSED | 8e72a7a6c411755041fbba0223849494 | train_003.jsonl | 1593095700 | There are two rival donut shops.The first shop sells donuts at retail: each donut costs $$$a$$$ dollars.The second shop sells donuts only in bulk: box of $$$b$$$ donuts costs $$$c$$$ dollars. So if you want to buy $$$x$$$ donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to $$$x$$$.You want to determine two positive integer values: how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop? how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop? If any of these values doesn't exist then that value should be equal to $$$-1$$$. If there are multiple possible answers, then print any of them.The printed values should be less or equal to $$$10^9$$$. It can be shown that under the given constraints such values always exist if any values exist at all. | 256 megabytes | import java.util.Scanner;
public class donut{
public static void main(String args[]){
int test;
Scanner scan = new Scanner(System.in);
test = scan.nextInt();
for(int i=0;i<test;i++){
long a,b,c;
long y=-1;
long z=-1;
a = scan.nextLong();
b = scan.nextLong();
c = scan.nextLong();
//shop 1 is cheaper
if(a>=c){
y=-1;
z= b;
}else{
y=1;
if(a*b>c){
z=b;
}
}
System.out.print(y+ " " + z);
System.out.print("\n");
}//for test case
}//main
}//class | Java | ["4\n5 10 4\n4 5 20\n2 2 3\n1000000000 1000000000 1000000000"] | 2 seconds | ["-1 20\n8 -1\n1 2\n-1 1000000000"] | NoteIn the first testcase buying any number of donuts will be cheaper in the second shop. For example, for $$$3$$$ or $$$5$$$ donuts you'll have to buy a box of $$$10$$$ donuts for $$$4$$$ dollars. $$$3$$$ or $$$5$$$ donuts in the first shop would cost you $$$15$$$ or $$$25$$$ dollars, respectively, however. For $$$20$$$ donuts you'll have to buy two boxes for $$$8$$$ dollars total. Note that $$$3$$$ and $$$5$$$ are also valid answers for the second shop, along with many other answers.In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. $$$8$$$ donuts cost $$$32$$$ dollars in the first shop and $$$40$$$ dollars in the second shop (because you have to buy two boxes). $$$10$$$ donuts will cost $$$40$$$ dollars in both shops, so $$$10$$$ is not a valid answer for any of the shops.In the third testcase $$$1$$$ donut costs $$$2$$$ and $$$3$$$ dollars, respectively. $$$2$$$ donuts cost $$$4$$$ and $$$3$$$ dollars. Thus, $$$1$$$ is a valid answer for the first shop and $$$2$$$ is a valid answer for the second shop.In the fourth testcase $$$10^9$$$ donuts cost $$$10^{18}$$$ dollars in the first shop and $$$10^9$$$ dollars in the second shop. | Java 8 | standard input | [
"implementation",
"greedy",
"math"
] | 002801f26568a1b3524d8754207d32c1 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a \le 10^9$$$, $$$2 \le b \le 10^9$$$, $$$1 \le c \le 10^9$$$). | 1,000 | For each testcase print two positive integers. For both shops print such $$$x$$$ that buying $$$x$$$ donuts in this shop is strictly cheaper than buying $$$x$$$ donuts in the other shop. $$$x$$$ should be greater than $$$0$$$ and less or equal to $$$10^9$$$. If there is no such $$$x$$$, then print $$$-1$$$. If there are multiple answers, then print any of them. | standard output | |
PASSED | df44cd16b6d10d5944db70524fe7db20 | train_003.jsonl | 1593095700 | There are two rival donut shops.The first shop sells donuts at retail: each donut costs $$$a$$$ dollars.The second shop sells donuts only in bulk: box of $$$b$$$ donuts costs $$$c$$$ dollars. So if you want to buy $$$x$$$ donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to $$$x$$$.You want to determine two positive integer values: how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop? how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop? If any of these values doesn't exist then that value should be equal to $$$-1$$$. If there are multiple possible answers, then print any of them.The printed values should be less or equal to $$$10^9$$$. It can be shown that under the given constraints such values always exist if any values exist at all. | 256 megabytes | import java.util.Scanner;
public class Donuts {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i =0; i<t; i++)
{
long a = sc.nextInt();
long b = sc.nextInt();
long c = sc.nextInt();
if(a<c)
{
System.out.print("1"+" ");
}
else
{
System.out.print("-1"+" ");
}
if(a*b>c)
{
System.out.println(b+" ");
}
else
{
System.out.println("-1"+" ");
}
}
}
public static long lcm(long a, long b)
{
long x = -1L;
for (int i = 1; ; i++)
{
x = a * i;
if(x%b == 0)
{
return x;
}
}
}
} | Java | ["4\n5 10 4\n4 5 20\n2 2 3\n1000000000 1000000000 1000000000"] | 2 seconds | ["-1 20\n8 -1\n1 2\n-1 1000000000"] | NoteIn the first testcase buying any number of donuts will be cheaper in the second shop. For example, for $$$3$$$ or $$$5$$$ donuts you'll have to buy a box of $$$10$$$ donuts for $$$4$$$ dollars. $$$3$$$ or $$$5$$$ donuts in the first shop would cost you $$$15$$$ or $$$25$$$ dollars, respectively, however. For $$$20$$$ donuts you'll have to buy two boxes for $$$8$$$ dollars total. Note that $$$3$$$ and $$$5$$$ are also valid answers for the second shop, along with many other answers.In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. $$$8$$$ donuts cost $$$32$$$ dollars in the first shop and $$$40$$$ dollars in the second shop (because you have to buy two boxes). $$$10$$$ donuts will cost $$$40$$$ dollars in both shops, so $$$10$$$ is not a valid answer for any of the shops.In the third testcase $$$1$$$ donut costs $$$2$$$ and $$$3$$$ dollars, respectively. $$$2$$$ donuts cost $$$4$$$ and $$$3$$$ dollars. Thus, $$$1$$$ is a valid answer for the first shop and $$$2$$$ is a valid answer for the second shop.In the fourth testcase $$$10^9$$$ donuts cost $$$10^{18}$$$ dollars in the first shop and $$$10^9$$$ dollars in the second shop. | Java 8 | standard input | [
"implementation",
"greedy",
"math"
] | 002801f26568a1b3524d8754207d32c1 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a \le 10^9$$$, $$$2 \le b \le 10^9$$$, $$$1 \le c \le 10^9$$$). | 1,000 | For each testcase print two positive integers. For both shops print such $$$x$$$ that buying $$$x$$$ donuts in this shop is strictly cheaper than buying $$$x$$$ donuts in the other shop. $$$x$$$ should be greater than $$$0$$$ and less or equal to $$$10^9$$$. If there is no such $$$x$$$, then print $$$-1$$$. If there are multiple answers, then print any of them. | standard output | |
PASSED | 1553bcd792ec0f74bd9b702c9cebb3a9 | train_003.jsonl | 1593095700 | There are two rival donut shops.The first shop sells donuts at retail: each donut costs $$$a$$$ dollars.The second shop sells donuts only in bulk: box of $$$b$$$ donuts costs $$$c$$$ dollars. So if you want to buy $$$x$$$ donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to $$$x$$$.You want to determine two positive integer values: how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop? how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop? If any of these values doesn't exist then that value should be equal to $$$-1$$$. If there are multiple possible answers, then print any of them.The printed values should be less or equal to $$$10^9$$$. It can be shown that under the given constraints such values always exist if any values exist at all. | 256 megabytes | import java.util.*;
import java.io.*;
import java.io.BufferedReader;
public class Z_A{
public static long mod= 1000000007;
public static Debug db;
public static boolean w=true;
public static void main(String[] args) throws IOException {
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
Autocompletion solver = new Autocompletion();
db=new Debug(System.getSecurityManager()==null);
solver.solve(1, in, out);
out.close();
}
static class Autocompletion {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int t1=in.nextInt();
for(int z1=0;z1<t1;z1++) {
int a=in.nextInt();
int b=in.nextInt();
int c=in.nextInt();
int ret1=0;
int ret2=0;
if(c<a) {//box is cheaper than single
ret1=-1;
ret2=1;
}
else if(c==a) {
ret1=-1;
ret2=2;
}
else if((long)b*a<=c) {//rather buy singles
ret1=1;
ret2=-1;
}
else {//just get a box
ret1=1;
ret2=b;
}
out.println(ret1+" "+ret2);
}
}
}
static class Pair implements Comparable<Pair>{
int x;
int y;
Pair(int a, int b){
x=a;
y=b;
}
@Override
public int compareTo(Pair arg0) {
if(arg0.x!=x)return x-arg0.x;
return y-arg0.y;
}
}
static class Triple implements Comparable<Triple>{
int x;
int y;
int z;
Triple(int a, int b, int c){
x=a;
y=b;
z=c;
}
@Override
public int compareTo(Triple arg0) {
if(arg0.x!=x)return x-arg0.x;
return y-arg0.y;
}
}
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 int[] nextIntArr(int n) {
int arr[]=new int[n];
for(int i=0;i<n;i++) {
arr[i]=this.nextInt();
}
return arr;
}
}
public static class Debug {
private boolean allowDebug;
public Debug(boolean allowDebug) {
this.allowDebug = allowDebug;
}
private void outputName(String name) {
System.out.print(name + " = ");
}
public void debug(String name, int x) {
if (!allowDebug) {
return;
}
outputName(name);
System.out.println("" + x);
}
public void debug(String name, long x) {
if (!allowDebug) {
return;
}
outputName(name);
System.out.println("" + x);
}
public void debug(String name, double x) {
if (!allowDebug) {
return;
}
outputName(name);
System.out.println("" + x);
}
public void debug(String name, int[] x) {
if (!allowDebug) {
return;
}
outputName(name);
System.out.println(Arrays.toString(x));
}
public void debug(String name, long[] x) {
if (!allowDebug) {
return;
}
outputName(name);
System.out.println(Arrays.toString(x));
}
public void debug(String name, double[] x) {
if (!allowDebug) {
return;
}
outputName(name);
System.out.println(Arrays.toString(x));
}
public void debug(String name, Pair[] x) {
if (!allowDebug) {
return;
}
outputName(name);
StringBuilder sb = new StringBuilder("[");
int cnt=0;
for(Pair y:x) {
sb.append("("+y.x+","+y.y+')');
if (cnt != x.length-1)sb.append(", ");
cnt++;
}
System.out.println(sb.append("]").toString());
}
public void debug(String name, Object x) {
if (!allowDebug) {
return;
}
outputName(name);
System.out.println("" + x);
}
public void debug(String name, Object... x) {
if (!allowDebug) {
return;
}
outputName(name);
System.out.println(Arrays.deepToString(x));
}
}
}
| Java | ["4\n5 10 4\n4 5 20\n2 2 3\n1000000000 1000000000 1000000000"] | 2 seconds | ["-1 20\n8 -1\n1 2\n-1 1000000000"] | NoteIn the first testcase buying any number of donuts will be cheaper in the second shop. For example, for $$$3$$$ or $$$5$$$ donuts you'll have to buy a box of $$$10$$$ donuts for $$$4$$$ dollars. $$$3$$$ or $$$5$$$ donuts in the first shop would cost you $$$15$$$ or $$$25$$$ dollars, respectively, however. For $$$20$$$ donuts you'll have to buy two boxes for $$$8$$$ dollars total. Note that $$$3$$$ and $$$5$$$ are also valid answers for the second shop, along with many other answers.In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. $$$8$$$ donuts cost $$$32$$$ dollars in the first shop and $$$40$$$ dollars in the second shop (because you have to buy two boxes). $$$10$$$ donuts will cost $$$40$$$ dollars in both shops, so $$$10$$$ is not a valid answer for any of the shops.In the third testcase $$$1$$$ donut costs $$$2$$$ and $$$3$$$ dollars, respectively. $$$2$$$ donuts cost $$$4$$$ and $$$3$$$ dollars. Thus, $$$1$$$ is a valid answer for the first shop and $$$2$$$ is a valid answer for the second shop.In the fourth testcase $$$10^9$$$ donuts cost $$$10^{18}$$$ dollars in the first shop and $$$10^9$$$ dollars in the second shop. | Java 8 | standard input | [
"implementation",
"greedy",
"math"
] | 002801f26568a1b3524d8754207d32c1 | The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$)Β β the number of testcases. Each of the next $$$t$$$ lines contains three integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \le a \le 10^9$$$, $$$2 \le b \le 10^9$$$, $$$1 \le c \le 10^9$$$). | 1,000 | For each testcase print two positive integers. For both shops print such $$$x$$$ that buying $$$x$$$ donuts in this shop is strictly cheaper than buying $$$x$$$ donuts in the other shop. $$$x$$$ should be greater than $$$0$$$ and less or equal to $$$10^9$$$. If there is no such $$$x$$$, then print $$$-1$$$. If there are multiple answers, then print any of them. | standard output | |
PASSED | 952f8c16b5a8c2f7deb963fb29e57bba | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 256 megabytes | import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
sc.nextInt();
int height = sc.nextInt();
int width = 0;
while (sc.hasNextInt()){
if (sc.nextInt() > height){
width+=2;
}else{
width++;
}
}
System.out.print(width);
}
} | Java | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | f02aca83e2c33555a135d87a947bfc80 | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 256 megabytes | import java.util.*;
import java.io.*;
public class TestClass {
public static void main(String args[] ) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int h = s.nextInt();
int a=0;
for(int i=0;i<n;i++){
int x = s.nextInt();
if(h>0){
if(x<=h)
{
a+=1;
}
else
a+=2;
}
}
System.out.println(a);
}
}
| Java | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | 9bf3340e4ec0bcecf9c5566ee24d691b | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 256 megabytes | import java.util.Scanner;
/**
*
* @author MOHAMED
*/
public class ProblemSolving2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
//=================================== Vanya and Fence ==========================================
int n = s.nextInt();
int h = s.nextInt();
int widthOfStreet = 0;
for (int i = 0; i < n; i++) {
int nHieght = s.nextInt();
if (nHieght<=h) {
widthOfStreet++;
} else {
widthOfStreet += 2;
}
}
System.out.println(widthOfStreet);
}
}
| Java | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | c8e2bceaafde5f12a16ff222ad31b080 | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 256 megabytes | import java.util.Scanner;
import java.util.stream.IntStream;
public class ProblemSolving {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
//=================================== Vanya and Fence ===========================================
Scanner s = new Scanner(System.in);
int numberOfPersons = s.nextInt();
int hightOfFence = s.nextInt();
int[] personsHight = new int[numberOfPersons];
int[] personsWidth = new int[numberOfPersons];
for (int i = 0; i < personsHight.length; i++) {
int personHight = s.nextInt();
personsHight[i] = personHight;
if (personsHight[i]<=hightOfFence) {
personsWidth[i] = 1;
}
else {personsWidth[i]=2;}
}
System.out.println(String.valueOf(IntStream.of(personsWidth).sum()));
}
} | Java | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | 1b99d5ca9c130cf7470bb114c24b670a | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 256 megabytes | import java.util.Scanner;
public class VanyaAndFence {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// System.out.println("enter the number of friends ... ");
int numberOfFriends = scanner.nextInt();
// System.out.println("enter the height ... ");
int maxHeight = scanner.nextInt();
int[] friends = new int[numberOfFriends];
int counter = numberOfFriends ;
while (counter != 0) {
//System.out.println("enter the " + numberOfFriends + " friend");
friends[numberOfFriends - counter] = scanner.nextInt();
--counter;
}
System.out.println(calculateMinimumWidth(friends, maxHeight));
}
private static int calculateMinimumWidth(int[] friends, int maxHeight) {
int minimumWidth = 0 ;
for (int i = 0; i < friends.length; i++) {
if (friends[i] > maxHeight) {
minimumWidth +=2 ;
}else{
minimumWidth +=1 ;
}
}
return minimumWidth;
}
}
| Java | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | b3673ca4b4f3cdcec19e7c797ee91acb | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main (String [] args) {
Scanner key = new Scanner(System.in);
int n = key.nextInt();
int h = key.nextInt();
int width = 0, temp;
for (int i = 0; i < n; i++) {
temp = key.nextInt();
if (temp <= h)
width++;
else if (temp > h)
width += 2;
}
System.out.print(width);
}
} | Java | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | 5d3d5858de1a2f03a7ff4dbe6d9cbae7 | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 256 megabytes | //import Codeforces.CodeforcesLibrary; // it will be error - add methods to this class as static methods
import java.util.*;
public class TestCodeforces {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
solve(scanner);
scanner.close();
}
public static void solve(Scanner scanner) {
int x = scanner.nextInt(), h = scanner.nextInt();
int res = 0;
for (int i = 0; i < x; i++) {
int n= scanner.nextInt();
if (n > h) res += 2;
else res += 1;
}
System.out.println(res);
}
}
| Java | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | 4f2e21a22cef94f5609df6f5d0a9d8f7 | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 256 megabytes | //import Codeforces.CodeforcesLibrary; // it will be error - add methods to this class as static methods
import java.util.*;
public class TestCodeforces {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
solve(scanner);
scanner.close();
}
public static void solve(Scanner scanner) {
int x = scanner.nextInt(), h = scanner.nextInt();
int res = 0;
for (int i = 0; i < x; i++) {
int n = scanner.nextInt();
if (n > h) res += 2;
else res += 1;
}
System.out.println(res);
}
}
| Java | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | 309134d5f726c7fa689dcc1bfcb3e28d | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 256 megabytes | import java.util.*;
public class TestCodeforces {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int x = scanner.nextInt(), h = scanner.nextInt();
int res = 0;
for (int i = 0; i < x; i++) {
int n = scanner.nextInt();
if (n > h) res+= 2;
else res += 1;
}
System.out.println(res);
scanner.close();
}
}
| Java | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | d99f755c6b5a36af8a69f40702eb9940 | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 256 megabytes | import java.util.*;
public class TestCodeforces {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int x = scanner.nextInt(), h = scanner.nextInt();
int res = 0;
for (int i = 0; i < x; i++) {
int n = scanner.nextInt();
if (n > h) res += 2;
else res += 1;
}
System.out.println(res);
scanner.close();
}
}
| Java | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | e16df938cdb9557d1aac953c5b6a5e90 | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 256 megabytes | import java.util.*;
public class TestCodeforces {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt(), h = scanner.nextInt();
int res = 0;
for (int i = 0; i < n; i++) {
if (scanner.nextInt() > h) res += 2;
else res += 1;
}
System.out.println(res);
scanner.close();
}
}
| Java | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | 14e03e1871893c2d9cfb07020660ba10 | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 256 megabytes | import java.util.*;
public class TestCodeforces {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
/*
n people, h hieght, person standing - 1 width, person bending - 2 width, count the minimum length of them
*/
int n = scanner.nextInt(), h = scanner.nextInt();
int res = 0;
for (int i = 0; i < n; i++) {
int currH = scanner.nextInt();
if (currH > h) res += 2;
else res++;
}
System.out.println(res);
scanner.close();
}
}
| Java | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | bd8579741f37119cbe48a713801c38c2 | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 256 megabytes | import java.util.*;
public class VanyaAndFence {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int h = s.nextInt();
int sum = 0;
while(n-->=1) {
if(Math.ceil(s.nextInt()/(h+.0)) <= 1.0) {
sum++;
continue;
}
sum+=2;
}
System.out.println(sum);
}
} | Java | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | e59bd57f9a2dddf4b733c18356a07957 | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 256 megabytes | import java.util.Scanner;
public class p1 {
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int h = scan.nextInt();
int a;
int sum=0;
for(int i=0; i<n;i++){
a = scan.nextInt();
if(a <= h)
{
sum++;
}
else
{
sum +=2;}
}
System.out.println(sum);
}
} | Java | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | 8df8616826f85110a875a9d60faf63cb | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 256 megabytes | import java.util.Scanner;
public class VanyaAndFence {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int n,h,sum=0,a;
n=scan.nextInt();
h=scan.nextInt();
for(int i=0;i<n;i++){
a=scan.nextInt();
if(a<=h){
sum++;}
else{
sum+=2;}
}
System.out.println(sum);
}
} | Java | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | 882a7a16d2891631e0ed495707ae0b3d | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 256 megabytes | import java.util.Scanner;
import java.util.Arrays;
public class problem1 {
public static void main(String[] args) {
int width = 0;
Scanner read = new Scanner(System.in);
int n = read.nextInt();
int h = read.nextInt();
int Array[] = new int[n];
for (int i = 0; i <= Array.length - 1; i++) {
Array[i] = read.nextInt();
}
for (int z = 0; z <= Array.length - 1; z++) {
if (Array[z] <= h) {
width = width + 1;
} else {
width = width + 2;
}
}
System.out.println(width);
}
} | Java | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | 22807bd907dccd9313bb05d40f939e1d | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 256 megabytes | import java.util.Scanner;
public class First {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner reader = new Scanner(System.in); // Reading from System.in
//System.out.println("number of friends: ");
int n = reader.nextInt(); // Scans the next token of the input as an int.
//System.out.println("fence hight: ");
int h = reader.nextInt(); // Scans the next token of the input as an int.
//once finished
int result=0;
do {
int x = reader.nextInt();
//System.out.println(x);
if(x > h)
{
result = result+2;
}
else
{
result++;
}
n--;
}while(n>0);
reader.close();
System.out.println(result);
}
}
| Java | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | 478e90414a7ed5400980f0ccffdbe46d | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 256 megabytes | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n=in.nextInt() , h=in.nextInt(),per,sum=0;
for(int i=0;i<n;i++)
{
per=in.nextInt();
if(per>h)
sum+=2;
else
sum++;
}
System.out.println(sum);
}
} | Java | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | 3e3598ac81b7868876f9696bdf88e3da | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 256 megabytes | import java.util.Scanner;
public class Vanya {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int f=s.nextInt(),h=s.nextInt(),count=0,x;
for (int i=0;i<f;i++){
x=s.nextInt();
if (x>h)
count+=2;
else
count++;
}
System.out.print(count);
}
}
| Java | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | 97314ef5dfc3c369be11e6fed2fd890a | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 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 Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
try {
Scanner sc = new Scanner(System.in);
int sum=0;
//System.out.System.out.println("Enter Number of People");
int n = sc.nextInt();
int [] a = new int [n];
//System.out.println("Enter the Height of the fence");
int h = sc.nextInt();
for(int i=0;i<n;i++)
{
//Enter Height of N People
a[i] = sc.nextInt();
}
for(int i=0;i<n;i++)
{
if(a[i]>h)
{
sum+=2;
}
else
{
sum+=1;
}
}
System.out.println(""+sum);
} catch(Exception e) {
return;
}
}
} | Java | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | 5af1bba8be023cc4d83e2e052619a0a3 | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 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 Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
try {
Scanner sc = new Scanner(System.in);
int sum=0;
//System.out.System.out.println("Enter Number of People");
int n = sc.nextInt();
int [] a = new int [n];
//System.out.println("Enter the Height of the fence");
int h = sc.nextInt();
for(int i=0;i<n;i++)
{
//Enter Height of N People
a[i] = sc.nextInt();
}
for(int i=0;i<n;i++)
{
if(a[i]>h)
{
sum+=2;
}
else
{
sum+=1;
}
}
System.out.println(""+sum);
} catch(Exception e) {
return;
} finally {
}
}
} | Java | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | 7b41d8c177ade91ecb17ed48722ba8bc | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 256 megabytes | import java.util.*;
public class VanyaAndFence {
static int caculate() {
Scanner scanner = new Scanner(System.in);
Scanner lineScanner;
String line;
int numberOfFriends = 0;
int heightOfFrence = 0;
int minValidWidth = 0;
for (int i = 0; i < 2 && scanner.hasNextLine(); i++) {
if ( i== 0) {
line = scanner.nextLine();
lineScanner = new Scanner(line);
if (lineScanner.hasNextInt()) numberOfFriends = lineScanner.nextInt();
if (lineScanner.hasNextInt()) heightOfFrence = lineScanner.nextInt();
lineScanner.close();
}
if (i == 1) {
line = scanner.nextLine();
lineScanner = new Scanner(line);
for (int j = 0; j < numberOfFriends; j++) {
int val = lineScanner.nextInt();
minValidWidth += val > heightOfFrence ? 2 : 1;
}
lineScanner.close();
}
}
scanner.close();
return minValidWidth;
}
public static void main(String args[]) {
System.out.println(caculate());
}
}
| Java | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | ab2e7545c4abc75dcacd0fc8fb3d28fc | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 256 megabytes | /* https://codeforces.com/contest/677/problem/A
idea: compare the height of each person with the height of fence.
*/
import java.util.Scanner;
public class VanyaAndFence {
static int caculate() {
Scanner scanner = new Scanner(System.in);
int numberOfFriends = scanner.nextInt();
int heightOfFence = scanner.nextInt();
int minValidWidth = 0;
for (int i=0; i < numberOfFriends; i++) {
int heightOfPerson = scanner.nextInt();
if (heightOfPerson > heightOfFence){
minValidWidth += 2;
} else {
minValidWidth += 1;
}
}
return minValidWidth;
}
public static void main(String args[]) {
System.out.println(caculate());
}
}
| Java | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | 9f77b0103ad904c2c6ade8ca3771af2b | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 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.
*/
import java.util.Scanner;
/**
*
* @author Mohamed Thulfkar
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
// System.out.println("enter the number of elements and the height at the same line");
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int height = s.nextInt();
int[] arr = new int[n] ;
// System.out.println("enter the elements of the array");
int sum = 0;
for (int i = 0; i < n; i++) {
arr[i] = s.nextInt();
if (arr[i] > height) {
sum+=2;
}
else {
sum++;
}
}
// System.out.println("width is "+sum);
System.out.println(sum);
}
}
| Java | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | eb37617f0ba07302323df8d1d8059f6e | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 256 megabytes | public class App
{
public static void main (String[] args)
{
java.util.Scanner input=new java.util.Scanner(System.in);
int n =input.nextInt();
int h =input.nextInt();
int min=0;
for (int i = 0; i < n; i++) {
int a=input.nextInt();
if (a>h) {
min +=2;
}
else
{
min ++;
}
}
System.out.println(min);
}
} | Java | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | 09315194667185d86e6f31f579b88ab9 | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 256 megabytes | import java.util.*;
import java.lang.*;
import java.io.*;
public class VanyaAndFence {
public static void main(String[] args)throws java.lang.Exception
{
int i;
String s;
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
try
{s = br.readLine();}
catch(Exception e)
{return;}
String srr[] = new String[2];
srr = s.split(" ");
int a1 = Integer.parseInt(srr[0]);
int a2 = Integer.parseInt(srr[1]);
String temp;
String arr[] = new String[a1];
/*for(i = 0 ; i < a1 ; i++)
{
arr[i] = br.readLine();
}*/
temp = br.readLine();
arr = temp.split(" ");
int total = 0;
for(i = 0 ; i < arr.length ; i++)
{
if(Integer.parseInt(arr[i])>a2)
{
total = total + 2;
}
else
total++;
}
System.out.println(total);
}
}
| Java | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | 80213fa0bb912ca8954c8b49abf59640 | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 256 megabytes | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
FastReader in = new FastReader();
int n = in.nextInt();
int h = in.nextInt();
int[] persons = new int[n];
for(int i =0 ; i < persons.length ; i++)
persons[i] = in.nextInt();
int counter = 0;
for(int person : persons){
if(person > h)
counter+=2;
else
counter++;
}
System.out.print(counter);
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
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 | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | bba14780d288b90064bc4cb757038180 | train_003.jsonl | 1464798900 | Vanya and his friends are walking along the fence of height h and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed h. If the height of some person is greater than h he can bend down and then he surely won't be noticed by the guard. The height of the i-th person is equal to ai.Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? | 256 megabytes |
import java.util.Arrays;
import java.util.Scanner;
public class Main {
private static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
solve();
}
private static void solve(){
int n = sc.nextInt();
int h = sc.nextInt();
int[] array = readArray(n);
int cnt = 0;
for (int x : array) {
if (x > h)
cnt += 2;
else
cnt++;
}
System.out.println(cnt);
}
private static int[] frequencyArray(int n , int[] arr){
int count[] = new int[n+1];
Arrays.stream(arr).forEach(x -> count[x]++);
return count;
}
private static int[] readArray(int n){
int arr[] = new int[n];
for(int i = 0 ; i < n ;i++){
arr[i] = sc.nextInt();
}
return arr;
}
}
| Java | ["3 7\n4 5 14", "6 1\n1 1 1 1 1 1", "6 5\n7 6 8 9 10 5"] | 1 second | ["4", "6", "11"] | NoteIn the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.In the third sample, all the persons have to bend, except the last one. The required minimum width of the road is equal to 2β+β2β+β2β+β2β+β2β+β1β=β11. | Java 8 | standard input | [
"implementation"
] | e7ed5a733e51b6d5069769c3b1d8d22f | The first line of the input contains two integers n and h (1ββ€βnββ€β1000, 1ββ€βhββ€β1000)Β β the number of friends and the height of the fence, respectively. The second line contains n integers ai (1ββ€βaiββ€β2h), the i-th of them is equal to the height of the i-th person. | 800 | Print a single integerΒ β the minimum possible valid width of the road. | standard output | |
PASSED | ec658a81427c1a98ce70c1c84c987560 | train_003.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.Collections;
import java.util.Comparator;
import java.util.Scanner;
import java.util.AbstractMap.SimpleEntry;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n, k;
n = sc.nextInt();
k = sc.nextInt();
ArrayList<SimpleEntry<Integer, Integer>> scores = new ArrayList<>();
for (int i = 0; i < n; i++) {
scores.add(new SimpleEntry<>(sc.nextInt(), sc.nextInt()));
}
Collections.sort(scores,
new Comparator<SimpleEntry<Integer, Integer>>() {
@Override
public int compare(SimpleEntry<Integer, Integer> e1,
SimpleEntry<Integer, Integer> e2) {
if (e1.getKey() > e2.getKey())
return 1;
else if (e1.getKey() < e2.getKey())
return -1;
else if (e1.getValue() < e2.getValue())
return 1;
else if (e1.getValue() > e2.getValue())
return -1;
else
return 0;
}
});
Collections.reverse(scores);
int counter = 0;
// System.out.println(scores);
// System.out.println(scores.get(k-1));
for (SimpleEntry<Integer, Integer> simpleEntry : scores) {
if (simpleEntry.equals(scores.get(k-1))) {
counter++;
}
}
System.out.println(counter);
}
}
| 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 7 | 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 | ae76d759a94ab39367baa3aea62e1050 | train_003.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.util.Arrays;
import java.util.StringTokenizer;
public class rankListA {
static class pairsrank implements Comparable<pairsrank> {
int prob;
int pen;
public pairsrank(int x, int y) {
prob = x;
pen = y;
}
public int compareTo(pairsrank o2) {
if (this.prob < o2.prob)
return 1;
else if (this.prob == o2.prob)
return this.pen - o2.pen;
else
return -1;
}
public String toString (){
return "("+this.prob+","+this.pen+")";
}
}
public static void main(String[] args) throws NumberFormatException,
IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(bf.readLine());
int t = Integer.parseInt(st.nextToken());
int r = Integer.parseInt(st.nextToken());
pairsrank[] a = new pairsrank[t];
for (int i = 0; i < a.length; i++) {
st = new StringTokenizer(bf.readLine());
a[i] = new pairsrank(Integer.parseInt(st.nextToken()),
Integer.parseInt(st.nextToken()));
}
Arrays.sort(a);
int num = 1;
int rank = 1;
//System.out.println(Arrays.toString(a));
for (int i = 0; i < a.length - 1; i++) {
if (a[i].compareTo(a[i + 1]) == 0) {
++num;
++rank;
}
if (a[i].compareTo(a[i + 1]) != 0) {
if (r <= rank) {
System.out.println(num);
break;
} else {
rank++;
num = 1;
}
}
if(i == a.length-2)
System.out.println(num);
}
if(a.length == 1)
System.out.println(1);
}
}
| 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 7 | 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 | aea9fb7510a523684d0921e4d3ec7ec6 | train_003.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.Scanner;
public class problemI {
void sorting(int arr[][],int n){
boolean swapped = true;
int j = 0;
int temp1;
int temp2;
while (swapped) {
swapped = false;
j++;
for (int i = 0; i < n - j; i++) {
if (arr[i][0] < arr[i + 1][0]) {
temp1 = arr[i+1][0];
arr[i+1][0] = arr[i][0];
arr[i][0] = temp1;
temp2 = arr[i+1][1];
arr[i+1][1] = arr[i][1];
arr[i][1] = temp2;
swapped = true;
}
else if(arr[i][0] == arr[i + 1][0]&& arr[i][1]>arr[i+1][1]){
temp1 = arr[i+1][0];
arr[i+1][0] = arr[i][0];
arr[i][0] = temp1;
temp2 = arr[i+1][1];
arr[i+1][1] = arr[i][1];
arr[i][1] = temp2;
swapped = true;
}
}
}
}
int BSfindFirst(int start, int end, int val,int arr[][]) {
while(start < end) {
int mid= start + (end-start)/2;
if(arr[mid][0] > val)
start= mid+1;
else if(arr[mid][0]< val)
end = mid-1;
else
end = mid;
}
return start;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
problemI p = new problemI();
Scanner in = new Scanner(System.in);
int n=in.nextInt();
int k=in.nextInt();
int arr[][]=new int[n][2];
for(int i=0;i<n;i++){
arr[i][0]=in.nextInt();
arr[i][1]=in.nextInt();
}
p.sorting(arr,n);
/* for(int i=0;i<n;i++){
System.out.print(arr[i][0]+" ");
System.out.println(arr[i][1]);
}*/
int start=p.BSfindFirst(0, n-1, arr[k-1][0], arr);
//System.out.println(start);
int counter=0;
for (int i = start; i < arr.length; i++) {
if(arr[i][0]==arr[k-1][0]&&arr[i][1]==arr[k-1][1]){
counter++;
}
else if(arr[i][0]!=arr[k-1][0])
break;
}
System.out.println(counter);
}
}
| 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 7 | 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 | 9d289235c20ef431e50278ae35b46cb9 | train_003.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 j
{
public static void main(String a[])throws IOException
{
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
int d[];
int e[];
int i=0,j=0,n=0,p=0,k=0,w=0,t=0,u=0,z=0;
String s;
String r[];
s=b.readLine();
StringTokenizer c=new StringTokenizer(s);
n=Integer.parseInt(c.nextToken());
k=Integer.parseInt(c.nextToken());
r=new String[n];
d=new int[n];
e=new int[n];
for(i=0;i<n;i++)
r[i]=b.readLine();
for(i=0;i<n;i++)
{
StringTokenizer f=new StringTokenizer(r[i]);
d[i]=Integer.parseInt(f.nextToken());
e[i]=Integer.parseInt(f.nextToken());
}
for(j=0;j<n-1;j++)
{
for(i=j+1;i<n;i++)
{
if(d[j]<d[i])
{
w=d[j];
d[j]=d[i];
d[i]=w;
w=e[j];
e[j]=e[i];
e[i]=w;
}
if((d[j]==d[i])&&(e[j]>e[i]))
{
w=d[j];
d[j]=d[i];
d[i]=w;
w=e[j];
e[j]=e[i];
e[i]=w;
}
}
}
t=d[k-1];
u=e[k-1];
for(i=0;i<n;i++)
{
if(d[i]==t&&e[i]==u)
z++;
}
System.out.print(z);
}
} | 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 7 | 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 | dff73c9e76c6fc99b681b5fb671aef02 | train_003.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.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.Vector;
public class Solution {
class Q implements Comparable<Q> {
int p, t;
Q(int q, int w) {
p = q; t = w;
}
@Override
public int compareTo(Q arg0) {
if (p == arg0.p) return t - arg0.t;
return arg0.p - p;
}
}
void solve() throws Exception {
int n = nextInt();
int k = nextInt() - 1;
Q[] a = new Q[n];
for (int i = 0; i < n; i++) a[i] = new Q(nextInt(), nextInt());
Arrays.sort(a);
int ans = 1;
for (int i = k - 1; i >= 0; i--) if (a[i].compareTo(a[k]) == 0) ans++; else break;
for (int i = k + 1; i < n; i++) if (a[i].compareTo(a[k]) == 0) ans++; else break;
out.println(ans);
}
public static void main(String[] args) {
new Solution().run();
}
public void run() {
try {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
} finally {
out.close();
}
}
String nextToken() throws Exception {
while (st == null || !st.hasMoreTokens()) {
String s = in.readLine();
if (s == null) return null;
st = new StringTokenizer(s);
}
return st.nextToken();
}
int nextInt() throws Exception {
return Integer.parseInt(nextToken());
}
BufferedReader in;
PrintWriter out;
StringTokenizer st;
}
| 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 7 | 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 | 263c309cf124f874554bf599bb5e59b3 | train_003.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.util.StringTokenizer;
public class RankList {
static short[] prob;static short[] penalty; static short last=0;
static short []result;
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(bf.readLine());
short n = Short.parseShort(st.nextToken());
short k = Short.parseShort(st.nextToken());
prob=new short[n];
penalty=new short[n];
result=new short[n];
for (short i = 0; i < n; i++) {
st = new StringTokenizer(bf.readLine());
prob[i]=Short.parseShort(st.nextToken());
penalty[i]=Short.parseShort(st.nextToken());
}
sort(); int count=1;short plast=prob[0]; short tlast=penalty[0];
int place=0; int i=1;
while (true) {
while (i< penalty.length && prob[i]== plast && penalty[i] == tlast){
++count;++i;
}
if(i < penalty.length){
plast=prob[i];
tlast=penalty[i];++i;
}
if(k <= place + count){
System.out.println(count);return;
}
place+=count;
count=1;
}
}
public static void sort (){
for (int i = 0; i < penalty.length-1; i++) {// selectio sort
int pmax=i;
for (int j = i+1; j < penalty.length; j++) {
if( prob[pmax] < prob[j] || prob[pmax] == prob[j] && penalty[pmax] > penalty[j]){
pmax=j;
}
}
short ptmp=prob[i];
prob[i]=prob[pmax];
prob[pmax]=ptmp;
ptmp=penalty[i];
penalty[i]=penalty[pmax];
penalty[pmax]=ptmp;
}
}
// public static void insert(short p,short t){
// if(last==0){
// prob[0]=p;penalty[0]=t;++last;
// result[0]=1;return;
// }
// int i;
// for (i = last;i>0; i--) {
// if(p > prob[i-1]){
// prob[i]=prob[i-1];
// penalty[i]=penalty[i-1];
// result[i]=result[i-1];
// }
// else if(p == prob[i-1]){
// if(penalty[i-1] > t){
// prob[i]=prob[i-1];
// penalty[i]=penalty[i-1];
// result[i]=result[i-1];
// }
// else if(penalty[i-1] < t){
// prob[i]=p;
// penalty[i]=t;
// result[i]=1;
// ++last;
// return;
// }
// else{
// result[i-1]++;return;
// }
// }
// else{
// prob[i]=p;
// penalty[i]=t;
// result[i]=1;
// ++last;return;
//
// }
//
// }
// prob[0]=p;
// penalty[0]=t;
// result[0]=1;
// ++last;
//
// }
}
| 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 7 | 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 | 596d6663bc2ed9bfeddb15ed8a6bd752 | train_003.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.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Task166A {
public static void main(String... args) throws NumberFormatException,
IOException {
Solution.main(System.in, System.out);
}
static class Solution {
public static void main(InputStream is, OutputStream os)
throws NumberFormatException, IOException {
PrintWriter pw = new PrintWriter(os);
Scanner s = new Scanner(is);
int n = s.nextInt();
int k = s.nextInt();
ArrayList<Integer> results = new ArrayList<>();
for(int i = 0 ; i < n ; i++){
results.add(s.nextInt() * 100 - s.nextInt());
}
Collections.sort(results);
int retVal = 0;
for(int result:results){
if(result == results.get(results.size()-k)){
retVal++;
}
}
pw.write(retVal+"");
pw.flush();
s.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 7 | 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 | 503c587db2a2f34c119aba068a29439f | train_003.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.*;
public class practice {
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
rank[] ranks = new rank[n];
for(int i = 0; i < n; i++) {
ranks[i] = new rank(in.nextInt(), in.nextInt());
}
Arrays.sort(ranks);
int count = 0;
for(int i = 0; i < n; i++) {
if(ranks[i].compareTo(ranks[k - 1]) == 0) count++;
}
System.out.println(count);
/*StringBuilder sb = new StringBuilder();
for (int i=0; i<a; i++){
sb.append(nums[i]);
if(i != a - 1) {
sb.append(' ');
}
}
System.out.println(sb.toString());*/
}
static class rank implements Comparable<rank> {
int problems;
int time;
public rank(int p, int t) {
problems = p;
time = t;
}
@Override public int compareTo(rank r) {
if(problems != r.problems) {
return r.problems - problems;
}
return time - r.time;
}
}
} | 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 7 | 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 | ce8d513578b0481046157751045151a5 | train_003.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.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
st = new StringTokenizer(in.readLine());
int n = Integer.parseInt(st.nextToken()),
k = Integer.parseInt(st.nextToken());
ArrayList<Pair> A = new ArrayList<Pair>();
for (int i = 0 ; i < n ; i++) {
st = new StringTokenizer(in.readLine());
A.add(new Pair(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken())));
}
Collections.sort(A, new MyCmp());
int ans = 1;
for (int i = k ; i < n && A.get(i).x == A.get(k - 1).x && A.get(i).y == A.get(k - 1).y ; i++) {
ans++;
}
for (int i = k - 2 ; i >= 0 && A.get(i).x == A.get(k - 1).x && A.get(i).y == A.get(k - 1).y; i--) {
ans++;
}
System.out.println(ans);
}
static class Pair {
int x, y;
Pair(int a, int b) {
x = a;
y = b;
}
}
static class MyCmp implements Comparator<Pair> {
public int compare(Pair A, Pair B) {
if (A.x < B.x || (A.x == B.x && A.y > B.y)) return 1;
else if (A.x == B.x && A.y == B.y) return 0;
else return -1;
}
}
}
| 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 7 | 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 | 1d26223002786aded2b4ae5b1a3f84a4 | train_003.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.*;
public class Main {
public static void main(String[] args) {
Main p = new Main();
p.solve();
}
public void solve(){
int n, k;
Scanner in = new Scanner(System.in);
n = in.nextInt();
k = in.nextInt();
Team[] m = new Team[n];
for(int i = 0; i < n; i++){
m[i] = new Team(in.nextInt(), in.nextInt());
}
Arrays.sort(m, new Comparator<Team>(){
public int compare(Team a, Team b){
if(a.pn != b.pn)
return b.pn - a.pn;
else
return a.tn - b.tn;
}
});
int pn = m[k - 1].pn, tn = m[k - 1].tn;
//System.out.println(higherBound(m, pn, tn));
//System.out.println(lowerBound(m, pn, tn));
//for(int i = 0; i < m.length; i++){
// System.out.print(m[i].pn + " " + m[i].tn + ", ");
// }
//System.out.println();
System.out.println(higherBound(m, pn, tn) - lowerBound(m, pn, tn) + 1);
}
public int lowerBound(Team[] arr, int pn, int tn){
int low = 0, high = arr.length - 1, mid, best = -1;
while(low <= high){
mid = low + ((high - low) >> 1);
//System.out.println("pn, tn: " + arr[mid].pn + ", " + arr[mid].tn + " mid: " + mid + ", pn, tn: " + pn + ", " + tn);
if(arr[mid].pn <= pn){
if(arr[mid].pn == pn && arr[mid].tn < tn){
low = mid + 1;
continue;
}
best = mid;
high = mid - 1;
}
else{
low = mid + 1;
}
}
return best;
}
public int higherBound(Team[] arr, int pn, int tn){
int low = 0, high = arr.length - 1, mid, best = -1;
while(low <= high){
mid = low + ((high - low) >> 1);
if(arr[mid].pn >= pn){
if(arr[mid].pn == pn && arr[mid].tn > tn){
high = mid - 1;
continue;
}
best = mid;
low = mid + 1;
}
else{
high = mid - 1;
}
}
return best;
}
}
class Team{
int pn = 0, tn = 0;
public Team(int pp, int tt){
pn = pp;
tn = tt;
}
}
| 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 7 | 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 | 61f69d7860b8c83b248b2b5938a3a60c | train_003.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.Scanner;
public class Task166A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int[] pt = new int[n];
for (int i = 0; i < n; i++) {
pt[i] = sc.nextInt() * 100 + 50 - sc.nextInt();
}
sc.close();
Arrays.sort(pt);
int c = 0;
for (int i = n - 1; i >= 0; i--) {
if (pt[i] == pt[n - k]) {
c++;
}
if (pt[i] < pt[n - k]) {
break;
}
}
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 7 | 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 | 7a9af164897fa26cc93176edb853d9e6 | train_003.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.util.Arrays;
public class Main {
static int[ ] readInts( String a ) {
String cad[] = a.split( " " );
int arr[] = new int[ cad.length ];
for ( int i = 0; i < arr.length; i++ ) {
arr[ i ] = Integer.parseInt( cad[ i ] );
}
return arr;
}
public static class Casilla implements Comparable<Casilla>{
int res;
int penalty;
public Casilla ( int res, int penalty ) {
this.res = res;
this.penalty = penalty;
}
@Override
public int compareTo( Casilla o ) {
if (res<o.res)return 1;
if (res>o.res)return -1;
if(penalty>o.penalty)return 1;
return -1;
}
public String toString(){
return res+" "+penalty;
}
}
public static void main( String[ ] args ) throws IOException {
BufferedReader in = new BufferedReader( new InputStreamReader( System.in ) );
String line=in.readLine( );
int arr[]=readInts(line);
Casilla cad[]=new Casilla[arr[0]];
int c[];
for ( int i = 0; i < cad.length; i++ ) {
c=readInts(in.readLine( ));
cad[i]=new Casilla( c[0], c[1] );
}
Arrays.sort( cad );
int k=arr[1]-2;
int k2=arr[1];
int sum=0;
while(k>=0 && cad[k].res == cad[arr[1]-1].res && cad[k].penalty == cad[arr[1]-1].penalty){
k--;
sum++;
}
while(k2<cad.length && cad[k2].res == cad[arr[1]-1].res && cad[k2].penalty == cad[arr[1]-1].penalty){
k2++;
sum++;
}
System.out.println(++sum);
}
}
| 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 7 | 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 | dae8d40e5f474253925a97071009e8cc | train_003.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.lang.*;
import java.io.*;
import java.util.*;
public class Rank {
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);
TaskA solver = new TaskA();
solver.solve(in, out);
out.close();
}
}
class TaskA {
public void solve(InputReader in, PrintWriter out) {
int n = in.nextInt(), k = in.nextInt() - 1;
int ans = 0;
Node[] a = new Node[n];
int i, j;
for (i=0; i<n; ++i)
a[i] = new Node(in.nextInt(), in.nextInt());
Arrays.sort(a);
Node x = a[k];
// for (i=0; i<n; ++i)
// out.println(a[i].p + " " + a[i].t);
ans = 1;
i = k-1;
while (i>=0 && x.equals(a[i])) {
--i;
++ans;
}
i = k+1;
while (i<n && x.equals(a[i])) {
++i;
++ans;
}
out.println(ans);
}
}
class Node implements Comparable<Node> {
int p, t;
public Node(int p, int t) {
this.p = p;
this.t = t;
}
public int compareTo(Node o) {
if (p == o.p)
return t - o.t;
return o.p - p;
}
public boolean equals(Node o) {
return o.p==p && o.t==t;
}
}
class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
| Java | ["7 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 7 | 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 | a7343edbd77ac43b2a6a0ad93715e2ea | train_003.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.Arrays;
import java.util.Scanner;
public class A {
public static void main(String[] args){
new A().go();
}
private void go() {
Scanner in = new Scanner(System.in);
int n=in.nextInt(),k=in.nextInt();
int[] list = new int[n];
for(int i=0;i<n;i++){
list[i] = (in.nextInt()*1000 - in.nextInt());
}
Arrays.sort(list);
int val = list[n-k];
int count = 1;
int index = n-k+1;
while(index<n && list[index]==val){
count++;
index++;
}
index = n-k-1;
while(index>=0 && list[index]==val){
count++;
index--;
}
System.out.println(count);
}
}
| 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 7 | 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 | e3915ec68a356c083d2d7f07044f7fa0 | train_003.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;
public class RankList {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] l1 = br.readLine().split("\\s+");
int n = Integer.parseInt(l1[0]);
int kth = Integer.parseInt(l1[1]);
int[] solved = new int[n];
int[] penality = new int[n];
for (int i = 0; i < n; i++) {
String[] l2 = br.readLine().split("\\s+");
solved[i] = Integer.parseInt(l2[0]);
penality[i] = Integer.parseInt(l2[1]);
}
int temp1, temp2;
for (int i = 1; i < n; i++)
for (int j = 0; j < i; j++) {
if (solved[i] > solved[j]) {
temp1 = solved[j];
solved[j] = solved[i];
solved[i] = temp1;
temp2 = penality[j];
penality[j] = penality[i];
penality[i] = temp2;
} else if (solved[i] == solved[j] && penality[i] < penality[j]) {
temp1 = solved[j];
solved[j] = solved[i];
solved[i] = temp1;
temp2 = penality[j];
penality[j] = penality[i];
penality[i] = temp2;
}
}
int numTeams = 0, tpSolved = 0, tpPenality = 0;
tpSolved = solved[kth - 1];
tpPenality = penality[kth - 1];
for (int i = 0; i < n; i++)
if (solved[i] == tpSolved && penality[i] == tpPenality)
numTeams++;
System.out.println(numTeams);
}
}
| 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 7 | 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 | 6106e6a1ac34c18261470b8fa319d0e7 | train_003.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 CF113A {
private static BufferedReader br;
private static StringTokenizer st;
private static PrintWriter pw;
// private static Timer t = new Timer();
public CF113A() throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(System.out);
}
String next() throws IOException {
while (st == null || !st.hasMoreElements())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
boolean hasNext() {
if (st != null && st.hasMoreElements())
return true;
try {
while (st == null || !st.hasMoreElements())
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
return false;
}
return true;
}
String nextLine() throws IOException {
return br.readLine();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
double nextDouble() throws IOException {
return Double.parseDouble(next().replace(',', '.'));
}
boolean nextBool() throws IOException {
String s = next();
if (s.equalsIgnoreCase("true") || s.equals("1"))
return true;
if (s.equalsIgnoreCase("false") || s.equals("0"))
return false;
throw new IOException("Boolean expected, String found!");
}
public static int S(long x) {
int sum = 0;
while (x != 0) {
sum += x % 10;
x /= 10;
}
return sum;
}
public static void swap(int[] A, int a, int b) {
int temp = A[a];
A[a] = A[b];
A[b] = temp;
}
void solve() throws IOException {
int n = nextInt();
int k = nextInt();
int[][] A = new int[51][51];
for (int i = 0; i < n; i++) {
A[nextInt()][nextInt()]++;
}
for (int i = 50; i >= 0; i--) {
for (int j = 0; j < 51; j++) {
k = k - A[i][j];
if (k <= 0) {
pw.println(A[i][j]);
pw.flush();
return;
}
}
}
}
public static void main(String[] args) throws IOException {
new CF113A().solve();
}
}
| 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 7 | 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 | c5e0ad13bc61cbb947890f1b19064c7f | train_003.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 CF113A {
private static BufferedReader br;
private static StringTokenizer st;
private static PrintWriter pw;
// private static Timer t = new Timer();
public CF113A() throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(System.out);
}
String next() throws IOException {
while (st == null || !st.hasMoreElements())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
boolean hasNext() {
if (st != null && st.hasMoreElements())
return true;
try {
while (st == null || !st.hasMoreElements())
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
return false;
}
return true;
}
String nextLine() throws IOException {
return br.readLine();
}
int nextInt() throws IOException {
return Integer.parseInt(next());
}
long nextLong() throws IOException {
return Long.parseLong(next());
}
double nextDouble() throws IOException {
return Double.parseDouble(next().replace(',', '.'));
}
boolean nextBool() throws IOException {
String s = next();
if (s.equalsIgnoreCase("true") || s.equals("1"))
return true;
if (s.equalsIgnoreCase("false") || s.equals("0"))
return false;
throw new IOException("Boolean expected, String found!");
}
public static int S(long x) {
int sum = 0;
while (x != 0) {
sum += x % 10;
x /= 10;
}
return sum;
}
public static void swap(int[] A, int a, int b) {
int temp = A[a];
A[a] = A[b];
A[b] = temp;
}
void solve() throws IOException {
int n = nextInt();
int k = nextInt();
int[][] A = new int[51][51];
for (int i = 0; i < n; i++) {
A[nextInt()][nextInt()]++;
}
int a = 0;
for (int i = 50; i >= 0; i--) {
for (int j = 0; j < 51; j++) {
k = k - A[i][j];
if (k <= 0) {
pw.println(A[i][j]);
pw.flush();
return;
}
}
}
// pw.flush();
}
public static void main(String[] args) throws IOException {
new CF113A().solve();
}
}
| 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 7 | 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 | afe3742a58673213081c44e8d7659c23 | train_003.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 Solution {
private static void solve(InputReader in, OutputWriter out) {
int n, k;
n = in.nextInt();
k = in.nextInt();
int[][] a = new int[n][2];
for (int i = 0; i < n; i++) {
a[i][0] = in.nextInt();
a[i][1] = in.nextInt();
}
Arrays.sort(a, new Comparator<int[]>() {
@Override
public int compare(int[] o1, int[] o2) {
if (o1[0] > o2[0])
return 1;
else if (o1[0] < o2[0])
return -1;
else {
if (o1[1] < o2[1])
return 1;
else if (o1[1] > o2[1])
return -1;
else
return 0;
}
}
});
int cnt = 0;
for (int i = 0; i < n; i++)
if (a[i][0] == a[n-k][0] && a[i][1] == a[n-k][1]) cnt++;
out.print(cnt);
}
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
OutputWriter out = new OutputWriter(System.out);
solve(in, out);
in.close();
out.close();
}
private static class InputReader {
private BufferedReader br;
private StringTokenizer st;
InputReader(InputStream is) {
br = new BufferedReader(new InputStreamReader(is));
st = null;
}
String nextLine() {
String line = null;
try {
line = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return line;
}
String next() {
while (st == null || !st.hasMoreTokens()) {
String line = nextLine();
if (line == null) return null;
st = new StringTokenizer(line);
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
void close() {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
private static class OutputWriter {
BufferedWriter bw;
OutputWriter(OutputStream os) {
bw = new BufferedWriter(new OutputStreamWriter(os));
}
void print(int i) {
print(Integer.toString(i));
}
void println(int i) {
println(Integer.toString(i));
}
void print(long l) {
print(Long.toString(l));
}
void println(long l) {
println(Long.toString(l));
}
void print(double d) {
print(Double.toString(d));
}
void println(double d) {
println(Double.toString(d));
}
void print(boolean b) {
print(Boolean.toString(b));
}
void println(boolean b) {
println(Boolean.toString(b));
}
void print(char c) {
try {
bw.write(c);
} catch (IOException e) {
e.printStackTrace();
}
}
void println(char c) {
println(Character.toString(c));
}
void print(String s) {
try {
bw.write(s);
} catch (IOException e) {
e.printStackTrace();
}
}
void println(String s) {
print(s);
print('\n');
}
void close() {
try {
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
| 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 7 | 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 | fabcae9f15f9ac5b23e37bb834fea9fc | train_003.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.*;
public class P166A {
class Team implements Comparable<Team> {
int probs, time;
Team(int p, int t) {
probs = p;
time = t;
}
public int compareTo(Team that) {
if (probs == that.probs)
return Integer.signum(time - that.time);
return Integer.signum(that.probs - probs);
}
public String toString() {
return probs + " " + time;
}
}
P166A(Scanner in) {
int N = in.nextInt();
int K = in.nextInt();
Team[] teams = new Team[N];
for (int i=0; i<N; i++)
teams[i] = new Team(in.nextInt(), in.nextInt());
Arrays.sort(teams);
int s = K-1;
int e = K-1;
while(s-1>=0 && teams[s-1].compareTo(teams[K-1]) == 0)
s--;
while(e+1<N && teams[e+1].compareTo(teams[K-1]) == 0)
e++;
System.out.println(e-s+1);
}
public static void main(String[] args) {
new P166A(new Scanner(System.in));
}
}
| 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 7 | 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 | 7778f262cab5719d00e2b189d910d7f1 | train_003.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.Scanner;
public class RankList {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
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();
}
int c=0;
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(a[i][0]<a[j][0])
{
c=a[i][0];
a[i][0]=a[j][0];
a[j][0]=c;
c=a[i][1];
a[i][1]=a[j][1];
a[j][1]=c;
}
if((a[i][0]==a[j][0])&&a[i][1]>=a[j][1])
{
c=a[i][0];
a[i][0]=a[j][0];
a[j][0]=c;
c=a[i][1];
a[i][1]=a[j][1];
a[j][1]=c;
}
}
}
//
// System.out.println("---------------------");
//
// for(int i=0;i<n;i++)
// System.out.println(a[i][0]+" "+a[i][1]);
int count=1;
k=k-1;
for(int i=k;i<n-1;i++)
{
if((a[i][0]==a[i+1][0])&&(a[i][1]==a[i+1][1]))
count++;
else
break;
}
for(int i=k;i>0;i--)
{
if((a[i][0]==a[i-1][0])&&(a[i][1]==a[i-1][1]))
count++;
else
break;
}
System.out.println(count);
}
}
| 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 7 | 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 | 3d147916030bc54c183b6af3f1c9d076 | train_003.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.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author KHALED
*/
public class RankList {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
int k=scan.nextInt();
int[][]arr=new int[n][2];
for (int i = 0; i < n; i++)
{
int a=scan.nextInt();
int b=scan.nextInt();
arr[i][0]=a;
arr[i][1]=b;
// if(arr.length==0)
// {
// arr[0][0]=a;
// arr[0][1]=b;
// index++;
// }
// else
// {
// boolean fond=false;
// for (int j = 0; j < index; j++)
// {
// if(arr[j][0]==a&&arr[j][1]==b)
// {
// fond =true;
// if(arr[j][2]==0)
// arr[j][2]+=2;
// else
// arr[j][2]++;
// break;
// }
// }
// if(!fond)
// {
// arr[index][0]=a;
// arr[index][1]=b;
// index++;
// }
// }
}
for (int i = 0; i < n; i++)
{
for (int j = i; j < n; j++)
{
if(arr[i][0]<arr[j][0]||(arr[i][0]==arr[j][0]&&arr[i][1]>arr[j][1]))
{
int temp=arr[i][0];
arr[i][0]=arr[j][0];
arr[j][0]=temp;
temp=arr[i][1];
arr[i][1]=arr[j][1];
arr[j][1]=temp;
}
}
}
int a=arr[k-1][0];
int b=arr[k-1][1];
int count=0;
for (int j = 0; j < n; j++)
{
if(arr[j][0]==a&&arr[j][1]==b)
{
count++;
}
}
// for (int i = 0; i < n; i++)
// {
// System.out.println(arr[i][0]+" "+arr[i][1]+" "+arr[i][2]);
// }
System.out.println(count);
}
}
| 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 7 | 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 | 7d9825eea10462d372912151f41b0035 | train_003.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.*;
import java.math.*;
// 4/26/12 2:30 PM
// by Abrackadabra
public class A {
public static void main(String[] args) throws IOException {
if (args.length > 0 && args[0].equals("Abra")) debugMode = true;
new A().run();
/*new Thread(null, new Runnable() {
public void run() {
try {
new Test().run();
} catch (IOException e) {
e.printStackTrace();
}
}
}, "1", 1 << 24).start();*/
}
int IOMode = 0; //0 - consoleIO, 1 - <taskName>.in/out, 2 - input.txt/output.txt, 3 - test case generator
String taskName = "";
class Team implements Comparable<Team> {
int solved;
int time;
Team(int solved, int time, int index) {
this.solved = solved;
this.time = time;
this.index = index;
}
int index;
@Override
public int compareTo(Team o) {
if (solved != o.solved) return -Integer.compare(solved, o.solved);
if (time != o.time) return Integer.compare(time, o.time);
return Integer.compare(index, o.index);
}
}
void solve() throws IOException {
int n = nextInt(), k = nextInt();
ArrayList<Team> teams = new ArrayList<Team>();
for (int i = 0; i < n; i++) {
teams.add(new Team(nextInt(), nextInt(), i));
}
Collections.sort(teams);
int res = 0;
for (int i = 0; i < n; i++) {
if (teams.get(i).solved == teams.get(k - 1).solved && teams.get(i).time == teams.get(k - 1).time)
res++;
}
out.println(res);
}
long startTime = System.nanoTime(), tempTime = startTime, finishTime = startTime;
long startMem = Runtime.getRuntime().totalMemory(), finishMem = startMem;
void run() throws IOException {
init();
if (debugMode) {
con.println("Start");
con.println("Console:");
}
solve();
finishTime = System.nanoTime();
finishMem = Runtime.getRuntime().totalMemory();
out.flush();
if (debugMode) {
int maxSymbols = 1000;
BufferedReader tbr = new BufferedReader(new FileReader("input.txt"));
char[] a = new char[maxSymbols];
tbr.read(a);
if (a[0] != 0) {
con.println("File input:");
con.println(a);
if (a[maxSymbols - 1] != 0) con.println("...");
}
tbr = new BufferedReader(new FileReader("output.txt"));
a = new char[maxSymbols];
tbr.read(a);
if (a[0] != 0) {
con.println("File output:");
con.println(a);
if (a[maxSymbols - 1] != 0) con.println("...");
}
con.println("Execution time: " + (finishTime - startTime) / 1000000000.0 + " sec");
con.println("Used memory: " + (finishMem - startMem) + " bytes");
con.println("Total memory: " + Runtime.getRuntime().totalMemory() + " bytes");
}
}
boolean tick(double x) {
if (System.nanoTime() - tempTime > x * 1e9) {
tempTime = System.nanoTime();
con.println("Tick at " + (tempTime - startTime) / 1000000000 + " sec");
con.print(" ");
return true;
}
return false;
}
static boolean debugMode = false;
PrintStream con = System.out;
void init() throws IOException {
if (debugMode && IOMode != 3) {
br = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter(new FileWriter("output.txt"));
} else
switch (IOMode) {
case 0:
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
break;
case 1:
br = new BufferedReader(new FileReader(taskName + ".in"));
out = new PrintWriter(new FileWriter(taskName + ".out"));
break;
case 2:
br = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter(new FileWriter("output.txt"));
break;
case 3:
out = new PrintWriter(new FileWriter("input.txt"));
break;
}
if (!debugMode)
con = new PrintStream(new OutputStream() {
public void write(int b) throws IOException {
} // to /dev/null
});
if ((IOMode == 1 && taskName.length() == 0) || (IOMode != 1 && taskName.length() != 0)) {
System.err.println("Leha, check IO settings");
System.err.flush();
System.exit(0);
}
}
BufferedReader br;
PrintWriter out;
StringTokenizer in;
boolean hasMoreTokens() throws IOException {
while (in == null || !in.hasMoreTokens()) {
String line = br.readLine();
if (line == null) return false;
in = new StringTokenizer(line);
}
return true;
}
String nextString() throws IOException {
return hasMoreTokens() ? in.nextToken() : null;
}
int nextInt() throws IOException {
return Integer.parseInt(nextString());
}
long nextLong() throws IOException {
return Long.parseLong(nextString());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextString());
}
} | 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 7 | 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 | 5c1788b781df37098bca53566be474e4 | train_003.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.Scanner;
public class RankList {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] p = new int[n];
int[] t = new int[n];
int k = sc.nextInt();
for (int i = 0; i < t.length; i++) {
p[i] = sc.nextInt();
t[i] = sc.nextInt();
}
Final[] f = new Final[n];
for (int i = 0; i < f.length; i++) {
f[i] = new Final(p[i], t[i]);
}
--k;
Arrays.sort(f);
int res = 0;
for (int i = k + 1; i < f.length; i++) {
if (f[i].compareTo(f[k]) == 0) {
++res;
}
}
for (int i = k - 1; i >= 0; i--) {
if (f[i].compareTo(f[k]) == 0) {
++res;
}
}
System.out.println(res + 1);
}
static class Final implements Comparable<Final> {
int p;
int t;
public Final(int p, int t) {
this.p = p;
this.t = t;
}
public int compareTo(Final o) {
if (p == o.p) {
return t - o.t;
}
return -(p - o.p);
}
}
}
| 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 7 | 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 | 9982ceb960120de5c13e7f3b4af98a80 | train_003.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.math.BigInteger;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException,
NumberFormatException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n=Integer.parseInt(st.nextToken());
int k=Integer.parseInt(st.nextToken());
pair1 []teams=new pair1[n];
for(int i=0;i<teams.length;i++){
st=new StringTokenizer(br.readLine());
teams[i]=new pair1(Integer.parseInt(st.nextToken()),Integer.parseInt(st.nextToken()));
}
Arrays.sort(teams);
boolean flag=false;
int rank=1;
int ans=1;
for(int i=k-1;i>0;i--){
if(teams[i].x==teams[i-1].x&&teams[i].y==teams[i-1].y)ans++;
else break;
}
for(int i=k-1;i<teams.length-1;i++){
if(teams[i].x==teams[i+1].x&&teams[i].y==teams[i+1].y)ans++;
else break;
}
System.out.println(ans);
}
}
class pair1 implements Comparable{
int x,y;
public pair1(int x,int y){
this.x=x;
this.y=y;
}
public int compareTo(Object o){
pair1 p=(pair1)o;
if(this.x>p.x)return -1;
if(this.x<p.x)return 1;
else{
if(this.y==p.y)return 0;
else if(this.y>p.y)return 1;
else return -1;
}
}
} | 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 7 | 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 | 15c789956a07b48715f3aa5817ca082a | train_003.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.IOException;
import java.util.Scanner;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Computragy
*/
public class RankList {
public static void main(String[] args) throws IOException {
Scanner cs = new Scanner(System.in);
int num = cs.nextInt();
int place = cs.nextInt() -1;
Ranks[] arr = new Ranks[num];
for(int i=0 ; i<num ; i++)
{
int prob = cs.nextInt();
int penal = cs.nextInt();
arr[i] = new Ranks(prob, penal);
}
java.util.Arrays.sort(arr);
int count = 0;
for(int x = 0; x<num;x++)
{
if(arr[place].problems == arr[x].problems && arr[place].penalty == arr[x].penalty)
{
count++;
}
}
System.out.println(count);
}
public static class Ranks implements Comparable<Ranks>
{
int problems ;
int penalty ;
public Ranks(int problems, int penalty) {
this.problems = problems;
this.penalty = penalty;
}
@Override
public int compareTo(Ranks o) {
if(this.problems > o.problems)
{
return -1;
}
else if (this.problems == o.problems && this.penalty <= o.penalty)
{
return -1;
}
else
{
return 1;
}
}
}
}
| 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 7 | 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 | 465612e39e97e8c8fb35a3dd15f879bc | train_003.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.*;
public class Rank {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n=in.nextInt();
int k=in.nextInt();
ArrayList<Integer> a = new ArrayList<Integer>();
for(int i=0;i<n;i++)
{
a.add(in.nextInt()*100+51-in.nextInt());
}
Collections.sort(a, Collections.reverseOrder());
System.out.println(a.lastIndexOf(a.get(k-1))-a.indexOf(a.get(k-1))+1);
}
}
| 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 7 | 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 | 7bdfb2b61c7312f6d7f5fe65fd65cd60 | train_003.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.Scanner;
public class RankList {
public static void main(String asd[])throws Exception
{
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int k=in.nextInt();
int a[]=new int[n];
int b[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=in.nextInt();
b[i]=in.nextInt();
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n-1-i;j++)
{
if(a[j]<a[j+1])
{
int kk=a[j];
a[j]=a[j+1];
a[j+1]=kk;
kk=b[j];
b[j]=b[j+1];
b[j+1]=kk;
}
else if(a[j]==a[j+1] && b[j]>b[j+1])
{
int kk=b[j];
b[j]=b[j+1];
b[j+1]=kk;
}
}
}
int c=0,i=k-2,j=k;
while(i>=0 && a[i]==a[k-1] && b[i]==b[k-1])
{
c++;
i--;
}
while(j<n && a[j]==a[k-1] && b[j]==b[k-1])
{
c++;
j++;
}
System.out.println(c+1);
}
}
| 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 7 | 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 | fd7ca465502a752e0df926cee8a4ed93 | train_003.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.util.Arrays;
public class Rank {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String[] arg = in.readLine().split(" ");
int n = Integer.parseInt(arg[0]);
int k = Integer.parseInt(arg[1]);
int maxT = 0;
int[][] data = new int[n][2];
for(int i=0; i<n; i++){
String[] q = in.readLine().split(" ");
data[i][0] = Integer.parseInt(q[0]);
data[i][1] = Integer.parseInt(q[1]);
if(data[i][0]>maxT)
maxT = data[i][0]+1;
}
int[] total = new int[n];
for(int i=0; i<n; i++){
total[i] = maxT*data[i][0]+maxT-data[i][1];
}
Arrays.sort(total);
int rank = total[n-k];
int s = 1;
int i=n-k-1;
while(i>=0 && total[i]==rank){
s++;
i--;
}
i=n-k+1;
while(i<n && total[i]==rank){
s++;
i++;
}
System.out.println(s);
}
}
| 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 7 | 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.