exec_outcome
stringclasses
1 value
code_uid
stringlengths
32
32
file_name
stringclasses
111 values
prob_desc_created_at
stringlengths
10
10
prob_desc_description
stringlengths
63
3.8k
prob_desc_memory_limit
stringclasses
18 values
source_code
stringlengths
117
65.5k
lang_cluster
stringclasses
1 value
prob_desc_sample_inputs
stringlengths
2
802
prob_desc_time_limit
stringclasses
27 values
prob_desc_sample_outputs
stringlengths
2
796
prob_desc_notes
stringlengths
4
3k
βŒ€
lang
stringclasses
5 values
prob_desc_input_from
stringclasses
3 values
tags
sequencelengths
0
11
src_uid
stringlengths
32
32
prob_desc_input_spec
stringlengths
28
2.37k
βŒ€
difficulty
int64
-1
3.5k
βŒ€
prob_desc_output_spec
stringlengths
17
1.47k
βŒ€
prob_desc_output_to
stringclasses
3 values
hidden_unit_tests
stringclasses
1 value
PASSED
a86e788925908556fd8873405496ae27
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.util.*; public class Main { public static void main(String[] args){ Scanner input = new Scanner(System.in); int n = input.nextInt(); int m = input.nextInt(); int a[] = new int[n]; long sum=0; for (int i = 0; i < n; i++) { a[i] = input.nextInt(); sum+=a[i]; } sum+=(n-1); if(sum==m) System.out.println("YES"); else System.out.println("NO"); } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
0062dde7e94165137d997bc8078ece50
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.util.*; public class Japanese_crossword { public static void main(String a[]){ Scanner s = new Scanner(System.in); int n = s.nextInt(); long x = s.nextLong(); int[] arr = new int[n]; for(int i=0;i<n;i++){ arr[i] = s.nextInt(); } if(arr.length==1 && arr[0]==x){ System.out.println("YES"); } else if(arr.length==0){ System.out.println("YES"); } else if(arr.length>0){ int sum = 0; for(int i=0;i<n;i++){ sum = sum + arr[i]; } if(sum+n-1 == x){ System.out.println("YES"); }else{ System.out.println("NO"); } } else{ System.out.println("YES"); } } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
e71ac66f7bddd16e1f09ef8c0058a15d
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.util.*; public class Japanese_crossword { public static void main(String a[]){ Scanner s = new Scanner(System.in); int n = s.nextInt(); long x = s.nextLong(); int[] arr = new int[n]; for(int i=0;i<n;i++){ arr[i] = s.nextInt(); } if(arr.length==1 && arr[0]==x){ System.out.println("YES"); } else if(arr.length==0){ System.out.println("YES"); } else if(arr.length>0){ int sum = 0; for(int i=0;i<n;i++){ sum = sum + arr[i]; } if(sum+n-1 == x){ System.out.println("YES"); }else{ System.out.println("NO"); } } else{ System.out.println("YES"); } } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
35078570d5ccf529216d90971272c592
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner in; in = new Scanner(System.in); int n, x; n = in.nextInt(); x = in.nextInt(); int tot = 0; for(int i=1; i<=n; i++) { int u; u = in.nextInt(); tot += u; } if(tot + n - 1 == x) System.out.println("YES"); else System.out.println("NO"); } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
4df14c4a36f5db5692b7e7483694829d
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.util.Scanner; public class B { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scan = new Scanner(System.in); int n = scan.nextInt(), x = scan.nextInt(); int[] arr = new int[n]; int i; int sum = 0; for(i = 0 ; i < n ; i++) { arr[i] = scan.nextInt(); sum += arr[i]; } if(x == sum + n - 1) System.out.println("YES"); else System.out.println("NO"); scan.close(); } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
b62699f494fd9dacbae7c6e101c5d1b3
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Vadim */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastScanner in = new FastScanner(inputStream); PrintWriter out = new PrintWriter(outputStream); B solver = new B(); solver.solve(1, in, out); out.close(); } static class B { public void solve(int testNumber, FastScanner in, PrintWriter out) { int n = in.ni(), x = in.ni(); int[] a = in.na(n); long sum = -1; for (int i = 0; i < n; i++) { sum += a[i] + 1; } if (sum == x) { out.println("YES"); } else { out.println("NO"); } } } static class FastScanner { private BufferedReader in; private StringTokenizer st; public FastScanner(InputStream stream) { in = new BufferedReader(new InputStreamReader(stream)); } public String ns() { while (st == null || !st.hasMoreTokens()) { try { String rl = in.readLine(); if (rl == null) { return null; } st = new StringTokenizer(rl); } catch (IOException e) { throw new RuntimeException(e); } } return st.nextToken(); } public int ni() { return Integer.parseInt(ns()); } public int[] na(int n) { int[] ret = new int[n]; for (int i = 0; i < n; i++) { ret[i] = ni(); } return ret; } } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
d0c26ed2d123969a7380454b9ca8cafd
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class cf31 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line; line = br.readLine(); String str[] = line.split(" "); int n = Integer.parseInt(str[0]); long x = Long.parseLong(str[1]); line = br.readLine(); long[] a = new long[n]; str = line.split(" "); for (int i=0;i<n;i++) { a[i] = Long.parseLong(str[i]); } long ans=0; for(int i=0;i<n;i++){ ans+=a[i]; } if(x-ans!=n-1){ System.out.println("NO"); } else{ System.out.println("YES"); } } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
f254ea2c7d8c148813f38efa68bc52de
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.io.*; import java.util.*; public class EdThreeOneB{ public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int n = sc.nextInt(); int x = sc.nextInt(); int sum =0; for(int i =0; i<n; i++) { sum = sum +sc.nextInt(); } double residue = (double)(x-sum)/(double)(n-1); if (residue == 1) { out.println("YES"); } else if((n==1)&&(sum==x)) { out.println("YES"); } else if (n==0){ out.println("YES"); } else { out.println("NO"); } // Start writing your solution here. ------------------------------------- /* int n = sc.nextInt(); // read input as integer long k = sc.nextLong(); // read input as long double d = sc.nextDouble(); // read input as double String str = sc.next(); // read input as String String s = sc.nextLine(); // read whole line as String int result = 3*n; out.println(result); // print via PrintWriter */ // Stop writing your solution here. ------------------------------------- out.close(); } //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; //-----------MyScanner class for faster input---------- 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
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
491d8877b67946c26831d641a625580b
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.util.*; import java.io.*; public class a{ public static void main(String [] args){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int x=sc.nextInt(); int sum=0; for(int i=0;i<n;i++){ sum+=sc.nextInt(); } if((sum+(n-1))==x){ System.out.println("YES"); } else{ System.out.println("NO"); } } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
5202f50e5f7e127d9c29129187dcc13f
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.io.*; import java.util.*; import java.util.Map.Entry; import java.lang.Math; import java.math.BigInteger; public class Problem { class Pair { int x, y; Pair(int x, int y) { this.x = x; this.y = y; } } void solve() throws IOException { int n = rI(); long x = rL(); long sum = 0; for(int i=0;i<n;++i){ int cur = rI(); sum+= cur; } if(x-sum==n-1){ out.println("YES"); }else{ out.println("NO"); } } int checkBit(int mask, int bit) { return (mask >> bit) & 1; } public static void main(String[] args) throws IOException { new Problem().run(); } boolean isLower(char a) { return ((int) a) >= 97 ? true : false; } long INF = Integer.MAX_VALUE - 12345; int[][] STEPS = { { 0, 1 }, { 1, 0 }, { -1, 0 }, { 0, -1 } }; BufferedReader in; PrintWriter out; StringTokenizer tok; Random rnd = new Random(); static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null; Problem() 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"); } tok = new StringTokenizer(""); } long checkBit(long mask, int bit) { return (mask >> bit) & 1; } // ====================================================== // ====================================================== void run() throws IOException { solve(); out.close(); } char[] reverseCharArray(char[] arr) { char[] ans = new char[arr.length]; for (int i = 0; i < arr.length; ++i) { ans[i] = arr[arr.length - i - 1]; } return ans; } int sqrt(double m) { int l = 0; int r = 1000000000 + 9; int i = 1000; while (r - l > 1) { int mid = (r + l) / 2; if (mid * mid > m) { r = mid; } else { l = mid; } } return l; } int countPow(int m, int n) { int ans = 0; while (m % n == 0 && m > 0) { ans++; m /= n; } return ans; } long binPow(long a, long b) { if (b == 0) { return 1; } if (b % 2 == 1) { return a * binPow(a, b - 1); } else { long c = binPow(a, b / 2); return c * c; } } int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } long pow(long x, long k) { long ans = 1; for (int i = 0; i < k; ++i) { ans *= x; } return ans; } // //////////////////////////////////////////////////////////////////// String delimiter = " "; String readLine() throws IOException { return in.readLine(); } String rS() throws IOException { while (!tok.hasMoreTokens()) { String nextLine = readLine(); if (null == nextLine) return null; tok = new StringTokenizer(nextLine); } return tok.nextToken(delimiter); } int rI() throws IOException { return Integer.parseInt(rS()); } long rL() throws IOException { return Long.parseLong(rS()); } double rD() throws IOException { return Double.parseDouble(rS()); } int[] rA(int b) { int a[] = new int[b]; for (int i = 0; i < b; i++) { try { a[i] = rI(); } catch (IOException e) { e.printStackTrace(); } } return a; } int[] readSortedIntArray(int size) throws IOException { Integer[] array = new Integer[size]; for (int index = 0; index < size; ++index) { array[index] = rI(); } Arrays.sort(array); int[] sortedArray = new int[size]; for (int index = 0; index < size; ++index) { sortedArray[index] = array[index]; } return sortedArray; } int[] sortedIntArray(int size, int[] array) throws IOException { for (int index = 0; index < size; ++index) { array[index] = rI(); } Arrays.sort(array); int[] sortedArray = new int[size]; for (int index = 0; index < size; ++index) { sortedArray[index] = array[index]; } return sortedArray; } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
86a91ed8f78bb2f7b48aeed223e90751
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.util.*; public class B884{ public static void main(String[] args){ Scanner scan=new Scanner(System.in); int num=scan.nextInt(),len=scan.nextInt(),sum=0; for(int i=0;i<num;i++) sum += scan.nextInt(); System.out.print(sum+num-1==len?"YES":"NO"); } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
76a58928aada148daee63d0d51edee01
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.io.*; public class _884B { static PrintWriter out = new PrintWriter(System.out); static Scan in = new Scan(); public static void main(String[] args) throws IOException { int n = in.nextInt(), x = in.nextInt(), sum = 0; for (int i = 0; i < n; i++) { sum += in.nextInt(); } out.println(sum + n - 1 == x ? "YES" : "NO"); out.flush(); } } class Scan { private final java.io.InputStream stream = System.in; private final byte EOF = -1, NL = '\n', D = '-', SPC = ' ', buffer[] = new byte[0xFFFF]; private char cBuff[] = new char[0xFF]; public int $index, $readCount, itr; private void inc() { cBuff = java.util.Arrays.copyOf(cBuff, cBuff.length << 1); } private boolean readLINE() throws IOException { if ($readCount == EOF) return false; for (itr = 0;;) { while ($index < $readCount) if (buffer[$index] != NL) { if (itr == cBuff.length) inc(); cBuff[itr++] = (char)buffer[$index++]; } else { $index++; return true; } $index = 0; $readCount = stream.read(buffer); if ($readCount == EOF) return true; } } private boolean readPRT() throws IOException { if ($readCount == EOF) return false; T: for (;;) { while ($index < $readCount) if (buffer[$index] > SPC) break T; else $index++; $index = 0; $readCount = stream.read(buffer); if ($readCount == EOF) return false; } for (itr = 0;;) { while ($index < $readCount) if (buffer[$index] > SPC) { if (itr == cBuff.length) inc(); cBuff[itr++] = (char)buffer[$index++]; } else return true; $index = 0; $readCount = stream.read(buffer); if ($readCount == EOF) return true; } } public int nextInt() throws IOException { if (!readPRT()) throw new IOException(); else { int v = 0, i = 0; boolean neg; if (cBuff[i] == D) {neg = true; i++;} else neg = false; while (i < itr) v = (v << 3) + (v << 1) + cBuff[i++] - '0'; return neg ? -v : v; } } public long nextLong() throws IOException { if (!readPRT()) throw new IOException(); else { long v = 0; int i = 0; boolean neg; if (cBuff[i] == D) {neg = true; i++;} else neg = false; while (i < itr) v = (v << 3L) + (v << 1L) + cBuff[i++] - '0'; return neg ? -v : v; } } public char[] buffer() throws IOException { return readPRT() ? cBuff : null; } public String next() throws IOException { return readPRT() ? new String(cBuff, 0, itr) : null; } public char[] nextArr() throws IOException { return readPRT() ? java.util.Arrays.copyOf(cBuff, itr) : null; } public String nextLine() throws IOException { return readLINE() ? new String(cBuff, 0, itr) : null; } public char[] nextLineArr() throws IOException { return readLINE() ? java.util.Arrays.copyOf(cBuff, itr) : null; } public float nextFloat() throws IOException { return Float.parseFloat(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
f1912ab7beb8342b46c420793c6df045
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * Created by sahil on 31/10/17. */ public class Main { public static void main(String[] arg){ BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); try { String parameterStringList[] = reader.readLine().split(" "); int n = Integer.parseInt(parameterStringList[0]); int x = Integer.parseInt(parameterStringList[1]); String encodingString[] = reader.readLine().split(" "); int totSpaceOccupied = 0, i=0; boolean isUnique = true; while (i<n){ int a = Integer.parseInt(encodingString[i]); if(i!=n-1) totSpaceOccupied += a+1; else{ if(x-totSpaceOccupied > a) {isUnique = false;} else { totSpaceOccupied += a; } } i++; } if(totSpaceOccupied > x) isUnique = false; if(isUnique) System.out.println("YES"); else System.out.println("NO"); } catch (IOException e) { e.printStackTrace(); } } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
1268c85708bbbb8f023bc58d860ed021
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.util.Scanner; /** * Created by камиль on 06.11.2017. */ public class B { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int x = in.nextInt(); int a[] = new int[n]; int sum = 0; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); sum+=a[i]; } if(x==n-1+sum){ System.out.println("YES"); }else{ System.out.println("NO"); } } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
29f015fb8f4ba45b3b814377d62a831b
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Ideone { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc=new Scanner(System.in); int n=sc.nextInt(); long x=sc.nextInt(); long sum=0; for(int i=0;i<n;i++) { int a=sc.nextInt(); sum+=a; } long zeroes=x-sum; if(zeroes<0) System.out.println("NO"); else if(zeroes==(n-1)) System.out.println("YES"); else System.out.println("NO"); } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
96aeb8f338bb0e0d60516f751dd23e2d
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Summer { public static void main(String[] args) { PrintWriter out = new PrintWriter(System.out); Reader input = new Reader(); long n,x,a,res = 0; n = input.l(); x = input.l(); for(int i = 1;i <= n;i ++){ a= input.l(); res += a; if(i != n) res++; } if(res == x){ System.out.println("YES"); }else{ System.out.println("NO"); } } static class Reader { private InputStream mIs; private byte[] buf = new byte[1024]; private int curChar, numChars; public Reader() { this(System.in); } public Reader(InputStream is) { mIs = is; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = mIs.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public String s() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public long l() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int i() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double d() throws IOException { return Double.parseDouble(s()); } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
921efbe560fe92d8d6836aa71dd5b43c
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
// δ½œθ€…οΌšζ¨ζˆη‘žε…ˆη”Ÿ import java.io.*; import java.util.*; public class cfe31b { static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); st = new StringTokenizer(br.readLine()); } catch (Exception e){e.printStackTrace();} } public String next() { if (st.hasMoreTokens()) return st.nextToken(); try {st = new StringTokenizer(br.readLine());} catch (Exception e) {e.printStackTrace();} return st.nextToken(); } public int nextInt() {return Integer.parseInt(next());} public long nextLong() {return Long.parseLong(next());} public double nextDouble() {return Double.parseDouble(next());} public String nextLine() { String line = ""; if(st.hasMoreTokens()) line = st.nextToken(); else try {return br.readLine();}catch(IOException e){e.printStackTrace();} while(st.hasMoreTokens()) line += " "+st.nextToken(); return line; } } public static void main(String[] args) { FastScanner sc = new FastScanner(); int n = sc.nextInt(); int x = sc.nextInt(); int k = 0; for(int i=0;i<n;i++) k += sc.nextInt(); System.out.println(x - k == n - 1 ? "YES" : "NO"); } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
f0bf77d3cbb37167994a690b19facf3b
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.util.*; public class codeforces2 { private static Scanner sc = new Scanner(System.in); public static void main(String args[]) { int n=sc.nextInt(),x=sc.nextInt(),sum=0; int arr[]=new int[n]; for (int i = 0; i < n; i++) { arr[i]=sc.nextInt(); sum+=arr[i]; } if(sum+(n-1)==x) { System.out.println("YES"); } else { System.out.println("NO"); } } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
c6526f0df1824520e1b8ad739a3a9acc
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.util.*; public class B { static public void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int x = in.nextInt(); int[] a = new int[n]; long sum = 0; for(int i=0;i<n;i++) { a[i] = in.nextInt(); x-= a[i]; } if(x==n-1) { System.out.print("YES"); } else { System.out.print("NO"); } } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
98517e4748f44be1c4596fdb39fdd7c0
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Main { public static void main(String[] args) throws IOException { PrintWriter out = new PrintWriter(System.out); //Scanner sc = new Scanner(); Reader in = new Reader(); Main solver = new Main(); solver.solve(out, in); out.flush(); out.close(); } static int INF = (int)1e9; static int maxn = (int)1e6+5; static int mod= 1000000321 ; static int n,m,k,t,q,d,p; void solve(PrintWriter out, Reader in) throws IOException{ n = in.nextInt(); m = in.nextInt(); int total = 0; for (int i = 0; i < n;i++ ){ total += in.nextInt(); if (i!=n-1) total++; } if(total == m) out.println("YES"); else out.println("NO"); } //<> static class Reader { private InputStream mIs; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public Reader() { this(System.in); } public Reader(InputStream is) { mIs = is; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = mIs.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public String nextLine() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public String next() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } double nextDouble() { return Double.parseDouble(next()); } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
8235d6df09eb1284c780a808522d9813
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.util.*; public class B{ public static void main(String[] args){ Scanner sb = new Scanner(System.in); int n, x; n = sb.nextInt(); x = sb.nextInt(); int total_ones = 0; int minimum_zeros = n-1; for(int i = 0; i < n; i++){ total_ones += sb.nextInt(); } if(total_ones + minimum_zeros == x){ System.out.println("YES"); } else{ System.out.println("NO"); } } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
4b209941989a990b4a7f83eab6304e98
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.util.Scanner; public class second { public static void main(String[] args){ Scanner input = new Scanner(System.in); int n = input.nextInt(); long x = input.nextLong(); int[] arr; long sum = 0; arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = input.nextInt(); sum += arr[i]; } if((x - sum - n + 1) == 0) { System.out.println("YES"); } else System.out.println("NO"); } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
d0df0543416f4e60625a75cca3130bd5
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.io.*; import java.util.*; import java.math.*; //public class edu11{ //static variable static final int mod = (int) 1e9 + 7; static final double eps = 1e-6; static final double pi = Math.PI; static final long inf = Long.MAX_VALUE / 2; // .......static class static class Pair{ int key,value; Pair(int key,int value){ this.key=key; this.value=value; } int Key(){ return key; } int Value(){ return value; } } static class mycomparator implements Comparator<Pair>{ @Override public int compare(Pair o1,Pair o2){ Integer key1=o1.Key(),key2=o2.Key(); return key1.compareTo(key2); } } //.............staic class end. BufferedReader br; PrintWriter out; public static void main(String[] args) { new edu11().main1(); } void main1() { try{ br=new BufferedReader(new InputStreamReader(System.in)); out=new PrintWriter(System.out); int t=1; // t=ii(); while(t-->0){ //........solution start int tt[]=iint(); int n=tt[0],cw=tt[1]; int[] a =iint(); int sum=0; for (int i=0;i<n ;i++ ) { sum+=a[i]; } if(sum+n-1==cw) System.out.println("YES"); else System.out.println("NO"); //..........solution end. } out.flush(); out.close(); } catch(Exception e){ e.printStackTrace();} } // ...............required method. //................end. //..............input method start. int getmax(int a[]){ int n=a.length; int max=a[0]; for (int i=1;i<n ;i++ ) { max=Math.max(a[i],max); } return max; } int getmin(int a[]){ int n=a.length; int min=a[0]; for (int i=1;i<n ;i++ ) { min=Math.min(a[i],min); } return min; } int[] iint() throws IOException{ String line[]=br.readLine().split(" "); int[] a=new int[line.length]; for (int i=0;i<line.length ;i++ ) { a[i]=Integer.parseInt(line[i]); } return a; } long[] ilong() throws IOException{ String line[]=br.readLine().split(" "); long[] a=new long[line.length]; for (int i=0;i<line.length ;i++ ) { a[i]=Long.parseLong(line[i]); } return a; } double[] idouble() throws IOException{ String line[]=br.readLine().split(" "); double[] a=new double[line.length]; for (int i=0;i<line.length ;i++ ) { a[i]=Long.parseLong(line[i]); } return a; } long li() throws IOException{ return Long.parseLong(br.readLine()); } int ii() throws IOException{ return Integer.parseInt(br.readLine()); } double di() throws IOException{ return Double.parseDouble(br.readLine()); } char ci() throws IOException{ return (char)br.read(); } String si() throws IOException{ return br.readLine(); } String[] isa(int n) throws IOException{ String at =si(); return at.split(" "); } double[][] idm(int n, int m) throws IOException{ double a[][] = new double[n][m]; for (int i = 0; i < n; i++) { double[] temp=idouble(); for (int j = 0; j < m; j++) a[i][j] = temp[j]; } return a; } int[][] iim(int n, int m) throws IOException{ int a[][] = new int[n][m]; for (int i = 0; i < n; i++) { int[] temp=iint(); for (int j = 0; j < m; j++) a[i][j] =temp[j]; } return a; } long[][] ilm(int n, int m) throws IOException{ long a[][] = new long[n][m]; for (int i = 0; i < n; i++) { long[] temp=ilong(); for (int j = 0; j < m; j++) a[i][j] =temp[j]; } return a; } //..............input methods end; }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
479a602be9e398e241d5a560f75d598a
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.util.Scanner; public class Ssss { static Scanner read=new Scanner(System.in); public static void main(String[] args) { int n=read.nextInt(); int x=read.nextInt(); int[] t=new int[n]; int a=0; for(int i=0;i<n;i++){ t[i]=read.nextInt(); a=a+t[i]; } if (x==a+n-1) System.out.println("YES"); else System.out.println("NO"); } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
696717f93a045650cd511dbfc33d09a9
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.util.Scanner; public class Ssss { static Scanner read=new Scanner(System.in); public static void main(String[] args) { int n=read.nextInt(); int x=read.nextInt(); int a=0; for(int i=0;i<n;i++){ a=a+read.nextInt(); } if (x==a+n-1) System.out.println("YES"); else System.out.println("NO"); } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
b2daa31637de0848521a43dd367b714d
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
/** * Date: 24 Jun, 2018 * Link: * * @author Prasad-Chaudhari * @email [email protected] */ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; public class newProgram { public static void main(String[] args) throws IOException { // TODO code application logic here FastIO in = new FastIO(); int n = in.ni(); int x = in.ni(); int a[] = in.gia(n); long sum = n-1; for (int i = 0; i < n; i++) { sum += a[i]; } if (sum == x) { System.out.println("YES"); } else { System.out.println("NO"); } } static class FastIO { private final BufferedReader br; private final BufferedWriter bw; private String s[]; private int index; public FastIO() throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); bw = new BufferedWriter(new OutputStreamWriter(System.out, "UTF-8")); s = br.readLine().split(" "); index = 0; } public int ni() throws IOException { return Integer.parseInt(nextToken()); } public double nd() throws IOException { return Double.parseDouble(nextToken()); } public long nl() throws IOException { return Long.parseLong(nextToken()); } public String next() throws IOException { return nextToken(); } public String nli() throws IOException { try { return br.readLine(); } catch (IOException ex) { } return null; } public int[] gia(int n) throws IOException { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = ni(); } return a; } public int[] gia(int n, int start, int end) throws IOException { validate(n, start, end); int a[] = new int[n]; for (int i = start; i < end; i++) { a[i] = ni(); } return a; } public double[] gda(int n) throws IOException { double a[] = new double[n]; for (int i = 0; i < n; i++) { a[i] = nd(); } return a; } public double[] gda(int n, int start, int end) throws IOException { validate(n, start, end); double a[] = new double[n]; for (int i = start; i < end; i++) { a[i] = nd(); } return a; } public long[] gla(int n) throws IOException { long a[] = new long[n]; for (int i = 0; i < n; i++) { a[i] = ni(); } return a; } public long[] gla(int n, int start, int end) throws IOException { validate(n, start, end); long a[] = new long[n]; for (int i = start; i < end; i++) { a[i] = ni(); } return a; } public int[][] gg(int n, int m) throws IOException { int adja[][] = new int[n + 1][]; int from[] = new int[m]; int to[] = new int[m]; int count[] = new int[n + 1]; for (int i = 0; i < m; i++) { from[i] = ni(); to[i] = ni(); count[from[i]]++; count[to[i]]++; } for (int i = 0; i <= n; i++) { adja[i] = new int[count[i]]; } for (int i = 0; i < m; i++) { adja[from[i]][--count[from[i]]] = to[i]; adja[to[i]][--count[to[i]]] = from[i]; } return adja; } public void print(String s) throws IOException { bw.write(s); bw.flush(); } public void println(String s) throws IOException { bw.write(s); bw.newLine(); bw.flush(); } private String nextToken() throws IndexOutOfBoundsException, IOException { if (index == s.length) { s = br.readLine().split(" "); index = 0; } return s[index++]; } private void validate(int n, int start, int end) { if (start < 0 || end >= n) { throw new IllegalArgumentException(); } } } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
7d81001a863925db2e8b34c124b1cb9a
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
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; import java.util.*; public class Main { public static void main(String []args){ InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Task solver=new Task(); solver.solve(1,in,out); out.close(); } static class Task{ public void solve(int testNumber,InputReader in,PrintWriter out){ int n = in.nextInt(); int x = in.nextInt(); int sum = 0; for(int i = 0 ; i < n ; i++){ sum += (in.nextInt()); } if((sum + (n-1) + 0) == x) { out.println("YES"); } else { out.println("NO"); } } } static class InputReader{ private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public InputReader(InputStream stream) { this.stream = stream; } private int next() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextToken() { int c = next(); while (isSpaceChar(c)) c = next(); StringBuilder res = new StringBuilder(); do { res.append((char) c); c = next(); } while (!isSpaceChar(c)); return res.toString(); } public long nextLong(){ return Long.parseLong(nextToken()); } public int nextInt() { int c = next(); while (isSpaceChar(c)) c = next(); int sgn = 1; if (c == '-') { sgn = -1; c = next(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c-'0'; c = next(); } while (!isSpaceChar(c)); return res*sgn; } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
2c8c439acaeab858bd47afdb50fd814e
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.io.*; import java.util.*; public class Prog { public static void main(String[] args) throws Exception { //FileInputStream inputStream = new FileInputStream("input.txt"); //FileOutputStream outputStream = new FileOutputStream("output.txt"); InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Solver solver = new Solver(); solver.solve(1, in, out); out.close(); } static class Solver { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int x = in.nextInt(); int[] a = new int[n]; int res2 = 0; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); res2 += a[i]; if (i < n-1) res2 += 1; } if (res2 == x) out.println("YES"); else out.println("NO"); } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public float nextFloat() { return Float.parseFloat(next()); } } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
e41a47c47ac325fd04f7372c87958a28
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.util.*; public class comp { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int size = scan.nextInt(); for(int i = 0; i < n; i++) { size -= scan.nextInt(); } System.out.println((size-(n-1) == 0)?"YES":"NO"); } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
a77545b4312085077ff8c180a7bc3013
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; public class B { public static void main(String[] args) throws IOException { FastScanner in= new FastScanner(System.in); PrintWriter out= new PrintWriter(System.out); int n = in.nextInt(); int x= in.nextInt(); int tot= 0; for (int i = 0; i < n; i++) { tot+= in.nextInt(); } tot+=n-1; if(tot!=x) { System.out.println("NO"); } else { System.out.println("YES"); } } static class p implements Comparable<p>{ int id; long val; public p(int a, long b) { id=a; val=b; } public int compareTo(p o) { return Long.compare(o.val, this.val); } } static class FenwickTree { long[] ft; public FenwickTree(int n) { ft = new long[n + 1]; } int rsq(int b) { int sum = 0; for (; b > 0; b -= (b & (-b))) sum += ft[b]; return sum; } int rsq(int a, int b) { return rsq(b) - (a == 1 ? 0 : rsq(a - 1)); } void update(int k, int v) { for (; k < ft.length; k += (k & (-k))) ft[k] += v; } } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); st = new StringTokenizer(""); } public String next() throws IOException { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); return next(); } return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public double nextDouble() throws NumberFormatException, IOException { return Double.parseDouble(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
912f65435b1291990380da8d42722c0a
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.util.*; public class tree { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int x = scanner.nextInt(); int [] a = new int[n]; for (int i = 0; i <n ; i++) { a[i] = scanner.nextInt(); } int sum = 0; for (int i = 0; i <n ; i++) { sum+=a[i]; } if (sum == x && n!=1) System.out.println("NO"); else if (x-sum==n-1 || (n==1 && sum==x)) System.out.println("YES"); else System.out.println("NO"); } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
ee654a0ea6fc9eaad60ad9d29562c3f8
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
/* * @author romit17 */ import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class B884 { void solve() throws IOException { PrintWriter out = new PrintWriter(System.out); StringBuilder sb = new StringBuilder(""); int n = ni(); long x = nl(); int[] a = na(n); long s = 0; for(int i:a) s+=i; if(x==s+n-1) System.out.println("YES"); else System.out.println("NO"); } public static void main(String[] args) throws IOException { new B884().solve(); } private byte[] inbuf = new byte[1024]; public int lenbuf = 0, ptrbuf = 0; InputStream is = System.in; 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[] na1(int n) { int[] a = new int[n + 1]; for (int i = 1; i < n + 1; i++) { a[i] = ni(); } return a; } private long[] nb(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = nl(); } return a; } private long[] nb1(int n) { long[] a = new long[n + 1]; for (int i = 1; i < n + 1; i++) { a[i] = nl(); } 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(); } } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
6303489e47a19f769f42d95385cf0327
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.util.Scanner; /** * * @author rreza */ public class JavaApplication4 { /** * @param args the command line arguments */ static Scanner in = new Scanner(System.in); public static void main(String[] args) { String temp = in.nextLine(); String[] temp1 = temp.split(" "); int n = Integer.parseInt(temp1[0]); int d = Integer.parseInt(temp1[1]); int sum = n-1; temp = in.nextLine(); temp1 = temp.split(" "); for (int i = 0; i < n; i++) { sum += Integer.parseInt(temp1[i]); } if(sum == d){ System.out.println("YES"); }else{ System.out.println("NO"); } } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
cf7b92a613cbc4951dba782da8e479b0
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.Scanner; public class Main { private static Scanner sc = new Scanner(new InputStreamReader(System.in)); private static PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out)); public static void main(String[] args) { int n = sc.nextInt(); int x = sc.nextInt(); int sum = 0; for (int i = 0; i < n; i++) { sum += sc.nextInt(); } pw.println(x + 1 == sum + n ? "YES" : "NO"); pw.flush(); } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
1104384f3f6d60b5afeed3bc1cd599d7
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.FilterInputStream; import java.io.BufferedInputStream; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Jenish */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; ScanReader in = new ScanReader(inputStream); PrintWriter out = new PrintWriter(outputStream); B884 solver = new B884(); solver.solve(1, in, out); out.close(); } static class B884 { public void solve(int testNumber, ScanReader in, PrintWriter out) { int n = in.scanInt(); int x = in.scanInt(); int arr[] = new int[n]; long sum = 0; for (int i = 0; i < n; i++) { arr[i] = in.scanInt(); sum += arr[i]; } if (sum > x) { out.println("NO"); } else { if (n == 1) { if (sum == x) out.println("YES"); else out.println("NO"); } else { int t = n - 1; long numberofZERoO = x - sum; if (numberofZERoO == 0) { out.println("NO"); } else { if (numberofZERoO < t) out.println("NO"); else if (numberofZERoO == t) out.println("YES"); else { if (numberofZERoO - t % 2 == 0) { out.println("YES"); } else { out.println("NO"); } } } } } } } static class ScanReader { private byte[] buf = new byte[4 * 1024]; private int index; private BufferedInputStream in; private int total; public ScanReader(InputStream inputStream) { in = new BufferedInputStream(inputStream); } private int scan() { if (index >= total) { index = 0; try { total = in.read(buf); } catch (Exception e) { e.printStackTrace(); ; } if (total <= 0) return -1; } return buf[index++]; } public int scanInt() { int integer = 0; int n = scan(); while (isWhiteSpace(n)) n = scan(); int neg = 1; if (n == '-') { neg = -1; n = scan(); } while (!isWhiteSpace(n)) { if (n >= '0' && n <= '9') { integer *= 10; integer += n - '0'; n = scan(); } } return neg * integer; } private boolean isWhiteSpace(int n) { if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true; else return false; } } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
ddbd3eac24c780477b8b09ef803e000f
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.util.*; import java.io.*; import static java.lang.Math.*; public class q2 { static class Scan { private final InputStream inputStream; private final byte[] buffer = new byte[1024]; private int currentChar; private int numChars; private SpaceCharFilter filter; public Scan () { inputStream = System.in; } public int read () { if (numChars==-1) throw new InputMismatchException(); if (currentChar >= numChars) { currentChar = 0; try { numChars = inputStream.read(buffer); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buffer[currentChar++]; } public String nextLine () { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String str = ""; try { str = br.readLine(); } catch (IOException e) { } return str; } public int nextInt () { int ch = read(); while (isSpaceChar(ch)) ch = read(); int sgn = 1; if (ch == '-') { sgn = -1; ch = read(); } int res = 0; do { if (ch < '0' || ch > '9') throw new InputMismatchException(); res *= 10; res += ch - '0'; ch = read(); } while (!isSpaceChar(ch)); return res * sgn; } public long nextLong () { int ch = read(); while (isSpaceChar(ch)) ch = read(); int sgn = 1; if (ch == '-') { sgn = -1; ch = read(); } long res = 0; do { if (ch < '0' || ch > '9') throw new InputMismatchException(); res *= 10; res += ch - '0'; ch = read(); } while (!isSpaceChar(ch)); return res * sgn; } public double nextDouble () { int ch = read(); while (isSpaceChar(ch)) ch = read(); int sgn = 1; if (ch == '-') { sgn = -1; ch = read(); } double res = 0; while (!isSpaceChar(ch) && ch != '.') { if (ch == 'e' || ch == 'E') return res * Math.pow(10, nextInt()); if (ch < '0' || ch > '9') throw new InputMismatchException(); res *= 10; res += ch - '0'; ch = read(); } if (ch == '.') { ch = read(); double m = 1; while (!isSpaceChar(ch)) { if (ch == 'e' || ch == 'E') return res * Math.pow(10, nextInt()); if (ch < '0' || ch > '9') throw new InputMismatchException(); m /= 10; res += (ch - '0') * m; ch = read(); } } return res * sgn; } public String readString () { int ch = read(); while (isSpaceChar(ch)) ch = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(ch); ch = read(); } while (!isSpaceChar(ch)); return res.toString(); } public boolean isSpaceChar (int ch) { if (filter != null) return filter.isSpaceChar(ch); return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t' || ch == -1; } public String next () { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static class Print { private final BufferedWriter bw; public Print () { this.bw=new BufferedWriter(new OutputStreamWriter(System.out)); } public void print (Object object)throws IOException { bw.append(""+object); } public void println (Object object)throws IOException { print(object); bw.append("\n"); } public void close () throws IOException { bw.close(); } } private static void readArray (int[] arr, Scan scan) { for (int i = 0; i < arr.length; i++) { arr[i] = scan.nextInt(); } } private static void read2DArray (int[][] arr, Scan scan) { for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr[i].length; j++) { arr[i][j] = scan.nextInt(); } } } private static void printArray (int[] arr, char ch, Print pr) throws IOException { for (int i = 0; i < arr.length; i++) { pr.print(arr[i] + "" + ch); } } private static void print2DArray (int[][] arr, Print pr) throws IOException { for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr[i].length; j++) { pr.print(arr[i][j] + " "); } pr.println(""); } } private static void sort2DArray (int[][] arr) { Arrays.sort (arr, new Comparator<int[]>() { public int compare (int[] a, int[] b) { return Integer.compare(a[0], b[0]); } /*public int compare (int[] a, int[] b) { if(a[0] < b[0]) return -1; else if(a[0] > b[0]) return 1; else return Integer.compare(a[1], b[1]); }*/ }); } public static void main (String[] args) throws IOException { Scan sc = new Scan(); Print pr = new Print(); int n, x, i, count=0; n=sc.nextInt(); x=sc.nextInt(); int arr[] = new int[n]; for(i=0;i<n;i++) { arr[i]=sc.nextInt(); count+=arr[i]; } if((x-count)==(n-1)) { pr.println("YES"); } else pr.println("NO"); pr.close(); } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
a4bdf11bf4414daa21e77fd86a984ed6
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.util.*; import java.io.*; public class programA { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); int t = Integer.parseInt(st.nextToken()); int arr[] = new int[n]; st = new StringTokenizer(br.readLine()); int sum=0; for(int i=0;i<n;i++) { arr[i] = Integer.parseInt(st.nextToken()); sum+=arr[i]; } if(sum+n-1 == t ) { System.out.println("YES"); } else { System.out.println("NO"); } } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
3bf01d37bb7ce3e0fe7ecdfdb0a46223
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.util.Scanner; public final class CrossWordCF { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int x=sc.nextInt(); int sum=0; for(int i=0;i<n;i++){ sum+=sc.nextInt(); } sum+=(n-1); if(sum==x) System.out.println("YES"); else System.out.println("NO"); } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
08eb8f93fdce87d4ad4e345b557aa080
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class he { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int n = cin.nextInt(), k = cin.nextInt(); int a[] = new int [n]; int sum = 0; for(int i = 0; i < n; i++) { a[i] = cin.nextInt(); sum += a[i]; } if(n == 1 && a[0] == k - 1) System.out.println("NO"); else if(sum + n - 1 == k) { System.out.println("YES"); } else { System.out.println("NO"); } //Arrays.sort(a); } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
0b12b6f1c25f890004723b880175c09e
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.util.*; public class JapaneseCrosswordsStrikeBack{ public static void main(String[] args){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int x=in.nextInt(); int k=0; for(int i=0;i<n;i++){ k+=in.nextInt(); } if(x==k+n-1){ System.out.println("YES"); } else{ System.out.println("NO"); } } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
016cd60d8ccd7ea70ee31329970a6ad0
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.util.Scanner; public class B { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int n = sc.nextInt(), x = sc.nextInt(); int sum = 0; for(int i = 0; i< n; i++) sum += sc.nextInt(); if(sum == (x-n+1)) { System.out.println("YES"); } else System.out.println("NO"); } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
63648741ac7ee76b13b424ab4e9973f6
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.util.Scanner; public class divs { public static void main(String[] args) { Scanner in = new Scanner(System.in); int nelements = in.nextInt(); int length = in.nextInt(); int[] arr = new int[nelements]; for (int i = 0; i < nelements; i++){ arr[i] = in.nextInt(); } int min = arr[0]; if (arr.length > 1) min++; for (int j = 1; j < nelements; j++){ min += arr[j]; if (j != nelements - 1) min++; } if (min == length) System.out.println("YES"); else System.out.println("NO"); } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
9590bb366149229e766198317016b87f
train_000.jsonl
1509113100
A one-dimensional Japanese crossword can be represented as a binary string of length x. An encoding of this crossword is an array a of size n, where n is the number of segments formed completely of 1's, and ai is the length of i-th segment. No two segments touch or intersect.For example: If x = 6 and the crossword is 111011, then its encoding is an array {3, 2}; If x = 8 and the crossword is 01101010, then its encoding is an array {2, 1, 1}; If x = 5 and the crossword is 11111, then its encoding is an array {5}; If x = 5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Scanner; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } static class TaskB { public void solve(int testNumber, Scanner in, PrintWriter out) { int n = in.nextInt(); long x = in.nextLong(); in.nextLine(); String s[] = in.nextLine().split(" "); long ls = 0L; for (int i = 0; i < n; i++) { ls += Long.parseLong(s[i]); if (i != 0) ls++; } //if(n>1)ls+=(n+1)/2; String rez; if (ls == x) rez = "YES"; else rez = "NO"; out.println(rez); } } }
Java
["2 4\n1 3", "3 10\n3 3 2", "2 10\n1 3"]
1 second
["NO", "YES", "NO"]
null
Java 8
standard input
[ "implementation" ]
080a3458eaea4903da7fa4cf531beba2
The first line contains two integer numbers n and x (1 ≀ n ≀ 100000, 1 ≀ x ≀ 109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains n integer numbers a1, a2, ..., an (1 ≀ ai ≀ 10000) β€” the encoding.
1,100
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
standard output
PASSED
0d73107e6c89c3e47547224d22046758
train_000.jsonl
1366385400
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in the t-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.
256 megabytes
import java.util.Scanner; public class A { public static void main(String[] args) { Scanner input = new Scanner( System.in ); int n = input.nextInt(); String way = input.next(); int firstR = way.indexOf( 'R' ) + 1, firstL = way.indexOf( 'L' ) + 1, lastR = way.lastIndexOf( 'R' ) + 1, lastL = way.lastIndexOf( 'L' ) + 1; if( firstR == 0 ) { System.out.println( "" + lastL + " " + ( firstL - 1 ) ); System.exit(0); } if( firstL == 0 ) { System.out.println( "" + firstR + " " + ( lastR + 1 ) ); System.exit(0); } System.out.println( "" + firstR + " " + lastR ); } }
Java
["9\n..RRLL...", "11\n.RRRLLLLL.."]
1 second
["3 4", "7 5"]
NoteThe first test sample is the one in the picture.
Java 7
standard input
[ "implementation", "greedy" ]
3053cba2426ebd113fcd70a9b026dad0
The first line of the input contains integer n (3 ≀ n ≀ 1000). The second line contains the description of the road β€” the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
1,300
Print two space-separated integers β€” the values of s and t. If there are several possible solutions you can print any of them.
standard output
PASSED
78da0332f97be06f6e8a2607613fb237
train_000.jsonl
1366385400
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in the t-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.
256 megabytes
import java.io.*; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.Map.Entry; import java.util.Set; import java.util.TreeSet; public class Main { public static void main(String[] args) throws Exception { int n = Integer.parseInt(inB.readLine()); String s = inB.readLine(); int sPos = -1, tPos = -1; if(!s.contains("R")){ exit((s.indexOf('L') + 1) + " " + (s.indexOf('L'))); } else if (!s.contains("L")){ exit((s.indexOf('R') + 1) + " " + (s.lastIndexOf('R') + 2)); } for(int i = 0; i < s.length(); i++){ if(s.charAt(i) == 'R' && sPos == -1){ sPos = i + 1; } else if(s.charAt(i) == 'L') { tPos = i; break; } } println(sPos + " " + tPos); } private static PrintWriter out = new PrintWriter(System.out); private static BufferedReader inB = new BufferedReader(new InputStreamReader(System.in)); private static StreamTokenizer in = new StreamTokenizer(inB); private static void exit(Object o) throws Exception { out.println(o); out.flush(); System.exit(0); } private static void println(Object o) throws Exception{ out.println(o); out.flush(); } private static void print(Object o) throws Exception{ out.print(o); out.flush(); } private static int nextInt() throws Exception { in.nextToken(); return (int)in.nval; } private static String nextString() throws Exception { in.nextToken(); return in.sval; } }
Java
["9\n..RRLL...", "11\n.RRRLLLLL.."]
1 second
["3 4", "7 5"]
NoteThe first test sample is the one in the picture.
Java 7
standard input
[ "implementation", "greedy" ]
3053cba2426ebd113fcd70a9b026dad0
The first line of the input contains integer n (3 ≀ n ≀ 1000). The second line contains the description of the road β€” the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
1,300
Print two space-separated integers β€” the values of s and t. If there are several possible solutions you can print any of them.
standard output
PASSED
9ea41ed702670398f0ba4641c213ad2c
train_000.jsonl
1366385400
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in the t-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.*; public class A { public static void main(String[] args) throws IOException { //Scanner in = new Scanner (System.in); InputStreamReader reader = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(reader); int n,s,t,rs=0,ls=0,rt,lt,checkR=0,checkL=0; String path; //n = in.nextInt(); n = Integer.parseInt(br.readLine()); path = br.readLine(); for(int i=0;i<path.length();i++) { if(path.charAt(i)!='.') if(path.charAt(i)=='R' && checkR==0) { rs=i; checkR=1; } else if(path.charAt(i)=='L' && checkL==0) { ls=i; checkL=1; } } if(checkR==1 && checkL==1) { System.out.println((rs+1)+" "+(ls)); System.exit(0); } else for(int i=0;i<path.length();i++) { if(checkR==0 && checkL==1) { /* if(path.charAt(i)=='L' && path.charAt(i+1)=='.') { lt=i; System.out.println((ls+1)+" "+lt); }*/ System.out.println((ls+1)+" "+ls); System.exit(0); } else if(checkL==0 && checkR==1) { if(path.charAt(i)=='R' && path.charAt(i+1)=='.') { rt=i; System.out.println((rs+1)+" "+(rt+2)); System.exit(0); } } } } }
Java
["9\n..RRLL...", "11\n.RRRLLLLL.."]
1 second
["3 4", "7 5"]
NoteThe first test sample is the one in the picture.
Java 7
standard input
[ "implementation", "greedy" ]
3053cba2426ebd113fcd70a9b026dad0
The first line of the input contains integer n (3 ≀ n ≀ 1000). The second line contains the description of the road β€” the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
1,300
Print two space-separated integers β€” the values of s and t. If there are several possible solutions you can print any of them.
standard output
PASSED
583a63ee35f24e131872e2fa69bd69df
train_000.jsonl
1366385400
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in the t-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.
256 megabytes
//package com.congli.codeforces; import java.io.*; import java.util.*; public class C180Div2A_SnowFootprints { BufferedReader in; PrintWriter out; StringTokenizer tok = new StringTokenizer(""); public static void main(String[] args) { C180Div2A_SnowFootprints test = new C180Div2A_SnowFootprints(); test.start(); } public void solve() throws IOException { int n = readInt(); String temp = readString(); char[] array = temp.toCharArray(); calculate(array); } public void calculate(char[] array) { int i = 0; while(array[i] == '.') ++i; int start = i+1; while(array[i] == array[i+1]) ++i; int end = i+1; if(array[i] == 'L') out.println(end + " " + (start-1)); else { if(array[i+1] == '.') out.println(start + " " + (end+1)); else out.println(start + " " + end); } } public void start() { try { long t1 = System.currentTimeMillis(); if (System.getProperty("ONLINE_JUDGE") != null) { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } else { in = new BufferedReader(new FileReader("..\\Codeforces\\src\\com\\congli\\codeforces\\input.txt")); out = new PrintWriter(System.out); } Locale.setDefault(Locale.US); solve(); in.close(); out.close(); long t2 = System.currentTimeMillis(); System.err.println("Time = " + (t2 - t1)); } catch (Throwable t) { t.printStackTrace(System.err); System.exit(-1); } } public String readString() throws IOException { while (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); } return tok.nextToken(); } public int readInt() throws IOException { return Integer.parseInt(readString()); } public long readLong() throws IOException { return Long.parseLong(readString()); } public double readDouble() throws IOException { return Double.parseDouble(readString()); } }
Java
["9\n..RRLL...", "11\n.RRRLLLLL.."]
1 second
["3 4", "7 5"]
NoteThe first test sample is the one in the picture.
Java 7
standard input
[ "implementation", "greedy" ]
3053cba2426ebd113fcd70a9b026dad0
The first line of the input contains integer n (3 ≀ n ≀ 1000). The second line contains the description of the road β€” the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
1,300
Print two space-separated integers β€” the values of s and t. If there are several possible solutions you can print any of them.
standard output
PASSED
f9e6a1a89ce4181373cea3b749c6b624
train_000.jsonl
1366385400
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in the t-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.
256 megabytes
import java.io.*; import java.util.StringTokenizer; public class A { private static final boolean DEBUG = !"true".equalsIgnoreCase(System.getProperty("ONLINE_JUDGE")); private static final boolean DEBUG_OUT = true; private final String inFile = getClass().getName() + ".in"; private final String outFile = getClass().getName() + ".out"; private BufferedReader in; private StringTokenizer tok; private PrintWriter out; private void run() throws IOException { nextLine(); int n = readInt(); nextLine(); String str = read(); int start = -1, end = -1; boolean right = false; for (int i = 0 ; i < n; i++) { if (str.charAt(i) == 'R') { if (start == -1) { start = i; end = i + 1; } else { end = i + 1; } right = true; } else if (str.charAt(i) == 'L') { if (right) { end = i - 1; break; } else { if (end == -1) { start = i; end = i - 1; } else { start = i; } } } } out.println((1+start) + " " + (1+end)); } private String readLine() throws IOException {return in.readLine();} private void nextLine() throws IOException {tok = new StringTokenizer(readLine());} private String read() {return tok.nextToken();} private int readInt() {return Integer.parseInt(read());} private long readLong() {return Long.parseLong(read());} private double readDouble() {return Double.parseDouble(read());} private void debug(Object fmt, Object ...args) { if (!DEBUG) return; if (!DEBUG_OUT) return; System.out.print(String.format(fmt.toString(), args)); } private void debugln(Object fmt, Object ...args) { if (!DEBUG) return; if (!DEBUG_OUT) return; System.out.println(String.format(fmt.toString(), args)); } private void debugln() { if (!DEBUG) return; if (!DEBUG_OUT) return; System.out.println(); } public static void main(String[] args) throws IOException { new A().exec(); } private void exec() { prepare(); process(); if (DEBUG) { outputOutput(); } } private void prepare() { openFiles(); } private void openFiles() { try { if (DEBUG) { in = new BufferedReader(new FileReader(inFile)); out = new PrintWriter(new BufferedWriter(new FileWriter(outFile)), true); } else { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(new BufferedOutputStream(System.out), true); } } catch (IOException e) { System.out.println(e); System.exit(1); } } private void process() { try { if (DEBUG) { in.mark(1000); while (in.read() != -1) { in.reset(); run(); in.mark(1000); } } else { run(); } } catch (IOException e) { System.out.println(e); System.exit(1); } finally { out.close(); try { in.close(); } catch (IOException e) { System.out.println(e); System.exit(1); } } } private void outputOutput() { try { FileInputStream input = new FileInputStream(outFile); byte []buf = new byte[1024]; int r; while ((r = input.read(buf)) != -1) { System.out.write(buf, 0, r); } input.close(); } catch (IOException e) { System.out.println(e); System.exit(1); } } }
Java
["9\n..RRLL...", "11\n.RRRLLLLL.."]
1 second
["3 4", "7 5"]
NoteThe first test sample is the one in the picture.
Java 7
standard input
[ "implementation", "greedy" ]
3053cba2426ebd113fcd70a9b026dad0
The first line of the input contains integer n (3 ≀ n ≀ 1000). The second line contains the description of the road β€” the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
1,300
Print two space-separated integers β€” the values of s and t. If there are several possible solutions you can print any of them.
standard output
PASSED
fd050075ae8385ec79ba5f40a642943a
train_000.jsonl
1366385400
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in the t-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.
256 megabytes
import java.io.*; import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class CF289A { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); //READ---------------------------------------------------- int n = sc.nextInt(); String str = sc.next(); //SOLVE---------------------------------------------------- int fR = str.indexOf('R')+1; int lR = str.lastIndexOf('R')+1; int fL = str.indexOf('L')+1; int lL = str.lastIndexOf('L')+1; if(fR>0 && fL>0) System.out.println(fR+" "+lR); else if(fR>0) System.out.println(fR+" "+(lR+1)); else System.out.println(lL+" "+(fL-1)); //CLOSE---------------------------------------------------- sc.close(); } }
Java
["9\n..RRLL...", "11\n.RRRLLLLL.."]
1 second
["3 4", "7 5"]
NoteThe first test sample is the one in the picture.
Java 7
standard input
[ "implementation", "greedy" ]
3053cba2426ebd113fcd70a9b026dad0
The first line of the input contains integer n (3 ≀ n ≀ 1000). The second line contains the description of the road β€” the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
1,300
Print two space-separated integers β€” the values of s and t. If there are several possible solutions you can print any of them.
standard output
PASSED
db61750488fe6d4cf1d3b7554a805c7b
train_000.jsonl
1366385400
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in the t-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class FootPrints { public static void main (String[]args) throws IOException { BufferedReader rdr = new BufferedReader(new InputStreamReader(System.in)); String line = rdr.readLine(); int n = Integer.parseInt(line); String foot = rdr.readLine(); boolean r = false; boolean l = false; boolean both = false; //int countR = 0; //int countL = 0; for(int i = 0; i < foot.length();i++) { if(foot.charAt(i) == 'R') { r = true; //countR++; } if(foot.charAt(i) == 'L') { l = true; //countL++; } if(l && r) both = true; } if(!(l && r)) { if(l) { boolean first = false; int indxFirst=0 ; int indxLast=0; for(int i = 0; i < foot.length();i++) { if(foot.charAt(i) == 'L' && first) { indxLast = i; } if(foot.charAt(i) == 'L' && !first) { indxFirst = i; first = true; } } if(indxLast < indxFirst) indxLast = indxFirst; System.out.println((indxLast+1)+" "+(indxFirst)); } else if(r) { boolean first = false; int indxFirst=0 ; int indxLast=0; for(int i = 0; i < foot.length();i++) { if(foot.charAt(i) == 'R' && first) { indxLast = i; } if(foot.charAt(i) == 'R' && !first) { indxFirst = i; first = true; } } if(indxLast < indxFirst) indxLast = indxFirst; System.out.println((indxFirst+1)+" "+(indxLast+2)); } } else { boolean first = false; int indxFirst=0 ; int indxLast=0; for(int i = 0; i < foot.length();i++) { if(foot.charAt(i) == 'L' && first) { indxLast = i; } if(foot.charAt(i) == 'L' && !first) { indxFirst = i; first = true; } } if(indxLast < indxFirst) indxLast = indxFirst; System.out.println((indxLast+1)+" "+(indxFirst+1)); } } }
Java
["9\n..RRLL...", "11\n.RRRLLLLL.."]
1 second
["3 4", "7 5"]
NoteThe first test sample is the one in the picture.
Java 7
standard input
[ "implementation", "greedy" ]
3053cba2426ebd113fcd70a9b026dad0
The first line of the input contains integer n (3 ≀ n ≀ 1000). The second line contains the description of the road β€” the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
1,300
Print two space-separated integers β€” the values of s and t. If there are several possible solutions you can print any of them.
standard output
PASSED
411fa1fcc91d762479a468fc39d3c380
train_000.jsonl
1366385400
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in the t-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.
256 megabytes
//package Round_180; import java.util.*; import java.io.*; import static java.lang.Math.*; public class A { void solve () throws IOException { int n = in.nextInt(); char c[] = in.next().toCharArray(); for (int i = 0; i<c.length-1; i++){ if (c[i] == 'R'){ int l = i; int r = n - 1; for (; r > l && c[r] != 'R'; r--); if (c[r + 1] == '.') r++; out.println((l + 1) + " " + (r + 1)); return; } } for (int i = n-1; i>0; i--){ if (c[i] == 'L'){ int l = 0; int r = i; for (; l < r && c[l] != 'L'; l++); if (c[l - 1] =='.') l--; out.println((r + 1) + " " + (l + 1)); return; } } } String input = ""; String output = ""; FastScanner in; PrintWriter out; void run () { try { BufferedReader bf; if (input.length() == 0) { bf = new BufferedReader(new InputStreamReader(System.in)); } else { bf = new BufferedReader(new FileReader(input)); } in = new FastScanner(bf); if (output.length() == 0) { out = new PrintWriter(System.out); } else { out = new PrintWriter(new File(output)); } solve(); out.close(); } catch (Exception ex) { out.close(); ex.printStackTrace(); } } public static void main (String[] args) { new A().run(); } class FastScanner { BufferedReader bf; StringTokenizer st; FastScanner (BufferedReader bf) { this.bf = bf; } String next () throws IOException { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(bf.readLine()); } return st.nextToken(); } String nextLine () throws IOException { String line = bf.readLine(); while (line.length() == 0) { line = bf.readLine(); } return line; } int nextInt () throws IOException { return Integer.parseInt(next()); } long nextLong () throws IOException { return Long.parseLong(next()); } double nextDouble () throws IOException { return Double.parseDouble(next()); } int[] readIntArray (int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } return a; } long[] readLongArray (int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextLong(); } return a; } } }
Java
["9\n..RRLL...", "11\n.RRRLLLLL.."]
1 second
["3 4", "7 5"]
NoteThe first test sample is the one in the picture.
Java 7
standard input
[ "implementation", "greedy" ]
3053cba2426ebd113fcd70a9b026dad0
The first line of the input contains integer n (3 ≀ n ≀ 1000). The second line contains the description of the road β€” the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
1,300
Print two space-separated integers β€” the values of s and t. If there are several possible solutions you can print any of them.
standard output
PASSED
787c410d17712e175d41f9cfe5fd3692
train_000.jsonl
1366385400
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in the t-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.
256 megabytes
import java.util.*; import java.util.ArrayList; import java.io.*; public class Main{ public static void main(String[] args){ Scanner cin = new Scanner(System.in); int n = cin.nextInt(); String str = cin.next(); int l = -1, r = -1; for (int i = 0; i < str.length(); i++) if(str.charAt(i) == 'L'){ l = i; break; } for (int i = str.length()-1; i >= 0; i--) if(str.charAt(i) == 'R'){ r = i; } if (l == -1){ for (int i = str.length()-1; i >= 0; i--) if(str.charAt(i) == 'R'){ r = i; break; } r++; System.out.println(r + " " + (r+1)); return ; } if (r == -1){ System.out.println((l+1) + " " + (l)); return ; } r++; System.out.println(r + " " + l); } }
Java
["9\n..RRLL...", "11\n.RRRLLLLL.."]
1 second
["3 4", "7 5"]
NoteThe first test sample is the one in the picture.
Java 7
standard input
[ "implementation", "greedy" ]
3053cba2426ebd113fcd70a9b026dad0
The first line of the input contains integer n (3 ≀ n ≀ 1000). The second line contains the description of the road β€” the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
1,300
Print two space-separated integers β€” the values of s and t. If there are several possible solutions you can print any of them.
standard output
PASSED
32e60c00dcee085dfd8cd59825561727
train_000.jsonl
1366385400
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in the t-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.
256 megabytes
import static java.util.Arrays.deepToString; import java.io.*; import java.math.*; import java.util.*; public class Main { static void solve() throws IOException { int n = nextInt(); int[] array = new int[n]; String s = reader.readLine(); int r = 0; int l = 0; for (int i = 0; i < array.length; i++) { if (s.charAt(i) == '.') array[i] = 0; else if (s.charAt(i) == 'R') { array[i] = 1; r++; } else { array[i] = -1; l++; } } int start = 0; int end = 0; if (r > 0 && l > 0) { for (int i = 0; i < array.length; i++) { if (array[i] == 1) { start = i + 1; break; } } for (int i = 1; i < array.length; i++) { if (array[i] == -1) { end = i; break; } } } else if (r > 0) { for (int i = 0; i < array.length; i++) { if (array[i] == 1) { start = i + 1; break; } } for (int i = start; i < array.length; i++) { if (array[i] != 1) { end = i+1; break; } } } else { for (int i = 0; i < array.length; i++) { if (array[i] == -1) { end = i; break; } } for (int i = end; i < array.length; i++) { if (array[i] != -1) { start = i; break; } } } System.out.println(start + " " + end); } public static void main(String[] args) throws Exception { reader = new BufferedReader(new InputStreamReader(System.in)); writer = new PrintWriter(System.out); // setTime(); solve(); // printTime(); // printMemory(); writer.close(); } static BufferedReader reader; static PrintWriter writer; static StringTokenizer tok = new StringTokenizer(""); static long systemTime; static void debug(Object... o) { System.err.println(deepToString(o)); } static void setTime() { systemTime = System.currentTimeMillis(); } static void printTime() { System.err.println("Time consumed: " + (System.currentTimeMillis() - systemTime)); } static void printMemory() { System.err.println("Memory consumed: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime() .freeMemory()) / 1000 + "kb"); } static String next() { while (!tok.hasMoreTokens()) { String w = null; try { w = reader.readLine(); } catch (Exception e) { e.printStackTrace(); } if (w == null) return null; tok = new StringTokenizer(w); } return tok.nextToken(); } static int nextInt() { return Integer.parseInt(next()); } static long nextLong() { return Long.parseLong(next()); } static double nextDouble() { return Double.parseDouble(next()); } static BigInteger nextBigInteger() { return new BigInteger(next()); } }
Java
["9\n..RRLL...", "11\n.RRRLLLLL.."]
1 second
["3 4", "7 5"]
NoteThe first test sample is the one in the picture.
Java 7
standard input
[ "implementation", "greedy" ]
3053cba2426ebd113fcd70a9b026dad0
The first line of the input contains integer n (3 ≀ n ≀ 1000). The second line contains the description of the road β€” the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
1,300
Print two space-separated integers β€” the values of s and t. If there are several possible solutions you can print any of them.
standard output
PASSED
9b81142aec8a89aa6818fe777d5f23bd
train_000.jsonl
1366385400
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in the t-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.
256 megabytes
import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.InputMismatchException; import java.io.OutputStream; import java.io.PrintWriter; import java.math.BigInteger; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author alex */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } } class TaskA { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.readInt(); char[] x = in.readLine().toCharArray(); int s = -1; int t = -1; for (int i = 0; i < n; ++i) { if (x[i] == 'R') s = i; if (t == -1 && x[i] == 'L') t = i; } if (t==-1) t = s+1; else if (s==-1) { s = t; --t; } else { t = s; } ++s; ++t; out.println(s + " " + t); } } class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public static boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private String readLine0() { StringBuffer buf = new StringBuffer(); int c = read(); while (c != '\n' && c != -1) { if (c != '\r') buf.appendCodePoint(c); c = read(); } return buf.toString(); } public String readLine() { String s = readLine0(); while (s.trim().length() == 0) s = readLine0(); return s; } }
Java
["9\n..RRLL...", "11\n.RRRLLLLL.."]
1 second
["3 4", "7 5"]
NoteThe first test sample is the one in the picture.
Java 7
standard input
[ "implementation", "greedy" ]
3053cba2426ebd113fcd70a9b026dad0
The first line of the input contains integer n (3 ≀ n ≀ 1000). The second line contains the description of the road β€” the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
1,300
Print two space-separated integers β€” the values of s and t. If there are several possible solutions you can print any of them.
standard output
PASSED
4bb0ce5422dbd00354ef9d1449764065
train_000.jsonl
1366385400
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in the t-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.
256 megabytes
import java.io.InputStreamReader; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.BufferedWriter; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.util.StringTokenizer; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author Lokesh Khandelwal */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } } class TaskA { public void solve(int testNumber, InputReader in, OutputWriter out) { int n=in.nextInt(),i; String s=in.next(); int lastR=0,firstL=0; for(i=0;i<n;i++) { if(s.charAt(i)=='R') lastR=i+1; if(s.charAt(i)=='L'&&firstL==0) firstL=i+1; } if(firstL==0) { out.printLine(lastR+" "+(lastR+1)); } else if(lastR==0) { out.printLine(firstL+" "+(firstL-1)); } else out.printLine(lastR+" "+lastR); } } class InputReader { BufferedReader in; StringTokenizer tokenizer=null; public InputReader(InputStream inputStream) { in=new BufferedReader(new InputStreamReader(inputStream)); } public String next() { try{ while (tokenizer==null||!tokenizer.hasMoreTokens()) { tokenizer=new StringTokenizer(in.readLine()); } return tokenizer.nextToken(); } catch (IOException e) { return null; } } public int nextInt() { return Integer.parseInt(next()); } } class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object...objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void printLine(Object...objects) { print(objects); writer.println(); } public void close() { writer.close(); } }
Java
["9\n..RRLL...", "11\n.RRRLLLLL.."]
1 second
["3 4", "7 5"]
NoteThe first test sample is the one in the picture.
Java 7
standard input
[ "implementation", "greedy" ]
3053cba2426ebd113fcd70a9b026dad0
The first line of the input contains integer n (3 ≀ n ≀ 1000). The second line contains the description of the road β€” the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
1,300
Print two space-separated integers β€” the values of s and t. If there are several possible solutions you can print any of them.
standard output
PASSED
a656a6c870aff4445c38b044112e263c
train_000.jsonl
1366385400
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in the t-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.
256 megabytes
// @author Sanzhar import java.io.*; import java.util.*; import java.awt.Point; public class Template { BufferedReader in; PrintWriter out; StringTokenizer st; String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(in.readLine()); } catch (Exception e) { } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } public void run() throws Exception { //in = new BufferedReader(new FileReader("passwords.in")); //out = new PrintWriter(new FileWriter("passwords.out")); in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); out.flush(); out.close(); in.close(); } public void solve() throws Exception { int n = nextInt(); char[] x = next().toCharArray(); int s = 0, t = 0; for (int i = 0; i < n; i++) { if (x[i] == 'R') { s = i + 1; while (i < n && x[i] == 'R') { i++; } t = i + 1; out.println(s + " " + t); return; } } for (int i = 0; i < n; i++) { if (x[i] == 'L') { t = i; while (i < n && x[i] == 'L') { i++; } s = i; out.println(s + " " + t); return; } } } public static void main(String[] args) throws Exception { new Template().run(); } }
Java
["9\n..RRLL...", "11\n.RRRLLLLL.."]
1 second
["3 4", "7 5"]
NoteThe first test sample is the one in the picture.
Java 7
standard input
[ "implementation", "greedy" ]
3053cba2426ebd113fcd70a9b026dad0
The first line of the input contains integer n (3 ≀ n ≀ 1000). The second line contains the description of the road β€” the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
1,300
Print two space-separated integers β€” the values of s and t. If there are several possible solutions you can print any of them.
standard output
PASSED
b81c50a02b5b32c075f11e0752e1f882
train_000.jsonl
1366385400
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in the t-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.
256 megabytes
import java.util.*; public class Main{ public static String path(String n){ int start = 0; int countR = 0; int countL = 0; for(int i=0; i<n.length(); i++){ if(n.charAt(i) == '.') start++; if(n.charAt(i) == 'R' || n.charAt(i) == 'L') break; } if(n.length()>=start+1){ for(int i=start; i<n.length(); i++){ if(n.charAt(i)== 'R') countR ++; if(n.charAt(i) == 'L') countL ++; } } int stop = start + countR; if(countL == 0) stop++; start++; return start + " " + stop; } public static void main (String[] args){ Scanner sc = new Scanner (System.in); String n = sc.nextLine(); String l = sc.nextLine(); System.out.println(path(l)); } }
Java
["9\n..RRLL...", "11\n.RRRLLLLL.."]
1 second
["3 4", "7 5"]
NoteThe first test sample is the one in the picture.
Java 7
standard input
[ "implementation", "greedy" ]
3053cba2426ebd113fcd70a9b026dad0
The first line of the input contains integer n (3 ≀ n ≀ 1000). The second line contains the description of the road β€” the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
1,300
Print two space-separated integers β€” the values of s and t. If there are several possible solutions you can print any of them.
standard output
PASSED
ab4b3495b9508abc0480404ecc7e0d64
train_000.jsonl
1366385400
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in the t-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.
256 megabytes
import java.util.Scanner; /** * Created by tdph5945 on 2016-06-27. */ public class SnowFootprints { public static void main(String... args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); String line = scanner.next(); int first = -1, last = -1, misMatch = -1; for (int i = 0; i < n; i++) { if (line.charAt(i) != '.' && first == -1) { first = i; } if (first != -1 && line.charAt(i) == '.') { last = i; break; } } if (!line.contains("R")) { System.out.println(last + " " + first); } else if (!line.contains("L")) { last++; first++; System.out.println(first + " " + last); } else { first++; last++; System.out.println(first + " " + (line.indexOf("RL") + 1)); } } }
Java
["9\n..RRLL...", "11\n.RRRLLLLL.."]
1 second
["3 4", "7 5"]
NoteThe first test sample is the one in the picture.
Java 7
standard input
[ "implementation", "greedy" ]
3053cba2426ebd113fcd70a9b026dad0
The first line of the input contains integer n (3 ≀ n ≀ 1000). The second line contains the description of the road β€” the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
1,300
Print two space-separated integers β€” the values of s and t. If there are several possible solutions you can print any of them.
standard output
PASSED
a1f2d99bccf38af5339a489238d302a0
train_000.jsonl
1366385400
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in the t-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class CodeforcesRound180Div2 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String a = br.readLine(); int n = Integer.parseInt(a); String b = br.readLine(); solution(n,b.toCharArray()); } public static void solution(int n,char[] res) { int numR = 0; int numL = 0; int leftMostR = -1; int leftMostL = -1; int rightMostR = -1; int rightMostL = -1; for(int i=0;i<res.length;i++) { if(res[i]=='L') { numL++; rightMostL = i; if(leftMostL == -1) leftMostL = i; } else if(res[i]=='R') { numR++; rightMostR = i; if(leftMostR == -1) leftMostR = i; } } if(numL==0) { res(leftMostR,rightMostR+1); } else if(numR==0) { res(rightMostL,leftMostL-1); } else { res(leftMostR,leftMostL-1); } } public static void res(int s,int t) { System.out.println((s+1)+" "+(t+1)); } }
Java
["9\n..RRLL...", "11\n.RRRLLLLL.."]
1 second
["3 4", "7 5"]
NoteThe first test sample is the one in the picture.
Java 7
standard input
[ "implementation", "greedy" ]
3053cba2426ebd113fcd70a9b026dad0
The first line of the input contains integer n (3 ≀ n ≀ 1000). The second line contains the description of the road β€” the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
1,300
Print two space-separated integers β€” the values of s and t. If there are several possible solutions you can print any of them.
standard output
PASSED
ea86ac2844196bd3769c53b1541b6fe0
train_000.jsonl
1366385400
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in the t-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.
256 megabytes
import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Writer; import java.math.BigInteger; import java.util.InputMismatchException; /** * @Author Roman Dzhadan * @Team Noobs v3.0 * @E-Mail [email protected] * @Skype ronex36 */ public class Main { public static final boolean STANDART_IO = true; public static final String INPUT_FILE_NAME = "input.txt"; public static final String OUTPUT_FILE_NAME = "output.txt"; public static void main(String[] args) throws Exception { Task task = new Task(); task.init(); task.solve(); task.close(); } } class Task { //------------------------------------------------------ SOLUTION -----------------------------------------------------------// public void solve() { int n = in.readInt(); String line = in.readLine(); int firstR = -1; int lastR = -1; int firstL = -1; int lastL = -1; for (int i = 0; i < line.length(); i++) { if (line.charAt(i) == 'R') { if (firstR == -1) { firstR = i + 1; } lastR = i + 1; } if (line.charAt(i) == 'L') { if (firstL == -1) { firstL = i + 1; } lastL = i + 1; } } // out.println(firstR, lastR, firstL, lastL); if (firstR == -1) { out.println(lastL, firstL - 1); } else if (firstL == -1) { out.println(firstR, lastR + 1); } else if (firstR != -1 && firstL != -1) out.println(firstR, firstL - 1); } //-----------------------------------------------------------------------------------------------------------------------------// private InputReader in; private OutputWriter out; public void init() throws FileNotFoundException {if (Main.STANDART_IO) {in = new InputReader(System.in);out = new OutputWriter(System.out);}else {in = new InputReader(new FileInputStream(Main.INPUT_FILE_NAME));out = new OutputWriter(new FileOutputStream(Main.OUTPUT_FILE_NAME));}} public void close() {out.close();} } class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } private int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int peek() { if (numChars == -1) return -1; if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { return -1; } if (numChars <= 0) return -1; } return buf[curChar]; } public int readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long readLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private String readLine0() { StringBuilder buf = new StringBuilder(); int c = read(); while (c != '\n' && c != -1) { if (c != '\r') buf.appendCodePoint(c); c = read(); } return buf.toString(); } public String readLine() { String s = readLine0(); while (s.trim().length() == 0) s = readLine0(); return s; } public String readLine(boolean ignoreEmptyLines) { if (ignoreEmptyLines) return readLine(); else return readLine0(); } public BigInteger readBigInteger() { try { return new BigInteger(readString()); } catch (NumberFormatException e) { throw new InputMismatchException(); } } public char readChar() { int c = read(); while (isSpaceChar(c)) c = read(); return (char) c; } public double readDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, readInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, readInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public boolean isExhausted() { int value; while (isSpaceChar(value = peek()) && value != -1) read(); return value == -1; } public String next() { return readString(); } public SpaceCharFilter getFilter() { return filter; } public void setFilter(SpaceCharFilter filter) { this.filter = filter; } public int[] readIntArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) array[i] = readInt(); return array; } public long[] readLongArray(int size) { long[] array = new long[size]; for (int i = 0; i < size; i++) array[i] = readLong(); return array; } public double[] readDoubleArray(int size) { double[] array = new double[size]; for (int i = 0; i < size; i++) array[i] = readDouble(); return array; } public String[] readStringArray(int size) { String[] array = new String[size]; for (int i = 0; i < size; i++) array[i] = readString(); return array; } public char[] readCharArray(int size) { char[] array = new char[size]; for (int i = 0; i < size; i++) array[i] = readChar(); return array; } public char[][] readCharTable(int rowCount, int columnCount) { char[][] table = new char[rowCount][]; for (int i = 0; i < rowCount; i++) table[i] = readCharArray(columnCount); return table; } public int[][] readIntTable(int rowCount, int columnCount) { int[][] table = new int[rowCount][]; for (int i = 0; i < rowCount; i++) table[i] = readIntArray(columnCount); return table; } public double[][] readDoubleTable(int rowCount, int columnCount) { double[][] table = new double[rowCount][]; for (int i = 0; i < rowCount; i++) table[i] = readDoubleArray(columnCount); return table; } public long[][] readLongTable(int rowCount, int columnCount) { long[][] table = new long[rowCount][]; for (int i = 0; i < rowCount; i++) table[i] = readLongArray(columnCount); return table; } public String[][] readStringTable(int rowCount, int columnCount) { String[][] table = new String[rowCount][]; for (int i = 0; i < rowCount; i++) table[i] = readStringArray(columnCount); return table; } public String readText() { StringBuilder result = new StringBuilder(); while (true) { int character = read(); if (character == '\r') continue; if (character == -1) break; result.append((char) character); } return result.toString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void print(int[] array) { for (int i = 0; i < array.length; i++) { if (i != 0) writer.print(' '); writer.print(array[i]); } } public void print(long[] array) { for (int i = 0; i < array.length; i++) { if (i != 0) writer.print(' '); writer.print(array[i]); } } public void println(int[] array) { print(array); writer.println(); } public void println(int[][] array) { for (int i = 0; i < array.length; i++) { print(array[i]); writer.println(); } } public void println(long[] array) { print(array); writer.println(); } public void println(long[][] array) { for (int i = 0; i < array.length; i++) { print(array[i]); writer.println(); } } public void println() { writer.println(); } public void println(Object... objects) { print(objects); writer.println(); } public void print(char i) { writer.print(i); } public void println(char[] array) { writer.println(array); } public void println(char[][] array) { for (int i = 0; i < array.length; i++) { print(new String(array[i])); writer.println(); } } public void printFormat(String format, Object... objects) { writer.printf(format, objects); } public void close() { writer.close(); } public void flush() { writer.flush(); } }
Java
["9\n..RRLL...", "11\n.RRRLLLLL.."]
1 second
["3 4", "7 5"]
NoteThe first test sample is the one in the picture.
Java 7
standard input
[ "implementation", "greedy" ]
3053cba2426ebd113fcd70a9b026dad0
The first line of the input contains integer n (3 ≀ n ≀ 1000). The second line contains the description of the road β€” the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
1,300
Print two space-separated integers β€” the values of s and t. If there are several possible solutions you can print any of them.
standard output
PASSED
bfba9b8226cb008fd22d0dd398f808e0
train_000.jsonl
1366385400
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in the t-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class SnowFootprints { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader input = new BufferedReader(new InputStreamReader( System.in)); int t = Integer.parseInt(input.readLine()); String s = input.readLine(); int x = 0; int xx = 0; if (t == 3) { if (s.charAt(1) == 'L') { System.out.println(2 + " " + 1); } else { System.out.println(2 + " " + 3); } return; } for (int i = 0; i < s.length(); i++) { if (s.charAt(i) != '.') { x = i; break; } } for (int i = x + 1; i < s.length(); i++) { if (s.charAt(i) == '.') { xx = i; break; } } int r = 0; boolean allSame = true; for (int i = x; i < xx - 1; i++) { if (s.charAt(i) != s.charAt(i + 1)) { r = i; allSame = false; break; } } if (allSame == true) { if (s.charAt(x) == 'L') { System.out.println((xx) + " " + (x)); } else { System.out.println((x + 1) + " " + (xx + 1)); } } else { System.out.println((x + 1) + " " + (r + 1)); } } }
Java
["9\n..RRLL...", "11\n.RRRLLLLL.."]
1 second
["3 4", "7 5"]
NoteThe first test sample is the one in the picture.
Java 7
standard input
[ "implementation", "greedy" ]
3053cba2426ebd113fcd70a9b026dad0
The first line of the input contains integer n (3 ≀ n ≀ 1000). The second line contains the description of the road β€” the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
1,300
Print two space-separated integers β€” the values of s and t. If there are several possible solutions you can print any of them.
standard output
PASSED
7c2a5967613ad417e1d07d7bfddd8bc5
train_000.jsonl
1366385400
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in the t-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.
256 megabytes
import java.io.*; import java.util.*; public class z3 { public static void main(String[] args) throws IOException { Scanner in = new Scanner(System.in); int n=in.nextInt(); in.nextLine(); String s=in.nextLine(); char c; int minR=10000; int maxR=0; int minL=10000; int maxL=0; int isR=0; int isL=0; for (int i=0;i<n;i++) { c=s.charAt(i); switch(c) { case 'R':isR=1;minR=Math.min(minR,i+1);maxR=Math.max(maxR,i+1);break; case 'L':isL=1;minL=Math.min(minL,i+1);maxL=Math.max(maxL,i+1);break; } } if (isL==0) System.out.print(""+minR+" "+(maxR+1)); else if (isR==0) System.out.print(""+maxL+" "+(minL-1)); else System.out.print(""+minR+" "+(minL-1)); } }
Java
["9\n..RRLL...", "11\n.RRRLLLLL.."]
1 second
["3 4", "7 5"]
NoteThe first test sample is the one in the picture.
Java 7
standard input
[ "implementation", "greedy" ]
3053cba2426ebd113fcd70a9b026dad0
The first line of the input contains integer n (3 ≀ n ≀ 1000). The second line contains the description of the road β€” the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
1,300
Print two space-separated integers β€” the values of s and t. If there are several possible solutions you can print any of them.
standard output
PASSED
498a37872d6020a8c13efc957fb68b95
train_000.jsonl
1366385400
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in the t-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int x = Integer.parseInt(in.nextLine()); String cad = in.nextLine(); int pi = 0; int pf = 0; if (cad.contains("R")) { pi = cad.indexOf("R") + 1; for (int i = 0; i < cad.length(); i++) { if ((cad.charAt(i) + "").equals("R")) { pf = i + 1; } } if (!cad.contains("L")) { pf++; } } else { pf = cad.indexOf("L") + 1; for (int i = 0; i < cad.length(); i++) { if ((cad.charAt(i) + "").equals("L")) { pi = i + 1; } } if (!cad.contains("R")) { pf--; } } System.out.println(pi + " " + pf); } }
Java
["9\n..RRLL...", "11\n.RRRLLLLL.."]
1 second
["3 4", "7 5"]
NoteThe first test sample is the one in the picture.
Java 7
standard input
[ "implementation", "greedy" ]
3053cba2426ebd113fcd70a9b026dad0
The first line of the input contains integer n (3 ≀ n ≀ 1000). The second line contains the description of the road β€” the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
1,300
Print two space-separated integers β€” the values of s and t. If there are several possible solutions you can print any of them.
standard output
PASSED
eaf9b895caa1c385ab63fa854fd7b642
train_000.jsonl
1366385400
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in the t-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.
256 megabytes
//package Div_180; //Xudo xoxlasa Accepted import java.util.Scanner; public class A { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String s=sc.next(); int r=s.indexOf("R"); int l=s.indexOf("L"); if(r!=-1&&l!=-1){ System.out.println((r+1)+" "+l); }else{ if(r==-1){ int y=s.lastIndexOf("L"); System.out.println((y+1)+" "+(l)); } if(l==-1){ int y=s.lastIndexOf("R"); System.out.println((r+1)+" "+(y+2)); } } } }
Java
["9\n..RRLL...", "11\n.RRRLLLLL.."]
1 second
["3 4", "7 5"]
NoteThe first test sample is the one in the picture.
Java 7
standard input
[ "implementation", "greedy" ]
3053cba2426ebd113fcd70a9b026dad0
The first line of the input contains integer n (3 ≀ n ≀ 1000). The second line contains the description of the road β€” the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
1,300
Print two space-separated integers β€” the values of s and t. If there are several possible solutions you can print any of them.
standard output
PASSED
36843039b10fa8b1bc2e52daaf172969
train_000.jsonl
1366385400
There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in the t-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.
256 megabytes
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; public class A { static FastScanner in = new FastScanner(System.in); public static void main (String args[]){ int n = in.nextInt(); char a[] = in.next().toCharArray(); int s = 0 ; boolean st = false; int t = 0 ; int r = 0; int l = 0 ; for(int i = 0 ;i<a.length;i++){ if(a[i]=='L'){ l++; } if(a[i]=='R') r++; } if(r==0){ for(int i = a.length-1;i>=0;i--){ if(a[i]=='L'&&!st){ s=i; t=i; st=true; } if(a[i]=='L'){ t=i; } } } else{ for(int i = 0 ; i < a.length;i++){ if(a[i]=='R' && !st){ s=i; t = i ; st = true; } if(a[i]=='R'){ t = i ; } } } if(l<1) t++; if(r<1) t--; System.out.println((s+1)+" "+(t+1)); } } class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(File f) { try { br = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException e) { e.printStackTrace(); } } public FastScanner(InputStream f) { br = new BufferedReader(new InputStreamReader(f)); } String next() { while (st == null || !st.hasMoreTokens()) { String s = null; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } if (s == null) return null; st = new StringTokenizer(s); } return st.nextToken(); } boolean hasMoreTokens() { while (st == null || !st.hasMoreTokens()) { String s = null; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } if (s == null) return false; st = new StringTokenizer(s); } return true; } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } }
Java
["9\n..RRLL...", "11\n.RRRLLLLL.."]
1 second
["3 4", "7 5"]
NoteThe first test sample is the one in the picture.
Java 7
standard input
[ "implementation", "greedy" ]
3053cba2426ebd113fcd70a9b026dad0
The first line of the input contains integer n (3 ≀ n ≀ 1000). The second line contains the description of the road β€” the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.
1,300
Print two space-separated integers β€” the values of s and t. If there are several possible solutions you can print any of them.
standard output
PASSED
e1e86424be2e0e020ad7f45b6cdbbee6
train_000.jsonl
1363188600
The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.A Bitlandish string is a string made only of characters "0" and "1".BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = xΒ xorΒ y, q = xΒ orΒ y. Then he replaces one of the two taken characters by p and the other one by q.The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class R173_DIV2_3 { static String origString = ""; static String modifiedString = ""; static MyScanner scanner = new MyScanner(); public R173_DIV2_3(){ } public static void main(String[] args) { String answer = "NO"; origString = scanner.next(); modifiedString = scanner.next(); if(origString.length() != modifiedString.length()){ answer = "NO"; }else if(origString.equals(modifiedString)){ answer = "YES"; }else if(origString.length() == 1){ answer = "NO"; }else if(origString.indexOf("1")>=0 && modifiedString.indexOf("1")>=0){ answer = "YES"; } System.out.println(answer); } 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()); } } }
Java
["11\n10", "1\n01", "000\n101"]
2 seconds
["YES", "NO", "NO"]
null
Java 7
standard input
[ "constructive algorithms", "implementation", "math" ]
113ae625e67c8ea5ab07be44c3b58a8f
The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths. It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106.
1,500
Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes.
standard output
PASSED
dd28ba19f8726ae62ecccbd9c52fac33
train_000.jsonl
1363188600
The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.A Bitlandish string is a string made only of characters "0" and "1".BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = xΒ xorΒ y, q = xΒ orΒ y. Then he replaces one of the two taken characters by p and the other one by q.The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations.
256 megabytes
import java.util.Scanner; public class Codeforces { static Scanner scanner; public static void main(String[] args) throws Exception { // TODO code application logic here scanner = new Scanner(System.in); String str; String str2; str = scanner.next(); str2 = scanner.next(); if(str.length() != str2.length()) { System.out.print("NO"); System.exit(0); } if((0>str.indexOf('1')^0>str2.indexOf('1'))==true) { System.out.print("NO"); System.exit(0); } else if((0>str.indexOf('1')^0>str2.indexOf('1'))==false) { System.out.print("YES"); System.exit(0); } } }
Java
["11\n10", "1\n01", "000\n101"]
2 seconds
["YES", "NO", "NO"]
null
Java 7
standard input
[ "constructive algorithms", "implementation", "math" ]
113ae625e67c8ea5ab07be44c3b58a8f
The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths. It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106.
1,500
Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes.
standard output
PASSED
f4170c471533e7b79b7f4843b14c81f6
train_000.jsonl
1363188600
The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.A Bitlandish string is a string made only of characters "0" and "1".BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = xΒ xorΒ y, q = xΒ orΒ y. Then he replaces one of the two taken characters by p and the other one by q.The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; public class C { public static void main(String[] args) { InputReader in = new InputReader(System.in); String a = in.next(); String b = in.next(); if (a.length() != b.length()) { System.out.println("NO"); } else { if (a.equals(b)) { System.out.println("YES"); } else { if (a.length() == 1) { System.out.println("NO"); } else { int aa = 0; int bb = 0; char[] fir = a.toCharArray(); char[] sec = b.toCharArray(); for (int i = 0; i < fir.length; i++) { if (fir[i] == '1') { aa++; } if (sec[i] == '1') { bb++; } } if ((aa == 0 && bb > 0) || (bb == 0 && aa > 0)) { System.out.println("NO"); } else { System.out.println("YES"); } } } } } static class InputReader { private BufferedReader reader; private StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public String nextLine() { try { return reader.readLine(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } }
Java
["11\n10", "1\n01", "000\n101"]
2 seconds
["YES", "NO", "NO"]
null
Java 7
standard input
[ "constructive algorithms", "implementation", "math" ]
113ae625e67c8ea5ab07be44c3b58a8f
The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths. It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106.
1,500
Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes.
standard output
PASSED
dec3d9cf333e3407a332fc206db902a9
train_000.jsonl
1363188600
The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.A Bitlandish string is a string made only of characters "0" and "1".BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = xΒ xorΒ y, q = xΒ orΒ y. Then he replaces one of the two taken characters by p and the other one by q.The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations.
256 megabytes
import java.io.BufferedInputStream; import java.util.Arrays; import java.util.Scanner; public class C282 { public static void main(String[] args) { Scanner scanner = new Scanner(new BufferedInputStream(System.in)); char[] first = scanner.next().toCharArray(); char[] second = scanner.next().toCharArray(); scanner.close(); if(first.length != second.length){ System.out.println("NO"); }else{ Arrays.sort(first); Arrays.sort(second); if((first[first.length-1]^second[second.length-1]) ==1){ System.out.println("NO"); }else{ System.out.println("YES"); } } } }
Java
["11\n10", "1\n01", "000\n101"]
2 seconds
["YES", "NO", "NO"]
null
Java 7
standard input
[ "constructive algorithms", "implementation", "math" ]
113ae625e67c8ea5ab07be44c3b58a8f
The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths. It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106.
1,500
Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes.
standard output
PASSED
2ed5b0c13830dab41f6405630ab36979
train_000.jsonl
1363188600
The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.A Bitlandish string is a string made only of characters "0" and "1".BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = xΒ xorΒ y, q = xΒ orΒ y. Then he replaces one of the two taken characters by p and the other one by q.The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations.
256 megabytes
import java.util.*; import java.io.*; public class Task { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { String a = br.readLine(); String b = br.readLine(); if (a.equals(b)) { System.out.println("YES"); return; } if (a.length() != b.length()) { System.out.println("NO"); return; } if (a.indexOf("1") >= 0 && b.indexOf("1") >= 0) { System.out.println("YES"); return; } System.out.println("NO"); } }
Java
["11\n10", "1\n01", "000\n101"]
2 seconds
["YES", "NO", "NO"]
null
Java 7
standard input
[ "constructive algorithms", "implementation", "math" ]
113ae625e67c8ea5ab07be44c3b58a8f
The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths. It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106.
1,500
Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes.
standard output
PASSED
150b092050f62b86c095fc744cde68df
train_000.jsonl
1363188600
The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.A Bitlandish string is a string made only of characters "0" and "1".BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = xΒ xorΒ y, q = xΒ orΒ y. Then he replaces one of the two taken characters by p and the other one by q.The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class XORandOR { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String a = br.readLine(); String b = br.readLine(); if (a.length() != b.length()) { System.out.println("NO"); } else { int cant1a = cant1(a); int cant1b = cant1(b); if (cant1a == 0 ^ cant1b == 0) { System.out.println("NO"); } else { System.out.println("YES"); } } } private static int cant1(String a) { int res = 0; for (int i = 0; i < a.length(); i++) { if (a.charAt(i) == '1') res++; } return res; } }
Java
["11\n10", "1\n01", "000\n101"]
2 seconds
["YES", "NO", "NO"]
null
Java 7
standard input
[ "constructive algorithms", "implementation", "math" ]
113ae625e67c8ea5ab07be44c3b58a8f
The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths. It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106.
1,500
Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes.
standard output
PASSED
ef0567ab129c72df936a28cef46fc6f3
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
import java.util.*; import java.lang.*; import java.math.*; import java.io.*; import static java.lang.Math.*; /* spar5h */ public class cf3 implements Runnable{ static class pair { int i; long w; pair(int i, long w) { this.i = i; this.w = w; } } static class comp implements Comparator<pair> { public int compare(pair x, pair y) { if(x.w < y.w) return -1; if(x.w > y.w) return 1; return 0; } } public void run() { InputReader s = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); int n = s.nextInt(); long m = s.nextLong(), d = s.nextLong() + 1; ArrayList<pair> a = new ArrayList<pair>(); for(int i = 0; i < n; i++) a.add(new pair(i, s.nextLong())); Collections.sort(a, new comp()); int[] color = new int[n + 1]; PriorityQueue<pair> pq = new PriorityQueue<pair>(new comp()); int count = 0; for(int i = 0; i < n; i++) { if(pq.isEmpty() || a.get(i).w - pq.peek().w < d) { count++; color[a.get(i).i] = count; pq.add(new pair(count, a.get(i).w)); continue; } color[a.get(i).i] = pq.peek().i; pq.poll(); pq.add(new pair(color[a.get(i).i], a.get(i).w)); } w.println(count); for(int i = 0; i < n; i++) w.print(color[i] + " "); w.println(); w.close(); } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars==-1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if(numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while(isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if(c<'0'||c>'9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } public static void main(String args[]) throws Exception { new Thread(null, new cf3(),"cf3",1<<26).start(); } }
Java
["4 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
9553c0f8358b921c56b375fd6c4e5180
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class B{ public static void main(String[] args)throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); int m = Integer.parseInt(st.nextToken()); int d = Integer.parseInt(st.nextToken()); int arr[] = new int[n]; String inputArray[] = br.readLine().split(" "); ArrayList<Integer> list = new ArrayList<Integer>(n); HashMap<Integer,Integer> hm = new HashMap<Integer,Integer>(n); TreeSet<Integer> ts = new TreeSet<Integer>(); for(int i=0;i<n;i++){ int minute = Integer.parseInt(inputArray[i]); hm.put(minute,0); list.add(minute); ts.add(minute); } int count = 0, day = 0, start=0; while(ts.size()!=0){ day++; start = ts.first(); int prev = start; hm.put(prev,day); ts.remove(prev); while(ts.ceiling(start+d+1)!=null){ start = ts.ceiling(start+d+1); hm.put(start,day); ts.remove(start); } } System.out.println(day); for(int i=0;i<n;i++){ int min = list.get(i); System.out.print(hm.get(min)+" "); } } }
Java
["4 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
92bd6d2f5638d931ff55c79af59a34ee
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
//package com.pb.codeforces.practice; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; import java.util.TreeMap; public class CF1041C { public static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } public String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader in = new FastReader(); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(); int m = in.nextInt(); int d = in.nextInt(); int[] ans = new int[n]; int dcnt = 0; TreeMap<Integer,Integer> tmap = new TreeMap<Integer,Integer>(); for(int i=0; i<n; i++) tmap.put(in.nextInt(), i); while(!tmap.isEmpty()) { dcnt+=1; int k = tmap.firstKey(); ans[tmap.get(k)] = dcnt; tmap.remove(k); int st = k; while(true) { st += d+1; Integer min = tmap.ceilingKey(st); if(min == null) break; st = min; ans[tmap.get(min)] = dcnt; tmap.remove(min); } } out.println(dcnt); for(int i=0; i<ans.length; i++) out.print(ans[i]+" "); out.flush(); out.close(); } }
Java
["4 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
92854debc5fa6c0ef0342073fc216a9c
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.*; public class wef { public static class FastReader { BufferedReader br; StringTokenizer st; //it reads the data about the specified point and divide the data about it ,it is quite fast //than using direct public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception r) { r.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next());//converts string to integer } double nextDouble() { return Double.parseDouble(next()); } long nextLong() { return Long.parseLong(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (Exception r) { r.printStackTrace(); } return str; } } static ArrayList<String>list1=new ArrayList<String>(); static void combine(String instr, StringBuffer outstr, int index,int k) { if(outstr.length()==k) { list1.add(outstr.toString());return; } if(outstr.toString().length()==0) outstr.append(instr.charAt(index)); for (int i = 0; i < instr.length(); i++) { outstr.append(instr.charAt(i)); combine(instr, outstr, i + 1,k); outstr.deleteCharAt(outstr.length() - 1); } index++; } static ArrayList<ArrayList<Integer>>l=new ArrayList<>(); static void comb(int n,int k,int ind,ArrayList<Integer>list) { if(k==0) { l.add(new ArrayList<>(list)); return; } for(int i=ind;i<=n;i++) { list.add(i); comb(n,k-1,ind+1,list); list.remove(list.size()-1); } } static long sum(long n) { long sum=0; while(n!=0) { sum+=n%10; n/=10; } return sum; } static boolean check(HashMap<Integer,Integer>map) { for(int h:map.values()) if(h>1) return false; return true; } static class Pair implements Comparable<Pair>{ int x;int y; Pair(int x,int y){ this.x=x; this.y=y; // this.i=i; } @Override public int compareTo(Pair o) { // TODO Auto-generated method stub return x-o.x; } } static boolean isPrime(int n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so // that we can skip // middle five numbers // in below loop if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out)); public static void main(String[] args) { // TODO Auto-generated method stub FastReader in=new FastReader(); HashMap<Integer,Integer>map=new HashMap<Integer,Integer>(); ArrayList<Integer>list=new ArrayList<Integer>(); TreeSet<Integer>set=new TreeSet<Integer>(); int n=in.nextInt(); int m=in.nextInt(); int d=in.nextInt(); int b[]=new int[n]; for(int i=0;i<n;i++) { int y=in.nextInt();set.add(y); b[i]=y; } d++; Collections.sort(list); int day=1; while(!set.isEmpty()) { int num=set.first(); map.put(num,day); set.remove(new Integer(num)); num+=d; while(!set.isEmpty()&&num<=m&&num<=set.last()) { num=set.ceiling(num); map.put(num,day); set.remove(new Integer(num)); num+=d; } day++; } StringBuilder sb=new StringBuilder(); out.println(day-1); for(int i=0;i<n;i++) sb.append(map.get(b[i])+" "); out.println(sb); out.close(); } }
Java
["4 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
65ad6e8fc30c6d5c6887d92f0e6f9c3b
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
import java.io.*; import java.math.*; import java.text.*; import java.util.*; import java.util.regex.*; public class Main { static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; public InputReader(InputStream st) { this.stream = st; } public int read() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } public static void main(String[] args) throws Exception { InputReader in=new InputReader(System.in); PrintWriter w=new PrintWriter(System.out); int n=in.nextInt(); int m=in.nextInt(); int d=in.nextInt(); int[] a=new int[n]; HashMap<Integer,Integer> map=new HashMap<Integer,Integer>(); int[] days=new int[n]; boolean[] vis=new boolean[n]; a=in.nextIntArray(n); for(int i=0;i<n;i++) { map.put(a[i],i); } Arrays.sort(a); int currday=1; for(int i=0;i<n;i++) { if(!vis[i]) { int cur=a[i]; days[map.get(cur).intValue()]=currday; vis[i]=true; while(cur<m) { int num=cur+1+d; if(num>m) break; int index=Arrays.binarySearch(a,num); if(index<0) index=(-1)*(index+1); if(index>=n) break; if(!vis[index]) { cur=a[index]; vis[index]=true; days[map.get(a[index]).intValue()]=currday; } else { while(index<n && vis[index]) { index++; } if(index<=n-1) { cur=a[index]; vis[index]=true; days[map.get(a[index]).intValue()]=currday; } else { break; } } } currday++; } } w.println(currday-1); for(int i=0;i<n;i++) { w.print(days[i]+" "); } w.println(); w.close(); } }
Java
["4 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
d1012a47899218e4164d6826668a0e7c
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
import java.io.*; import java.lang.reflect.Array; import java.util.*; public class Main { public static void main(String[] args) throws IOException { FastReader in = new FastReader(System.in); PrintWriter out = new PrintWriter(System.out); //FastReader in = new FastReader(new FileInputStream(new File(".in"))); //PrintWriter out = new PrintWriter(new FileOutputStream(new File(".out"))); int n = in.nextInt(), m = in.nextInt(), d = in.nextInt(); HashMap<Integer, Integer> map = new HashMap<>(); int[] mas = new int[n]; int[] masAns = new int[n]; for(int i = 0; i < n; i++){ mas[i] = in.nextInt(); masAns[i] = mas[i]; } Arrays.sort(mas); ArrayList<Integer> list = new ArrayList<>(); int max = 0; int j = 0; for(int i = 0; i < n; i++){ if(i == 0) map.put(mas[i], 1); else { if(mas[i] - mas[j] > d){ map.put(mas[i], map.get(mas[j])); j++; } else { map.put(mas[i], i - j + 1); } } max = Math.max(i - j + 1, max); } System.out.println(max); for(int i : masAns){ System.out.print(map.get(i) + " "); } System.out.close(); } } class FastReader { InputStream is; private byte[] inbuf = new byte[1024]; private int lenbuf = 0, ptrbuf = 0, charArrayLength = (int) 1e3; public FastReader(InputStream is) { this.is = is; } public 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++]; } public boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } public int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } public String next() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public String nextLine() { int b = readByte(); StringBuilder sb = new StringBuilder(); while (b != '\n' || b != '\r') { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public int nextInt() { 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 << 3) + (num << 1) + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } public long nextLong() { 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 << 3) + (num << 1) + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } public double nextDouble() { return Double.parseDouble(next()); } public char[] next(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); } public char nextChar() { return (char) skip(); } private char buff[]; public char[] nextCharArray() { if (buff == null) buff = new char[charArrayLength]; int b = skip(), p = 0; while (!(isSpaceChar(b))) { buff[p++] = (char) b; b = readByte(); } return Arrays.copyOf(buff, p); } }
Java
["4 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
c77b2761ffc9620e9fcf638dceaebcce
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.FilterInputStream; import java.io.BufferedInputStream; import java.io.InputStream; /** * @author khokharnikunj8 */ public class Main { public static void main(String[] args) { new Thread(null, new Runnable() { public void run() { new Main().solve(); } }, "1", 1 << 26).start(); } void solve() { InputStream inputStream = System.in; OutputStream outputStream = System.out; ScanReader in = new ScanReader(inputStream); PrintWriter out = new PrintWriter(outputStream); CCoffeeBreak solver = new CCoffeeBreak(); solver.solve(1, in, out); out.close(); } static class CCoffeeBreak { public void solve(int testNumber, ScanReader in, PrintWriter out) { int n = in.scanInt(); int m = in.scanInt(); int d = in.scanInt(); BSTCustom<pair> bstCustom = new BSTCustom<pair>(true); for (int i = 0; i < n; i++) { int tt = in.scanInt(); bstCustom.insert(new pair(tt, i)); } int day = 1; int ans[] = new int[n]; while (bstCustom.size() != 0) { long ttt = 0; pair tttt; while (ttt != -1 && ttt != bstCustom.size()) { tttt = bstCustom.get(ttt); bstCustom.remove(tttt, 1); ans[(int) (tttt.y)] = day; ttt = bstCustom.lower_bound(new pair(tttt.x + d + 1, 0)); } day++; } out.println(--day); for (int i = 0; i < n; i++) out.print(ans[i] + " "); } class pair implements Comparable<pair> { int x; int y; public int compareTo(pair o) { return this.x - o.x; } public pair(int x, int y) { this.x = x; this.y = y; } } } static class ScanReader { private byte[] buf = new byte[4 * 1024]; private int index; private BufferedInputStream in; private int total; public ScanReader(InputStream inputStream) { in = new BufferedInputStream(inputStream); } private int scan() { if (index >= total) { index = 0; try { total = in.read(buf); } catch (Exception e) { e.printStackTrace(); } if (total <= 0) return -1; } return buf[index++]; } public int scanInt() { int integer = 0; int n = scan(); while (isWhiteSpace(n)) n = scan(); int neg = 1; if (n == '-') { neg = -1; n = scan(); } while (!isWhiteSpace(n)) { if (n >= '0' && n <= '9') { integer *= 10; integer += n - '0'; n = scan(); } } return neg * integer; } private boolean isWhiteSpace(int n) { if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true; else return false; } } static class BSTCustom<T extends Comparable<? super T>> { private Node<T> __root; private Node<T> __tempnode; private Node<T> __tempnode1; private long __size; private boolean __multi; public BSTCustom() { __root = null; __size = 0; __multi = false; } public BSTCustom(boolean __multi) { __root = null; __size = 0; this.__multi = __multi; } public long lower_bound(T data) { __tempnode = __root; long index = 0; while (__tempnode != null) { int _comparator = data.compareTo(__tempnode.data); if (_comparator < 0) { __tempnode = __tempnode._left; } else if (_comparator > 0) { index += (__tempnode.count + __tempnode._leftside); __tempnode = __tempnode._right; } else { index += (__tempnode._leftside); break; } } return index; } private Node<T> remove(Node<T> temp, T data, long count) { if (temp == null) return temp; int _comparator = data.compareTo(temp.data); if (_comparator < 0) temp._left = remove(temp._left, data, count); else if (_comparator > 0) temp._right = remove(temp._right, data, count); else { if (__multi && count < temp.count && temp.count > 1) { __size -= count; temp.count -= count; } else { __size -= temp.count; if (temp._left == null && temp._right == null) return null; else if (temp._left == null) return temp._right; else if (temp._right == null) return temp._left; else { __tempnode = minValue(temp._right); temp.data = __tempnode.data; temp.count = __tempnode.count; temp._right = remove(temp._right, __tempnode.data, __tempnode.count); __size += temp.count; } } } // for __leftside and _rightside count if (temp._left != null) temp._leftside = temp._left._leftside + temp._left._rightside + temp._left.count; else temp._leftside = 0; if (temp._right != null) temp._rightside = temp._right._leftside + temp._right._rightside + temp._right.count; else temp._rightside = 0; temp._height = Math.max(getheight(temp._left), getheight(temp._right)) + 1; //Balancing long diff = getDiff(temp); if (diff > 1) { if (getDiff(temp._left) >= 0) { temp = rightRotate(temp); } else { temp._left = leftRotate(temp._left); temp = rightRotate(temp); } } else if (diff < -1) { if (getDiff(temp._right) <= 0) { temp = leftRotate(temp); } else { temp._right = rightRotate(temp._right); temp = leftRotate(temp); } } return temp; } public T get(long index) { __tempnode = __root; long current = 0; while (__tempnode != null) { if (__tempnode._left == null) { if (__tempnode.count + current > index) return __tempnode.data; else { current += __tempnode.count; __tempnode = __tempnode._right; } } else { if (current + __tempnode._leftside > index) __tempnode = __tempnode._left; else if (current + __tempnode._leftside + __tempnode.count > index) return __tempnode.data; else { current += __tempnode.count + __tempnode._leftside; __tempnode = __tempnode._right; } } } return null; } private Node<T> minValue(Node<T> temp) { __tempnode = temp; while (__tempnode._left != null) __tempnode = __tempnode._left; return __tempnode; } public void insert(T data, long... count) { if (count.length == 0) __root = insert(__root, data, 1); else if (count[0] > 0) __root = insert(__root, data, count[0]); } public void remove(T data, long... count) { if (count.length == 0) __root = remove(__root, data, 1); else if (count[0] > 0) __root = remove(__root, data, count[0]); } private Node<T> insert(Node<T> temp, T data, long count) { if (temp == null) { if (__multi) { __size += count; return new Node<>(data, count); } else { __size++; return new Node<>(data); } } int _comparator = data.compareTo(temp.data); if (_comparator < 0) temp._left = insert(temp._left, data, count); else if (_comparator > 0) temp._right = insert(temp._right, data, count); else if (__multi) { __size += count; temp.count += count; } // for __leftside and _rightside count if (temp._left != null) temp._leftside = temp._left._leftside + temp._left._rightside + temp._left.count; else temp._leftside = 0; if (temp._right != null) temp._rightside = temp._right._leftside + temp._right._rightside + temp._right.count; else temp._rightside = 0; temp._height = Math.max(getheight(temp._left), getheight(temp._right)) + 1; //Balancing long diff = getDiff(temp); if (diff > 1) { if (data.compareTo(temp._left.data) < 0) { temp = rightRotate(temp); } else if (data.compareTo(temp._left.data) > 0) { temp._left = leftRotate(temp._left); temp = rightRotate(temp); } } else if (diff < -1) { if (data.compareTo(temp._right.data) > 0) { temp = leftRotate(temp); } else if (data.compareTo(temp._right.data) < 0) { temp._right = rightRotate(temp._right); temp = leftRotate(temp); } } return temp; } private Node<T> rightRotate(Node<T> temp) { __tempnode = temp._left; __tempnode1 = __tempnode._right; __tempnode._right = temp; temp._left = __tempnode1; //height updation temp._height = Math.max(getheight(temp._left), getheight(temp._right)) + 1; __tempnode._height = Math.max(getheight(__tempnode._left), getheight(__tempnode._right)) + 1; //count updation if (temp._left != null) temp._leftside = temp._left._leftside + temp._left._rightside + temp._left.count; else temp._leftside = 0; if (temp._right != null) temp._rightside = temp._right._leftside + temp._right._rightside + temp._right.count; else temp._rightside = 0; if (__tempnode._left != null) __tempnode._leftside = __tempnode._left._leftside + __tempnode._left._rightside + __tempnode._left.count; else __tempnode._leftside = 0; if (__tempnode._right != null) __tempnode._rightside = __tempnode._right._leftside + __tempnode._right._rightside + __tempnode._right.count; else __tempnode._rightside = 0; return __tempnode; } private Node<T> leftRotate(Node<T> temp) { __tempnode = temp._right; __tempnode1 = __tempnode._left; __tempnode._left = temp; temp._right = __tempnode1; //height updation temp._height = Math.max(getheight(temp._left), getheight(temp._right)) + 1; __tempnode._height = Math.max(getheight(__tempnode._left), getheight(__tempnode._right)) + 1; //count updation if (temp._left != null) temp._leftside = temp._left._leftside + temp._left._rightside + temp._left.count; else temp._leftside = 0; if (temp._right != null) temp._rightside = temp._right._leftside + temp._right._rightside + temp._right.count; else temp._rightside = 0; if (__tempnode._left != null) __tempnode._leftside = __tempnode._left._leftside + __tempnode._left._rightside + __tempnode._left.count; else __tempnode._leftside = 0; if (__tempnode._right != null) __tempnode._rightside = __tempnode._right._leftside + __tempnode._right._rightside + __tempnode._right.count; else __tempnode._rightside = 0; return __tempnode; } private long getDiff(Node<T> temp) { if (temp == null) return 0; return getheight(temp._left) - getheight(temp._right); } public long getheight(Node<T> temp) { if (temp == null) return 0; return temp._height; } public long size() { return this.__size; } private class Node<T> { T data; Node<T> _left; Node<T> _right; long _leftside; long _rightside; long _height; long count; public Node(T data) { this.data = data; this._left = null; this._right = null; this._leftside = 0; this._rightside = 0; this._height = 1; this.count = 1; } public Node(T data, long count) { this.data = data; this._left = null; this._right = null; this._leftside = 0; this._rightside = 0; this._height = 1; this.count = count; } } } }
Java
["4 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
ab5254a7a63bb8a8c4b6924e3cc3dac7
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
//package pro; import java.io.IOException; import java.util.*; public class Codechef2 { static FasterScanner in = new FasterScanner(); static class node{ long val; long co; node(long v, long c){ this.val=v; this.co=c; } } public static void main(String[] args) { int n = in.nextInt(); long m = in.nextLong(), d = in.nextLong(); HashMap<Long, Integer> hm = new HashMap<>(); long [] arr = new long[n]; for(int i=0; i<n; i++){ arr[i]=in.nextLong(); hm.put(arr[i], i); } Arrays.sort(arr); long [] incr = new long[n]; for(int i=0; i<n; i++){ incr[i]=arr[i]+d+1; } LinkedList<node> qu = new LinkedList<>(); long c=0; //int it=0; long [] ans = new long[n]; /*while(it<n && incr[it]>arr[n-1]){ ans[it]=c+1; it++; c++; } if(it<n){ node tnd = new node(incr[it], c+1); qu.addLast(tnd); ans[it]=c+1; c++; }*/ for(int i=0; i<n; i++){ if(qu.isEmpty()){ int it=i; while(it<n && incr[it]>arr[n-1]){ ans[it]=c+1; it++; c++; } if(it<n){ node tnd = new node(incr[it], c+1); qu.addLast(tnd); ans[it]=c+1; c++; } i=it+1; } if(i<n){ if(arr[i]<qu.getFirst().val){ c++; ans[i]=c; }else{ ans[i]=qu.removeFirst().co; } if(incr[i]<=arr[n-1]){ node tnd = new node(incr[i], ans[i]); qu.addLast(tnd); } } } System.out.println(c); long [] fans = new long [n]; for(int i=0; i<n; i++){ int pos = hm.get(arr[i]); fans[pos]=ans[i]; } for(int i=0; i<n; i++)System.out.print(fans[i] + " "); System.out.println(); } static class FasterScanner { private byte[] buf = new byte[1024]; private int curChar; private int snumChars; public int read() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = System.in.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public String nextString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } public long[] nextLongArray(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = nextLong(); } return arr; } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } }
Java
["4 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
0f3196242365dd88a592d4cdc1c71417
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
import java.util.*; import java.io.*; public class Forces{ public static void main(String ...arg) { Read cin = new Read(); int n = cin.nextInt(); long m = cin.nextLong(); long d = cin.nextLong(); ArrayList<ArrayList<Long>> arr = new ArrayList<>(); for(int i=0;i<n;i++) { arr.add(new ArrayList<Long>()); arr.get(i).add(cin.nextLong()); arr.get(i).add((long)i); } Collections.sort(arr,new Comparator<ArrayList<Long>>(){ @Override public int compare(ArrayList<Long> a,ArrayList<Long> b) { if(a.get(0) != b.get(0)) return (int) (a.get(0) - b.get(0)); else return (int) (a.get(1) - b.get(1)); } }); Long[] ans = new Long[n]; int i=0,j=0; long day=0; while(i<n) { if(arr.get(i).get(0) - arr.get(j).get(0) <= d) { day++; ans[(int)(long)arr.get(i).get(1)] = day; } else { ans[(int)(long)arr.get(i).get(1)] = ans[(int)(long)arr.get(j).get(1)]; j++; } i++; } System.out.println(day); for(i=0;i<n;i++) System.out.print(ans[i] + " "); } } class Read { private BufferedReader br; private StringTokenizer st; public Read() { 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 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
be88a985d08dd52a2e938132c1d01ad1
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
import java.io.*; import java.util.*; public class cf509C{ public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int d = sc.nextInt(); int[] aa = new int[n]; TreeMap<Integer,Integer> tm = new TreeMap<Integer,Integer>(); for(int i=0;i<n;i++){ int num = sc.nextInt(); aa[i]=num; tm.put(num,0); } //Arrays.sort(aa); //int max = aa[n-1]; int k=1; HashMap<Integer,Integer> hm = new HashMap<Integer,Integer>(); while(tm.size()!=0){ int num = tm.firstKey(); hm.put(num,k); tm.remove(num); while(tm.ceilingKey(num+1+d)!=null){ int nn = tm.ceilingKey(num+1+d); hm.put(nn,k); tm.remove(nn); num = nn; } k++; } System.out.println(k-1); for(int i=0;i<n;i++){ System.out.print(hm.get(aa[i])+" "); } } }
Java
["4 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
44dc0bf31b1589f2cd9f6ab4d92e1b30
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
import java.util.*; import java.lang.*; import java.lang.reflect.Array; import java.io.*; import java.math.*; import java.text.DecimalFormat; import java.util.Arrays; import java.util.Collections; public class Prac{ static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; public InputReader(InputStream st) { this.stream = st; } public int read() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int ni() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nl() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nia(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = ni(); } return a; } public String rs() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } static PrintWriter w = new PrintWriter(System.out); public static class Pair { int value; int index; public Pair(Integer value,Integer index) { this.value = value; this.index =index; } // public Pair(int value,int index){ // this.index=index; // this.value=value; // } } public static int bs(Integer[][] arr,int l,int h,int key){ int index=Integer.MIN_VALUE; while(l<=h){ int mid=(l+h)/2; if(arr[mid][0]==key&&arr[mid][2]==0){ index=mid; h=mid-1; } else if(arr[mid][0]==key&&arr[mid][2]!=0){ l=mid+1; } else if(arr[mid][0]>key&&arr[mid][2]==0){ index=mid; h=mid-1; } else if(arr[mid][0]>key&&arr[mid][2]!=0){ } else{ l=mid+1; } } return (index!=Integer.MIN_VALUE)?index:l; } public static void main(String[] args) throws IOException { InputReader sc=new InputReader(System.in); //Scanner sc=new Scanner(System.in); //PriorityQueue<Integer> p=new PriorityQueue<Integer>(); TreeSet<Pair>set=new TreeSet<>((x,y)->x.value!=y.value?x.value-y.value:x.index-y.index); int n=sc.ni(); int m=sc.ni(); int d=sc.ni(); Integer arr[][]=new Integer[n][3]; for(int i=0;i<n;i++){ arr[i][0]=sc.ni(); arr[i][1]=i; arr[i][2]=0; } int ans[]=new int[n]; Arrays.sort(arr,Comparator.comparing((Integer arr1[])->arr1[0])); for(int i=0;i<n;i++){ Pair p=new Pair(arr[i][0],arr[i][1]); set.add(p); } int days=1,sum=1; Pair p=set.first(); ans[p.index]=days; sum=p.value; set.remove(p); while(set.size()>0){ sum+=(d+1); if(sum>m){ days++; Pair q=set.first(); sum=q.value; ans[q.index]=days; set.remove(q); } else{ Pair x=new Pair(sum,-1); Pair q=set.ceiling(x); if(q!=null){ sum=q.value; ans[q.index]=days; set.remove(q); } else{ days++; Pair q1=set.first(); sum=q1.value; ans[q1.index]=days; set.remove(q1); } } } System.out.println(days); for(int i=0;i<n;i++){ System.out.print(ans[i]+" "); } System.out.println(); } }
Java
["4 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
acfe3158040d594c853a73ac8ade3e94
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class tG { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args){ FastReader in=new FastReader(); int n=in.nextInt(); int m=in.nextInt(); int d=in.nextInt(); TreeSet<Integer> treeSet=new TreeSet<Integer>(); LinkedHashMap<Integer,Integer> hash=new LinkedHashMap<Integer,Integer>(); for(int i=0;i<n;i++){ int x=in.nextInt(); treeSet.add(x); hash.put(x,0); } int day=0; while(!treeSet.isEmpty()){ day++; Integer last=treeSet.last(); Integer first=treeSet.pollFirst(); Integer next=first+d+1; hash.put(first,day); while(next<=last){ if(treeSet.contains(next)){ hash.put(next,day); treeSet.remove(next); next=next+d+1; } else{ TreeSet<Integer> value =new TreeSet<Integer>(); value=(TreeSet<Integer>)treeSet.tailSet(next); hash.put(value.first(),day); next=value.first()+d+1; treeSet.remove(value.first()); } } } StringBuffer sb=new StringBuffer(); sb.append(day).append('\n'); for(Map.Entry<Integer,Integer> entry: hash.entrySet()){ sb.append(entry.getValue()).append(" "); } System.out.println(sb); } }
Java
["4 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
a5cd22359f677bbb982ff67ec1e42e2c
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
import java.util.*; public class a{ public static void main(String[] args) { Scanner in=new Scanner(System.in); int n=in.nextInt(); int m=in.nextInt(); int d=in.nextInt(); TreeSet<Integer> treeSet=new TreeSet<Integer>(); LinkedHashMap<Integer,Integer> hash=new LinkedHashMap<Integer,Integer>(); for(int i=0;i<n;i++){ int x=in.nextInt(); treeSet.add(x); hash.put(x,0); } int day=0; while(!treeSet.isEmpty()){ day++; Integer last=treeSet.last(); Integer first=treeSet.pollFirst(); Integer next=first+d+1; hash.put(first,day); while(next<=last){ if(treeSet.contains(next)){ hash.put(next,day); treeSet.remove(next); } else{ next=treeSet.ceiling(next); hash.put(next,day); treeSet.remove(next); } next=next+d+1; } } System.out.println(day); for(Map.Entry<Integer,Integer> entry: hash.entrySet()){ System.out.print(entry.getValue()+" "); } } }
Java
["4 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
f9fb6b8fcff2f8152238b5aae6689b65
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
import java.io.*; import java.util.*; import java.math.*; import java.lang.*; import static java.lang.Math.*; public class fast implements Runnable { static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; private BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars==-1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if(numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while(isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if(c<'0'||c>'9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } class Pair implements Comparable<Pair>, Comparator<Pair>{ int x; long y; Pair(int xi, long yi){ x=xi; y=yi; } @Override public int compareTo(Pair other){ if(this.y>other.y) return 1; if(this.y<other.y) return -1; return 0; } @Override public int compare(Pair p1,Pair p2){ if (p1.y > p2.y) return 1; else if(p1.y < p2.y) return -1; return 0; } } public static void main(String args[]) throws Exception { new Thread(null, new fast(),"fast",1<<26).start(); } public void sortbyColumn(int arr[][], int col){ // Using built-in sort function Arrays.sort Arrays.sort(arr, new Comparator<int[]>() { @Override // Compare values according to columns public int compare(final int[] entry1, final int[] entry2) { // To sort in descending order revert // the '>' Operator if (entry1[col] > entry2[col]) return 1; else if(entry1[col] < entry2[col]) return -1; return 0; } }); // End of function call sort(). } public void sortbyColumn(long arr[][], int col){ // Using built-in sort function Arrays.sort Arrays.sort(arr, new Comparator<long[]>() { @Override // Compare values according to columns public int compare(final long[] entry1, final long[] entry2) { // To sort in descending order revert // the '>' Operator if (entry1[col] > entry2[col]) return 1; else if(entry1[col] < entry2[col]) return -1; return 0; } }); // End of function call sort(). } long power(long x, long y, long p){ long res = 1; x = x % p; while (y > 0) { if((y & 1)==1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } long ncr(int n, int r, long p){ long C[]=new long[r+1]; C[0] = 1; for (int i = 1; i <= n; i++) { for (int j = Math.min(i, r); j > 0; j--) C[j] = (C[j] + C[j-1])%p; } return C[r]; } public void run(){ Scanner s = new Scanner(System.in); PrintWriter w = new PrintWriter(System.out); int n=s.nextInt(),len=s.nextInt(),min=s.nextInt(),ans[]=new int[n],day=1; TreeSet<Pair> ar=new TreeSet<>(); for(int i=0;i<n;i++){ ar.add(new Pair(i,s.nextInt())); } while(!ar.isEmpty()){ long up=0; Pair p=ar.first(); while(p!=null){ ans[p.x]=day; up=p.y+min+1; ar.remove(p); p=ar.higher(new Pair(0,up-1)); } day++; } System.out.println(day-1); for(int i:ans) System.out.print(i+" "); w.close(); } }
Java
["4 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
6d93036c0d852431fadbd20ecc493bc3
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
import java.util.*; import java.io.*; public class Main { static long gcd(long a,long b) { //System.out.println("a "+a+" b "+b); if(b==0) { return a; } return gcd(b,a%b); } static void debug(Object... O) { System.out.println(Arrays.deepToString(O)); } static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } static class Pair implements Comparable<Pair>{ int time,ind; public Pair(int t,int i) { time = t; ind = i; } public int compareTo(Pair p) { return this.time - p.time; } } public static void main(String[] args) throws IOException{ //Scanner sc = new Scanner(System.in); Reader sc = new Reader(); int n = sc.nextInt(); int m = sc.nextInt(); int d = sc.nextInt(); TreeSet<Pair> ts = new TreeSet<Pair>(); for(int i=0;i<n;i++) { int num = sc.nextInt(); ts.add(new Pair(num,i)); } Pair top = ts.pollFirst(); int time = top.time+d+1; int day = 1; int[] A = new int[n]; A[top.ind] = day; while(!ts.isEmpty()) { top = ts.ceiling(new Pair(time,0)); if(top == null) { day++; time = ts.first().time; }else { A[top.ind] = day; time = top.time + d + 1; ts.remove(top); } } System.out.println(day); StringBuilder ans = new StringBuilder(); for(int i=0;i<n;i++) { ans.append(A[i]); ans.append(" "); } ans.deleteCharAt(ans.length()-1); System.out.println(ans); } }
Java
["4 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
3bbc21f26752777bd743662762768bac
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
import javax.swing.event.TreeSelectionEvent; import java.io.DataInputStream; import java.io.IOException; import java.util.Arrays; import java.util.TreeMap; import java.util.TreeSet; public class Main { public static void main(String... args) throws IOException { Reader reader = new Reader(); int n = reader.nextInt(); int m = reader.nextInt(); int d = reader.nextInt(); int a[] = new int[n]; int b[] = new int[n]; for (int i = 0; i < n; i++) { b[i] = a[i] = reader.nextInt(); } Arrays.sort(b); int dc = 1; TreeMap<Integer, Integer> tm = new TreeMap<>(); TreeMap<Integer, Integer> ans = new TreeMap<>(); for (int i = 0; i < n; i++) { Integer lk = tm.lowerKey(b[i] - d); if(lk == null) { tm.put(b[i], dc); ans.put(b[i], dc); dc++; } else { tm.put(b[i], tm.get(lk)); ans.put(b[i], tm.get(lk)); tm.remove(lk); } } System.out.println(dc - 1); for (int i = 0; i < n; i++) { System.out.print(ans.get(a[i]) + " "); } System.out.println(); } static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } //Will read words with space as delimiters public String nextWord() throws IOException { byte[] buf = new byte[64]; // word length byte c = read(); while (c == ' ') c = read(); int cnt = 0; do { buf[cnt++] = c; c = read(); } while (c != ' ' && c != '\n'); 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; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } }
Java
["4 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
91be226d3bdd5f4229786f1e65ffebe3
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
import java.io.*; import java.util.*; import java.math.*; import java.lang.*; import static java.lang.Math.*; public class CoffeeBreak implements Runnable { static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; private BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars==-1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if(numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while(isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if(c<'0'||c>'9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static int binarySearch(Pair b[], int l, int r, int key) { int mid,ans=r; while(l<=r) { mid=(l+r)/2; if(b[mid].time==key) { ans=mid; r=mid-1; } else if(b[mid].time<key) { l=mid+1; } else { r=mid-1; ans=r; } } return ans; } public static void main(String args[]) throws Exception { new Thread(null, new CoffeeBreak(),"CoffeeBreak",1<<27).start(); } // **just change the name of class from Main to reuquired** public void run() { InputReader sc = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); int n=sc.nextInt(); int m=sc.nextInt(); int d=sc.nextInt(); Pair b[]= new Pair[n]; int counter=0; int ans[]= new int[n]; for(int i=0;i<n;++i) b[i]=new Pair(sc.nextInt(),i); Arrays.sort(b,new sortByTime()); //for(int i=0;i<n;++i) System.out.println(b[i].time+" "+b[i].index); boolean visited[]= new boolean[n]; for(int i=0;i<n;++i) { if(!visited[i]) { visited[i]=true; counter++; ans[b[i].index]=counter; int lastTime=b[i].time; int key=lastTime+d+1; int curr=i+1; int right=n-1; while(binarySearch(b,curr,right,key)<=(n-1)) { int index=binarySearch(b,curr,right,key); //System.out.println("index:"+index); while(index<n && (visited[index] || (b[index].time-lastTime)<=d)) index++; if(index>=n) break; if(index==(n-1) && (visited[index] || (b[index].time-lastTime)<=d)) break; //System.out.println("lastTime:"+lastTime+" currTime:"+b[index].time); visited[index]=true; ans[b[index].index]=counter; lastTime=b[index].time; key=lastTime+d+1; curr=index+1; } } } /* for(int i=0;i<n;++i) { if(!visited[i]) { int lastTime=b[i].time; counter++; visited[i]=true; ans[b[i].index]=counter; for(int j=i+1;j<n;++j) { if(!visited[j] && (b[j].time-lastTime)>d) { visited[j]=true; lastTime=b[j].time; ans[b[j].index]=counter; } } } }*/ w.println(counter); for(int i=0;i<n;++i) w.print(ans[i]+" "); System.out.flush(); w.close(); } } class Pair { int time; int index; Pair(int t, int in) { time=t; index=in; } } class sortByTime implements Comparator<Pair> { public int compare(Pair p1, Pair p2) { return p1.time-p2.time; } }
Java
["4 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
86e9e577a0095f9fce9ef3a48550b30f
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
import java.io.*; import java.util.*; import java.math.*; import java.lang.*; import static java.lang.Math.*; public class CoffeeBreak2 implements Runnable { static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; private BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars==-1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if(numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while(isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if(c<'0'||c>'9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } public static void main(String args[]) throws Exception { new Thread(null, new CoffeeBreak2(),"CoffeeBreak2",1<<27).start(); } // **just change the name of class from Main to reuquired** public void run() { InputReader sc = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); int n=sc.nextInt(); int m=sc.nextInt(); int d=sc.nextInt(); TreeSet<Pair> set = new TreeSet<>(); for(int i=0;i<n;++i) set.add(new Pair(sc.nextInt(),i)); int ans[]= new int[n]; int counter=1; while(!set.isEmpty()) { Pair p =set.first(); ans[p.index]=counter; int lastTime=p.time; set.remove(p); while(set.ceiling(new Pair(lastTime+d+1,-1))!=null) { Pair p2=set.ceiling(new Pair(lastTime+d+1,-1)); ans[p2.index]=counter; lastTime=p2.time; set.remove(p2); } counter++; } w.println(counter-1); for(int i=0;i<n;++i) w.print(ans[i]+" "); System.out.flush(); w.close(); } } class Pair implements Comparator<Pair>, Comparable<Pair> { int time; int index; Pair(int t, int in) { time=t; index=in; } public int compareTo(Pair other) { return this.time-other.time; } public int compare(Pair p1, Pair p2) { return p1.time-p2.time; } }
Java
["4 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
a2dce2fa64bc3729c9b6885dc64af653
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
import java.io.*; import java.util.Arrays; import java.util.StringTokenizer; import java.util.TreeSet; import static java.lang.Integer.parseInt; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Arrays.binarySearch; import static java.util.Arrays.sort; public class Main { public static void main(String[] args) throws IOException { try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in, UTF_8)); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out, UTF_8))) { StringTokenizer tokens = new StringTokenizer(in.readLine()); int n = parseInt(tokens.nextToken()); int m = parseInt(tokens.nextToken()); int d = parseInt(tokens.nextToken()); int[] a = new int[n]; tokens = new StringTokenizer(in.readLine()); for (int i = 0; i < n; i++) { a[i] = parseInt(tokens.nextToken()); } int[] orig = Arrays.copyOf(a, n); sort(a); int[] pos = new int[n]; int curr = 1; int max = 0; TreeSet<Integer> available = new TreeSet<>(); for (int i = 0; i < n; i++) { available.add(i); } for (int i = 0; i < n; i++) { if (pos[i] > 0) { continue; } pos[i] = curr; available.remove(i); max = curr; int next = a[i] + d + 1; while (true) { int p = binarySearch(a, next); if (p < 0) { p = -(p + 1); } Integer avPos = available.ceiling(p); if (avPos != null) { p = avPos; pos[p] = curr; available.remove(p); next = a[p] + d + 1; } else { break; } } curr++; } out.write(max + ""); out.newLine(); for (int i = 0; i < pos.length; i++) { int j = binarySearch(a, orig[i]); if (i > 0) { out.write(" " + pos[j]); } else { out.write("" + pos[j]); } } out.newLine(); } } }
Java
["4 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
bb5a711ec24bb2cf5ebde227726044f2
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
import java.io.*; import java.util.*; import java.math.*; public class C1041 { static char[] sarr; public static void main(String[] args) throws IOException { FastScanner fs=new FastScanner(); PrintWriter out = new PrintWriter(System.out); // int T = 1; // int T=fs.nextInt(); // for (int tt=0; tt<T; tt++) { // } int n = fs.nextInt(); int m = fs.nextInt(); int d = fs.nextInt(); int[] arr = new int[n]; TreeMap<Integer, Integer> treeMap = new TreeMap(); for (int i=0; i<n; i++) { arr[i] = fs.nextInt(); treeMap.put(arr[i],i); } int[] days = new int[n]; int current_day = 1; while (treeMap.size()!=0) { Map.Entry<Integer,Integer> entry = treeMap.higherEntry(0); arr[entry.getValue()]=current_day; treeMap.remove(entry.getKey()); while (treeMap.higherEntry(entry.getKey()+d)!=null) { entry = treeMap.higherEntry(entry.getKey()+d); arr[entry.getValue()]=current_day; treeMap.remove(entry.getKey()); } current_day++; } out.println(current_day-1); for (int i=0; i<n; i++) { out.print(arr[i]+" "); } out.println(); out.close(); } static final Random random=new Random(); static void ruffleSort(int[] a) { int n=a.length;//shuffle, then sort for (int i=0; i<n; i++) { int oi=random.nextInt(n), temp=a[oi]; a[oi]=a[i]; a[i]=temp; } Arrays.sort(a); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["4 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
139172488d3e9e3068f66f6c9b05617d
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
import java.io.*; import java.util.*; import java.lang.*; import java.util.HashMap; import java.util.PriorityQueue; public class templ implements Runnable { class pair { int f,s; pair(int fi,int se) { f=fi; s=se; } } public static int M=1000000007; static int binarySearch(int arr[], int l, int r, int x) { if (r >= l) { int mid = l + (r - l)/2; if (arr[mid] == x) return mid; if (arr[mid] > x) return binarySearch(arr, l, mid-1, x); return binarySearch(arr, mid+1, r, x); } return -1; } void merge1(int arr[], int l, int m, int r) { int n1 = m - l + 1; int n2 = r - m; int L[] = new int [n1]; int R[] = new int [n2]; for (int i=0; i<n1; ++i) L[i] = arr[l + i]; for (int j=0; j<n2; ++j) R[j] = arr[m + 1+ j]; int i = 0, j = 0; int k = l; while (i < n1 && j < n2) { if (L[i]<=R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } while (i < n1) { arr[k] = L[i]; i++; k++; } while (j < n2) { arr[k] = R[j]; j++; k++; } } void sort1(int arr[], int l, int r) { if (l < r) { int m = (l+r)/2; sort1(arr, l, m); sort1(arr , m+1, r); merge1(arr, l, m, r); } } void merge3(int arr[],int arr1[],int arr2[], int l, int m, int r) { int n1 = m - l + 1; int n2 = r - m; int L[] = new int [n1]; int R[] = new int [n2]; int L1[]=new int[n1]; int R1[]=new int[n2]; int L2[]=new int[n1]; int R2[]=new int[n2]; //long L3[]=new long[n1]; //long R3[]=new long[n2]; for (int i=0; i<n1; ++i) { L[i] = arr[l + i]; L1[i]=arr1[l+i]; L2[i]=arr2[l+i]; //L3[i]=arr3[l+i]; } for (int j=0; j<n2; ++j) { R[j] = arr[m + 1+ j]; R1[j]=arr1[m+1+j]; R2[j]=arr2[m+1+j]; //R3[j]=arr3[m+1+j]; } int i = 0, j = 0; int k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; arr1[k]=L1[i]; arr2[k]=L2[i]; //arr3[k]=L3[i]; i++; } else { arr[k] = R[j]; arr1[k]=R1[j]; arr2[k]=R2[j]; //arr3[k]=R3[j]; j++; } k++; } while (i < n1) { arr[k] = L[i]; arr1[k]=L1[i]; arr2[k]=L2[i]; //arr3[k]=L3[i]; i++; k++; } while (j < n2) { arr[k] = R[j]; arr1[k]=R1[j]; arr2[k]=R2[j]; //arr3[k]=R3[j]; j++; k++; } } void sort3(int arr[],int arr1[],int arr2[], int l, int r) { if (l < r) { int m = (l+r)/2; sort3(arr,arr1,arr2, l, m); sort3(arr ,arr1,arr2, m+1, r); merge3(arr,arr1,arr2,l, m, r); } } void merge2(int arr[],int arr1[],int l, int m, int r) { int n1 = m - l + 1; int n2 = r - m; int L[] = new int [n1]; int R[] = new int [n2]; int L1[]=new int[n1]; int R1[]=new int[n2]; for (int i=0; i<n1; ++i) { L[i] = arr[l + i]; L1[i]=arr1[l+i]; } for (int j=0; j<n2; ++j) { R[j] = arr[m + 1+ j]; R1[j]=arr1[m+1+j]; } int i = 0, j = 0; int k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; arr1[k]=L1[i]; i++; } else { arr[k] = R[j]; arr1[k]=R1[j]; j++; } k++; } while (i < n1) { arr[k] = L[i]; arr1[k]=L1[i]; i++; k++; } while (j < n2) { arr[k] = R[j]; arr1[k]=R1[j]; j++; k++; } } void sort2(int arr[],int arr1[],int l, int r) { if (l < r) { int m = (l+r)/2; sort2(arr,arr1, l, m); sort2(arr ,arr1, m+1, r); merge2(arr,arr1,l, m, r); } } void merge4(int arr[],int arr1[],int arr2[],int arr3[], int l, int m, int r) { int n1 = m - l + 1; int n2 = r - m; int L[] = new int [n1]; int R[] = new int [n2]; int L1[]=new int[n1]; int R1[]=new int[n2]; int L2[]=new int[n1]; int R2[]=new int[n2]; int L3[]=new int[n1]; int R3[]=new int[n2]; for (int i=0; i<n1; ++i) { L[i] = arr[l + i]; L1[i]=arr1[l+i]; L2[i]=arr2[l+i]; L3[i]=arr3[l+i]; } for (int j=0; j<n2; ++j) { R[j] = arr[m + 1+ j]; R1[j]=arr1[m+1+j]; R2[j]=arr2[m+1+j]; R3[j]=arr3[m+1+j]; } int i = 0, j = 0; int k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; arr1[k]=L1[i]; arr2[k]=L2[i]; arr3[k]=L3[i]; i++; } else { arr[k] = R[j]; arr1[k]=R1[j]; arr2[k]=R2[j]; arr3[k]=R3[j]; j++; } k++; } while (i < n1) { arr[k] = L[i]; arr1[k]=L1[i]; arr2[k]=L2[i]; arr3[k]=L3[i]; i++; k++; } while (j < n2) { arr[k] = R[j]; arr1[k]=R1[j]; arr2[k]=R2[j]; arr3[k]=R3[j]; j++; k++; } } void sort4(int arr[],int arr1[],int arr2[],int arr3[], int l, int r) { if (l < r) { int m = (l+r)/2; sort4(arr,arr1,arr2,arr3, l, m); sort4(arr ,arr1,arr2,arr3, m+1, r); merge4(arr,arr1,arr2,arr3,l, m, r); } } public int justsmall(long a[],int l,int r,long x) { int p=-1; while(l<=r) { int mid=(l+r)/2; if(a[mid]<=x) { p=mid; l=mid+1; } else r=mid-1; } return p; } public int justlarge(long a[],int l,int r,long x) { int p=0; while(l<=r) { int mid=(l+r)/2; if(a[mid]<x) { l=mid+1; } else { p=mid; r = mid - 1; } } return p; } long gcd(long x,long y) { if(x%y==0) return y; else return(gcd(y,x%y)); } int fact(int n) { int ans=1; for(int i=1;i<=n;i++) ans*=i; return ans; } long bintoint(String s) { long a=0; int l=s.length(); int k=0; for(int i=l-1;i>=0;i--) { char c=s.charAt(i); if(c=='1') { a=a+(long)Math.pow(2,k); } k++; } return a; } String inttobin(long x) { String s=""; while(x!=0) { long k=x%2; if(k==1) s="1"+s; else s="0"+s; x=x/2; } return s; } public static void main(String args[])throws Exception { new Thread(null,new templ(),"templ",1<<26).start(); } public void run() { try { InputReader in = new InputReader(System.in); PrintWriter out = new PrintWriter(System.out); int n=in.ni(); int m=in.ni(); int d=in.ni(); int a[]=new int[n]; int b[]=new int[n]; for(int i=0;i<n;i++) { a[i]=in.ni(); b[i]=i; } sort2(a,b,0,n-1); int c[]=new int[n]; HashMap<Integer,Integer>hm=new HashMap<>(); pair q[]=new pair[n+10]; int front=0,rear=-1; int level=0; for(int i=0;i<n;i++) { if(front==-1||front>rear) { level++; pair p=new pair(level,a[i]+d+1); if(d+2<=m) { if(front==-1) front=0; rear++; q[rear]=p; } hm.put(level,a[i]); c[b[i]]=level; continue; } pair p=q[front]; int lev=p.f; int val=p.s; if(val>a[i]) { level++; hm.put(level,a[i]); pair p1=new pair(level,a[i]+d+1); if(d+2<=m) { rear++; q[rear]=p1; } c[b[i]]=level; continue; } int x=hm.get(lev); front++; val=a[i]+d+1; if(val-x+1<=m) { pair p1=new pair(lev,val); rear++; q[rear]=p1; } c[b[i]]=lev; } out.println(level); for(int i=0;i<n;i++) out.print(c[i]+" "); out.close(); } catch(Exception e){ return; } } static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int ni() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nl() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = ni(); } return a; } public String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } }
Java
["4 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
a754e5ea6a1d509edf477ac22b8e95ad
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
import java.io.*; import java.math.*; import java.text.*; import java.util.*; import java.util.regex.*; public class Solution { static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; public InputReader(InputStream st) { this.stream = st; } public int read() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } public static void main(String[] args) throws Exception { InputReader in=new InputReader(System.in); PrintWriter w=new PrintWriter(System.out); int n=in.nextInt(); int m=in.nextInt(); int d=in.nextInt(); int[] ar=new int[n]; //int[] ix=new int[m+1]; HashMap<Integer,Integer> map=new HashMap<Integer,Integer>(); int[] days=new int[n]; boolean[] vis=new boolean[n]; ar=in.nextIntArray(n); for(int i=0;i<n;i++) { map.put(ar[i],i); } Arrays.sort(ar); int curday=1; for(int i=0;i<n;i++) { if(!vis[i]) { int cur=ar[i]; days[map.get(cur).intValue()]=curday; vis[i]=true; while(cur<m) { int num=cur+1+d; if(num>m) break; int index=Arrays.binarySearch(ar,num); if(index<0) index=(-1)*(index+1); if(index>=n) break; if(!vis[index]) { cur=ar[index]; vis[index]=true; days[map.get(ar[index]).intValue()]=curday; } else { while(index<n && vis[index]) { index++; } if(index<=n-1) { cur=ar[index]; vis[index]=true; days[map.get(ar[index]).intValue()]=curday; } else { break; } } } curday++; } } w.println(curday-1); for(int i=0;i<n;i++) { w.print(days[i]+" "); } w.println(); w.close(); } }
Java
["4 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
93cb995adef8a0dd39b178a38d11f523
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
import java.util.*; import java.io.*; import static java.lang.Math.*; public class Test { FastIO sc; static int n; static int[][] dp; static boolean check(boolean[] vis) { boolean r = false; for (boolean e : vis) { if (e) { r = true; break; } } return r; } void solve() throws Exception { n=sc.nextInt(); int m=sc.nextInt(); int d=sc.nextInt(); TreeSet<Pair> set = new TreeSet<>(); for(int i=0;i<n;++i) set.add(new Pair(sc.nextInt(),i)); int ans[]= new int[n]; int counter=1; while(!set.isEmpty()) { Pair p =set.first(); ans[p.index]=counter; int lastTime=p.time; set.remove(p); while(set.ceiling(new Pair(lastTime+d+1,-1))!=null) { Pair p2=set.ceiling(new Pair(lastTime+d+1,-1)); ans[p2.index]=counter; lastTime=p2.time; set.remove(p2); } counter++; } System.out.println(counter-1); for(int i=0;i<n;++i) System.out.print(ans[i]+" "); System.out.flush(); } void run() { try { sc = new FastIO(); solve(); sc.close(); } catch (Exception e) { e.printStackTrace(); System.exit(abs(-1)); } } public static void main(String[] args) { try { Locale.setDefault(Locale.US); } catch (Exception ignore) { } new Test().run(); } class FastIO extends PrintWriter { private BufferedReader in; private StringTokenizer stok; FastIO() { super(System.out); in = new BufferedReader(new InputStreamReader(System.in)); } FastIO(String s) throws FileNotFoundException { super("".equals(s) ? "output.txt" : s + ".out"); in = new BufferedReader(new FileReader("".equals(s) ? "input.txt" : s + ".in")); } @Override public void close() { super.close(); try { in.close(); } catch (IOException ignored) { } } String next() { while (stok == null || !stok.hasMoreTokens()) { try { stok = new StringTokenizer(in.readLine()); } catch (Exception e) { return null; } } return stok.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { try { return in.readLine(); } catch (IOException e) { return null; } } char[] nextCharArray() { return next().toCharArray(); } } class Pair implements Comparator<Pair>, Comparable<Pair> { int time; int index; Pair(int t, int in) { time=t; index=in; } public int compareTo(Pair other) { return this.time-other.time; } public int compare(Pair p1, Pair p2) { return p1.time-p2.time; } } class IntArray { private int capacity; private int[] data; private int size = 0; IntArray(int capacity) { this.capacity = capacity; this.data = new int[capacity]; } IntArray() { this(16); } int get(int index) { return data[index]; } void add(int x) { if (size == capacity) { int[] newData = new int[capacity * 2]; System.arraycopy(data, 0, newData, 0, capacity); data = newData; capacity *= 2; } data[size++] = x; } } void randomShuffle(int[] a) { Random random = new Random(); for (int i = 1; i < a.length; i++) { int x = random.nextInt(i + 1); int xchg = a[i]; a[i] = a[x]; a[x] = xchg; } } }
Java
["4 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
f89055877141600b167b91e7483bf5a0
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
import javax.swing.text.html.HTMLDocument; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.StringReader; import java.math.BigInteger; import java.nio.Buffer; import java.util.*; public class Main { public static void main(String[] args){ try { PrintWriter out=new PrintWriter(System.out,true); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String[] ss = br.readLine().split(" "); int n = Integer.parseInt(ss[0]); int m = Integer.parseInt(ss[1]); int d = Integer.parseInt(ss[2]); ss = br.readLine().split(" "); int[] arr = new int[n]; List<Integer> list =new ArrayList<>(); for(int i=0;i<n;i++){ arr[i] = Integer.parseInt(ss[i]); list.add(arr[i]); } Collections.sort(list); Map<Integer,Integer> map = new HashMap<>(); map.put(list.get(0),1); int p=list.get(0)+d+1; Queue<int[]> q= new ArrayDeque<>(); q.add(new int[]{list.get(0),1}); int u=2,i; for(i=1;i<list.size();i++){ if(list.get(i)<p){ map.put(list.get(i),u); q.add(new int[]{list.get(i),u}); u++; }else{ break; } } for(;i<list.size();i++){ if(q.size()>0) { int[] pp = q.peek(); if (list.get(i) - pp[0] > d) { q.poll(); map.put(list.get(i),pp[1]); q.add(new int[]{list.get(i), pp[1]}); } else { map.put(list.get(i),u); q.add(new int[]{list.get(i),u}); u++; } }else{ map.put(list.get(i),u); q.add(new int[]{list.get(i),u}); u++; } } StringBuilder str = new StringBuilder(""); int max=1; for(int j=0;j<n;j++){ arr[j]=map.get(arr[j]); max=Math.max(arr[j],max); str.append(arr[j]).append(" "); } out.println(max); out.println(str); out.close(); } catch (Exception e) { System.out.println("kkkk "+e.toString()); } } static void swap(int[] arr,int i,int j){ int temp = arr[i-1]; arr[i-1] = arr[j-1]; arr[j-1] = temp; } static int diff(String s1,String s2){ int c=0; for(int i=0;i<s1.length();i++){ if(s1.charAt(i)!=s2.charAt(i)){ c++; } } return c; } static boolean isPal(String s){ StringBuilder str=new StringBuilder(s); str=str.reverse(); String ss=String.valueOf(str); if (ss.equals(s)) { return true; } return false; } static int mod(int a,int b){ if (a>b){ return a-b; } return b-a; } static void shuffle(int[] a) { Random get = new Random(); for (int i = 0; i < a.length; i++) { int r = get.nextInt(a.length); int temp = a[i]; a[i] = a[r]; a[r] = temp; } } static int lcm(int a,int b){ long c=a*((long)b); return (int)(c/hcf(a,b)); } static int hcf(int a,int b){ if(a==0){ return b; } if(b==0){ return a; } if(a>b) return hcf(a%b,b); return hcf(a,b%a); } static int modInverse(int x,int m){ return power(x,m-2,m); } static int power(int x, int y, int m) { if (y == 0) return 1; long p = power(x, y / 2, m) % m; p = (p * p) % m; return (int)((y%2==0)? p : (x*p)%m); } static class pair{ long a; int b,c; public pair(long a,int b,int c){ this.a=a; this.b=b; this.c=c; } } }
Java
["4 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
353bc44e6d321e0e5e7fe0ecabd39efd
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
import java.lang.*; import java.math.*; import java.util.*; import java.io.*; public class Main { class Node implements Comparable<Node>{ long id; long d; public Node(long id,long d){ this.id=id; this.d=d; } public int compareTo(Node c){ int t=Long.compare(this.d,c.d); if(t!=0) return t; t=Long.compare(this.id,c.id); return t; } } void solve(){ int n=ni(); long m=nl(),d=nl(); Node nd[]=new Node[n+1]; for(int i=1;i<=n;i++) { // a[i]=nl(); nd[i]=new Node(i,nl()); } Arrays.sort(nd,1,n+1); long l=1,r=n; long ans=n; long b[]=new long[n+1]; PriorityQueue<Node>ts=new PriorityQueue<>(); long dd=0; ts.clear(); for(int i=1;i<=n;i++){ while(!ts.isEmpty() && ts.peek().d>m) ts.poll(); if(!ts.isEmpty() && ts.peek().d<=nd[i].d){ Node p=ts.poll(); b[(int)nd[i].id]=p.id; ts.add(new Node(p.id,nd[i].d+d+1)); }else { b[(int)nd[i].id]=++dd; ts.add(new Node(dd,nd[i].d+d+1)); } } ans=dd; pw.println(ans); for(int i=1;i<=n;i++) pw.print(b[i]+" "); } long gcd(long a,long b){ long r; while(b!=0){ r=a%b; a=b; b=r; } return a; } long M=(long)1e9+7; InputStream is; PrintWriter pw; String INPUT = ""; void run() throws Exception { is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes()); pw = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); pw.flush(); if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms"); } public static void main(String[] args) throws Exception { new Main().run(); } private byte[] inbuf = new byte[1024]; public int lenbuf = 0, ptrbuf = 0; private int readByte() { if(lenbuf == -1)throw new InputMismatchException(); if(ptrbuf >= lenbuf){ ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if(lenbuf <= 0)return -1; } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char)skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while(p < n && !(isSpaceChar(b))){ buf[p++] = (char)b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private char[][] nm(int n, int m) { char[][] map = new char[n][]; for(int i = 0;i < n;i++)map[i] = ns(m); return map; } private int[] na(int n) { int[] a = new int[n]; for(int i = 0;i < n;i++)a[i] = ni(); return a; } private int ni() { int num = 0, b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private long nl() { long num = 0; int b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private boolean oj = System.getProperty("ONLINE_JUDGE") != null; private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); } }
Java
["4 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
eb7a745c613081ace2bdcdfc3b1c59d8
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
import java.util.Scanner; import java.util.Arrays; import java.util.Comparator; public class test { static int n; static int m; static int d; static pair[] a; private static class pair implements Comparable<pair> { int n1; int n2; public pair(int n1, int n2) { this.n1 = n1; this.n2 = n2; } public int compareTo(pair other) { if( n1 < other.n1 ) { return -1; } return 1; } } private static boolean f(int days) { for(int i = 0; i+days < n; i++) { if(a[i].n1 + d >= a[i + days].n1) { return false; } } return true; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); n = sc.nextInt(); m = sc.nextInt(); d = sc.nextInt(); a = new pair[n]; for(int i = 0;i<n;i++) { int x = sc.nextInt(); a[i] = new pair(x, i); } Arrays.sort(a); int good = n; int bad = 0; while(bad+1 < good) { int middle = (good + bad)/2; if(f(middle)) { good = middle; } else { bad = middle; } } int[] answer = new int[n]; for(int i = 0;i<n;i++) { answer[ a[i].n2 ] = i % good + 1; } System.out.println(good); for(int i = 0; i < n; i++) { System.out.print(answer[i] + " "); } } }
Java
["4 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
d7bfff1771f21e92c05d849bab0da732
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
import java.io.*; import java.util.*; public class Main_Round509Div2_C { private static Scanner sc; private static Printer pr; private static void solve() { int n = sc.nextInt(); @SuppressWarnings("unused") int m = sc.nextInt(); int d = sc.nextInt(); List<Pair> a = new ArrayList<>(n); for (int i = 0; i < n; i++) { a.add(new Pair(sc.nextInt(), i)); } Collections.sort(a); PriorityQueue<Pair> pq = new PriorityQueue<>(); int cnt = 0; int[] ans = new int[n]; for (Pair e : a) { if (pq.isEmpty()) { pq.add(new Pair(e.a, ++cnt)); ans[e.b] = cnt; } else { Pair ee = pq.peek(); if (ee.a + d + 1 <= e.a) { pq.remove(); pq.add(new Pair(e.a, ee.b)); ans[e.b] = ee.b; } else { pq.add(new Pair(e.a, ++cnt)); ans[e.b] = cnt; } } } pr.println(cnt); for (int i = 0; i < n; i++) { if (i > 0) { pr.print(' '); } pr.print(ans[i]); } pr.println(); } static class Pair implements Comparable<Pair> { int a; int b; Pair(int a, int b) { this.a = a; this.b = b; } @Override public int compareTo(Pair o) { if (a == o.a) { return Integer.compare(b, o.b); } return Integer.compare(a, o.a); } @Override public int hashCode() { return Integer.hashCode(a + b); } @Override public boolean equals(Object obj) { Pair o = (Pair) obj; return a == o.a && b == o.b; } @Override public String toString() { // [xxx, xxxx] StringBuilder stmp = new StringBuilder(32); stmp.append('['); stmp.append(a); stmp.append(','); stmp.append(' '); stmp.append(b); stmp.append(']'); return stmp.toString(); } } // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(INPUT == null ? System.in : new ByteArrayInputStream(INPUT.getBytes())); pr = new Printer(System.out); solve(); // pr.close(); pr.flush(); // sc.close(); } static String INPUT = null; @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } private boolean isPrintable(int ch) { return ch >= '!' && ch <= '~'; } private boolean isCRLF(int ch) { return ch == '\n' || ch == '\r' || ch == -1; } private int nextPrintable() { try { int ch; while (!isPrintable(ch = br.read())) { if (ch == -1) { throw new NoSuchElementException(); } } return ch; } catch (IOException e) { throw new NoSuchElementException(); } } String next() { try { int ch = nextPrintable(); StringBuilder sb = new StringBuilder(); do { sb.appendCodePoint(ch); } while (isPrintable(ch = br.read())); return sb.toString(); } catch (IOException e) { throw new NoSuchElementException(); } } int nextInt() { try { // parseInt from Integer.parseInt() boolean negative = false; int res = 0; int limit = -Integer.MAX_VALUE; int radix = 10; int fc = nextPrintable(); if (fc < '0') { if (fc == '-') { negative = true; limit = Integer.MIN_VALUE; } else if (fc != '+') { throw new NumberFormatException(); } fc = br.read(); } int multmin = limit / radix; int ch = fc; do { int digit = ch - '0'; if (digit < 0 || digit >= radix) { throw new NumberFormatException(); } if (res < multmin) { throw new NumberFormatException(); } res *= radix; if (res < limit + digit) { throw new NumberFormatException(); } res -= digit; } while (isPrintable(ch = br.read())); return negative ? res : -res; } catch (IOException e) { throw new NoSuchElementException(); } } long nextLong() { try { // parseLong from Long.parseLong() boolean negative = false; long res = 0; long limit = -Long.MAX_VALUE; int radix = 10; int fc = nextPrintable(); if (fc < '0') { if (fc == '-') { negative = true; limit = Long.MIN_VALUE; } else if (fc != '+') { throw new NumberFormatException(); } fc = br.read(); } long multmin = limit / radix; int ch = fc; do { int digit = ch - '0'; if (digit < 0 || digit >= radix) { throw new NumberFormatException(); } if (res < multmin) { throw new NumberFormatException(); } res *= radix; if (res < limit + digit) { throw new NumberFormatException(); } res -= digit; } while (isPrintable(ch = br.read())); return negative ? res : -res; } catch (IOException e) { throw new NoSuchElementException(); } } float nextFloat() { return Float.parseFloat(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { try { int ch; while (isCRLF(ch = br.read())) { if (ch == -1) { throw new NoSuchElementException(); } } StringBuilder sb = new StringBuilder(); do { sb.appendCodePoint(ch); } while (!isCRLF(ch = br.read())); return sb.toString(); } catch (IOException e) { throw new NoSuchElementException(); } } void close() { try { br.close(); } catch (IOException e) { // throw new NoSuchElementException(); } } } private static class Printer extends PrintWriter { Printer(OutputStream out) { super(out); } } }
Java
["4 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
d691a2714e6293950eb5bf1a0192f7c1
train_000.jsonl
1537094100
Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.
256 megabytes
// package Practice1.CF1041; import java.util.Arrays; import java.util.Scanner; import java.util.TreeMap; public class CF1041C { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); int m = s.nextInt(); int d = s.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = s.nextInt(); } TreeMap<pair,Integer> map = new TreeMap<>(); int dayCount = 0; for (int i = 0; i < n; i++) { map.put(new pair(i,arr[i]),i); } int count = 1; int[] ans = new int[n]; while(!map.isEmpty()){ pair p = map.firstKey(); int val = p.value; ans[p.index] = count; map.remove(p); while(!map.isEmpty() && map.higherKey(new pair(-1,val + d)) != null){ p = map.higherKey(new pair(-1,val + d)); ans[p.index] = count; map.remove(p); val = p.value; } count++; } System.out.println(count - 1); // System.out.println(Arrays.toString(ans)); for (int i = 0; i < ans.length; i++) { System.out.print(ans[i] + " "); } System.out.println(); } private static class pair implements Comparable<pair>{ int index; int value; public pair(int index, int value) { this.index = index; this.value = value; } @Override public int compareTo(pair o) { return Integer.compare(this.value,o.value); } } }
Java
["4 5 3\n3 5 1 2", "10 10 1\n10 5 7 4 6 3 2 1 9 8"]
2 seconds
["3\n3 1 1 2", "2\n2 1 1 2 2 1 2 1 1 2"]
NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.
Java 8
standard input
[ "data structures", "two pointers", "binary search", "greedy" ]
cc1b29b49711131d4790d91d0fae4a5a
The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$Β β€” the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.
1,600
In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes. In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.
standard output
PASSED
a6056210d69cff99b40591f34cb27baa
train_000.jsonl
1601827500
Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.
256 megabytes
import java.util.*; import java.io.*; public class Problem { static int memo[][]; static long a, b, c, n, v, m, e, t; static ArrayList[] edgeList; static int[][] matrix; // static int[] a; final static int Infinity = Integer.MAX_VALUE; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); t = sc.nextInt(); while (t-- > 0) { ArrayList<Long> ts = new ArrayList<Long>(); for (int i = 0; i < 3; i++) ts.add(sc.nextLong()); ts.sort(null); a = ts.get(0); b = ts.get(1); c = ts.get(2); pw.println((long) Math.ceil(Math.sqrt(b * b + (c - a) * (c - a)))); } pw.flush(); pw.close(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream system) { br = new BufferedReader(new InputStreamReader(system)); } public Scanner(String file) throws Exception { br = new BufferedReader(new FileReader(file)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public String nextLine() throws IOException { return br.readLine(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public char nextChar() throws IOException { return next().charAt(0); } public Long nextLong() throws IOException { return Long.parseLong(next()); } public boolean ready() throws IOException { return br.ready(); } public void waitForInput() throws InterruptedException { Thread.sleep(3000); } } }
Java
["2\n1 2 3\n12 34 56"]
1 second
["4\n42"]
NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.
Java 8
standard input
[ "geometry", "math" ]
40d679f53417ba058144c745e7a2c76d
The first line contains a single integer $$$t$$$Β β€” the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$Β β€” the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).
800
For each test case print a single integer $$$d$$$Β β€” the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.
standard output