exec_outcome
stringclasses
1 value
code_uid
stringlengths
32
32
file_name
stringclasses
111 values
prob_desc_created_at
stringlengths
10
10
prob_desc_description
stringlengths
63
3.8k
prob_desc_memory_limit
stringclasses
18 values
source_code
stringlengths
117
65.5k
lang_cluster
stringclasses
1 value
prob_desc_sample_inputs
stringlengths
2
802
prob_desc_time_limit
stringclasses
27 values
prob_desc_sample_outputs
stringlengths
2
796
prob_desc_notes
stringlengths
4
3k
βŒ€
lang
stringclasses
5 values
prob_desc_input_from
stringclasses
3 values
tags
listlengths
0
11
src_uid
stringlengths
32
32
prob_desc_input_spec
stringlengths
28
2.37k
βŒ€
difficulty
int64
-1
3.5k
βŒ€
prob_desc_output_spec
stringlengths
17
1.47k
βŒ€
prob_desc_output_to
stringclasses
3 values
hidden_unit_tests
stringclasses
1 value
PASSED
a2c3d04460c2604a925fecdd6b521ebb
train_002.jsonl
1397837400
The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.The slogan of the company consists of n characters, so the decorators hung a large banner, n meters wide and 1 meter high, divided into n equal squares. The first character of the slogan must be in the first square (the leftmost) of the poster, the second character must be in the second square, and so on.Of course, the R1 programmers want to write the slogan on the poster themselves. To do this, they have a large (and a very heavy) ladder which was put exactly opposite the k-th square of the poster. To draw the i-th character of the slogan on the poster, you need to climb the ladder, standing in front of the i-th square of the poster. This action (along with climbing up and down the ladder) takes one hour for a painter. The painter is not allowed to draw characters in the adjacent squares when the ladder is in front of the i-th square because the uncomfortable position of the ladder may make the characters untidy. Besides, the programmers can move the ladder. In one hour, they can move the ladder either a meter to the right or a meter to the left.Drawing characters and moving the ladder is very tiring, so the programmers want to finish the job in as little time as possible. Develop for them an optimal poster painting plan!
256 megabytes
import java.util.Scanner; public class z_1 { public static void main(String args[]){ Scanner in = new Scanner(System.in); int n = in.nextInt(); int k = in.nextInt(); String s = in.next(); if(k > s.length()-k){ for(int i = k-1; i < s.length()-1;i++){ System.out.println("RIGHT"); } for(int i = s.length()-1; i >= 0; i--){ System.out.println("PRINT "+s.charAt(i)); if(i-1>=0)System.out.println("LEFT"); } } else{ for(int i = k-1; i > 0;i--){ System.out.println("LEFT"); } for(int i = 0; i < s.length(); i++){ System.out.println("PRINT "+s.charAt(i)); if(i+1<s.length())System.out.println("RIGHT"); } } } }
Java
["2 2\nR1", "2 1\nR1", "6 4\nGO?GO!"]
1 second
["PRINT 1\nLEFT\nPRINT R", "PRINT R\nRIGHT\nPRINT 1", "RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G"]
NoteNote that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character.
Java 7
standard input
[ "implementation", "greedy" ]
e3a03f3f01a77a1983121bab4218c39c
The first line contains two integers, n and k (1 ≀ k ≀ n ≀ 100) β€” the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as n characters written without spaces. Each character of the slogan is either a large English letter, or digit, or one of the characters: '.', '!', ',', '?'.
900
In t lines, print the actions the programmers need to make. In the i-th line print: "LEFT" (without the quotes), if the i-th action was "move the ladder to the left"; "RIGHT" (without the quotes), if the i-th action was "move the ladder to the right"; "PRINT x" (without the quotes), if the i-th action was to "go up the ladder, paint character x, go down the ladder". The painting time (variable t) must be minimum possible. If there are multiple optimal painting plans, you can print any of them.
standard output
PASSED
a823a190efa35c9c855a7b90792b5186
train_002.jsonl
1397837400
The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.The slogan of the company consists of n characters, so the decorators hung a large banner, n meters wide and 1 meter high, divided into n equal squares. The first character of the slogan must be in the first square (the leftmost) of the poster, the second character must be in the second square, and so on.Of course, the R1 programmers want to write the slogan on the poster themselves. To do this, they have a large (and a very heavy) ladder which was put exactly opposite the k-th square of the poster. To draw the i-th character of the slogan on the poster, you need to climb the ladder, standing in front of the i-th square of the poster. This action (along with climbing up and down the ladder) takes one hour for a painter. The painter is not allowed to draw characters in the adjacent squares when the ladder is in front of the i-th square because the uncomfortable position of the ladder may make the characters untidy. Besides, the programmers can move the ladder. In one hour, they can move the ladder either a meter to the right or a meter to the left.Drawing characters and moving the ladder is very tiring, so the programmers want to finish the job in as little time as possible. Develop for them an optimal poster painting plan!
256 megabytes
import java.util.*; import java.io.*; import java.math.*; import static java.util.Arrays.*; import static java.lang.Math.*; public class Main { static boolean LOCAL = System.getSecurityManager() == null; Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); void run() { int n = in.nextInt(), k = in.nextInt(); char[] cs = in.next().toCharArray(); if (k > n / 2) right(cs, n, k); else left(cs, n, k); } private void left(char[] cs, int n, int k) { for (int i = 1; i < k; i++) { out.println(L); } out.println(P + " " + cs[0]); for (int i = 1; i < n; i++) { out.println(R); out.println(P + " " + cs[i]); } } String R = "RIGHT", L = "LEFT", P = "PRINT"; private void right(char[] cs, int n, int k) { for (; k < n; k++) { out.println(R); } out.println(P + " " + cs[n - 1]); for (int i = n - 2; i >= 0; i--) { out.println(L); out.println(P + " " + cs[i]); } } void debug(Object... os) { System.err.println(deepToString(os)); } public static void main(String[] args) { long start = System.nanoTime(); if (LOCAL) { try { System.setIn(new FileInputStream("./../in")); // System.setOut(new PrintStream("./../in")); } catch (IOException e) { LOCAL = false; } } Main main = new Main(); main.run(); main.out.close(); if (LOCAL) System.err.printf("[Time %.6fs]%n", (System.nanoTime() - start) * 1e-9); } } class Scanner { BufferedReader br; StringTokenizer st; Scanner(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); eat(""); } private void eat(String string) { st = new StringTokenizer(string); } String nextLine() { try { return br.readLine(); } catch (IOException e) { return null; } } boolean hasNext() { while (!st.hasMoreTokens()) { String s = nextLine(); if (s == null) return false; eat(s); } return true; } String next() { hasNext(); return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } }
Java
["2 2\nR1", "2 1\nR1", "6 4\nGO?GO!"]
1 second
["PRINT 1\nLEFT\nPRINT R", "PRINT R\nRIGHT\nPRINT 1", "RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G"]
NoteNote that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character.
Java 7
standard input
[ "implementation", "greedy" ]
e3a03f3f01a77a1983121bab4218c39c
The first line contains two integers, n and k (1 ≀ k ≀ n ≀ 100) β€” the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as n characters written without spaces. Each character of the slogan is either a large English letter, or digit, or one of the characters: '.', '!', ',', '?'.
900
In t lines, print the actions the programmers need to make. In the i-th line print: "LEFT" (without the quotes), if the i-th action was "move the ladder to the left"; "RIGHT" (without the quotes), if the i-th action was "move the ladder to the right"; "PRINT x" (without the quotes), if the i-th action was to "go up the ladder, paint character x, go down the ladder". The painting time (variable t) must be minimum possible. If there are multiple optimal painting plans, you can print any of them.
standard output
PASSED
4445f146a50f6f8fee48b3e77bde33ce
train_002.jsonl
1397837400
The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.The slogan of the company consists of n characters, so the decorators hung a large banner, n meters wide and 1 meter high, divided into n equal squares. The first character of the slogan must be in the first square (the leftmost) of the poster, the second character must be in the second square, and so on.Of course, the R1 programmers want to write the slogan on the poster themselves. To do this, they have a large (and a very heavy) ladder which was put exactly opposite the k-th square of the poster. To draw the i-th character of the slogan on the poster, you need to climb the ladder, standing in front of the i-th square of the poster. This action (along with climbing up and down the ladder) takes one hour for a painter. The painter is not allowed to draw characters in the adjacent squares when the ladder is in front of the i-th square because the uncomfortable position of the ladder may make the characters untidy. Besides, the programmers can move the ladder. In one hour, they can move the ladder either a meter to the right or a meter to the left.Drawing characters and moving the ladder is very tiring, so the programmers want to finish the job in as little time as possible. Develop for them an optimal poster painting plan!
256 megabytes
import java.util.Scanner; public class CS_A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(), k = sc.nextInt(); String s = sc.next(); if (n / 2 <k) { if (n != k) for (int i = k; i < n; i++) { System.out.println("RIGHT"); } for (int i = s.length() - 1; i >= 0; i--) { System.out.println("PRINT " + s.charAt(i)); if (i > 0) System.out.println("LEFT"); } } else { if (k != 1) for (int i = k; i > 1; i--) { System.out.println("LEFT"); } for (int i = 0; i < s.length(); i++) { System.out.println("PRINT " + s.charAt(i)); if (s.length() - 1 > i) System.out.println("RIGHT"); } } } }
Java
["2 2\nR1", "2 1\nR1", "6 4\nGO?GO!"]
1 second
["PRINT 1\nLEFT\nPRINT R", "PRINT R\nRIGHT\nPRINT 1", "RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G"]
NoteNote that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character.
Java 7
standard input
[ "implementation", "greedy" ]
e3a03f3f01a77a1983121bab4218c39c
The first line contains two integers, n and k (1 ≀ k ≀ n ≀ 100) β€” the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as n characters written without spaces. Each character of the slogan is either a large English letter, or digit, or one of the characters: '.', '!', ',', '?'.
900
In t lines, print the actions the programmers need to make. In the i-th line print: "LEFT" (without the quotes), if the i-th action was "move the ladder to the left"; "RIGHT" (without the quotes), if the i-th action was "move the ladder to the right"; "PRINT x" (without the quotes), if the i-th action was to "go up the ladder, paint character x, go down the ladder". The painting time (variable t) must be minimum possible. If there are multiple optimal painting plans, you can print any of them.
standard output
PASSED
1f2366af9b3e6b4bbde0bfc176ca7a42
train_002.jsonl
1397837400
The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.The slogan of the company consists of n characters, so the decorators hung a large banner, n meters wide and 1 meter high, divided into n equal squares. The first character of the slogan must be in the first square (the leftmost) of the poster, the second character must be in the second square, and so on.Of course, the R1 programmers want to write the slogan on the poster themselves. To do this, they have a large (and a very heavy) ladder which was put exactly opposite the k-th square of the poster. To draw the i-th character of the slogan on the poster, you need to climb the ladder, standing in front of the i-th square of the poster. This action (along with climbing up and down the ladder) takes one hour for a painter. The painter is not allowed to draw characters in the adjacent squares when the ladder is in front of the i-th square because the uncomfortable position of the ladder may make the characters untidy. Besides, the programmers can move the ladder. In one hour, they can move the ladder either a meter to the right or a meter to the left.Drawing characters and moving the ladder is very tiring, so the programmers want to finish the job in as little time as possible. Develop for them an optimal poster painting plan!
256 megabytes
import java.io.*; import java.util.*; import java.math.*; public class Exercise1 implements Runnable { static BufferedReader in; static PrintWriter out; static StringTokenizer st; private void solve() throws IOException { int length = nextInt(); int currentPos = nextInt(); String slogan = nextToken(); if (currentPos > length / 2) { for (int i = currentPos; i < length; i++) { out.println("RIGHT"); } out.println("PRINT " + slogan.charAt(length - 1)); for (int i = length - 2; i >= 0; i--) { out.println("LEFT"); out.println("PRINT " + slogan.charAt(i)); } } else { for (int i = currentPos; i > 1; i--) { out.println("LEFT"); } out.println("PRINT " + slogan.charAt(0)); for (int i = 1; i < length; i++) { out.println("RIGHT"); out.println("PRINT " + slogan.charAt(i)); } } } public static void main(String[] args) { new Exercise1().run(); } @Override public void run() { try { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); out.close(); } catch (IOException e) { e.printStackTrace(System.err); System.exit(1); } } private String nextToken() throws IOException { while (st == null || !st.hasMoreTokens()) { String line = in.readLine(); if (line == null) { return null; } st = new StringTokenizer(line); } return st.nextToken(); } private int nextInt() throws IOException { return Integer.parseInt(nextToken()); } private long nextLong() throws IOException { return Long.parseLong(nextToken()); } private double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } }
Java
["2 2\nR1", "2 1\nR1", "6 4\nGO?GO!"]
1 second
["PRINT 1\nLEFT\nPRINT R", "PRINT R\nRIGHT\nPRINT 1", "RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G"]
NoteNote that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character.
Java 7
standard input
[ "implementation", "greedy" ]
e3a03f3f01a77a1983121bab4218c39c
The first line contains two integers, n and k (1 ≀ k ≀ n ≀ 100) β€” the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as n characters written without spaces. Each character of the slogan is either a large English letter, or digit, or one of the characters: '.', '!', ',', '?'.
900
In t lines, print the actions the programmers need to make. In the i-th line print: "LEFT" (without the quotes), if the i-th action was "move the ladder to the left"; "RIGHT" (without the quotes), if the i-th action was "move the ladder to the right"; "PRINT x" (without the quotes), if the i-th action was to "go up the ladder, paint character x, go down the ladder". The painting time (variable t) must be minimum possible. If there are multiple optimal painting plans, you can print any of them.
standard output
PASSED
8072b76b795fdd58717cd1d889ba784a
train_002.jsonl
1397837400
The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.The slogan of the company consists of n characters, so the decorators hung a large banner, n meters wide and 1 meter high, divided into n equal squares. The first character of the slogan must be in the first square (the leftmost) of the poster, the second character must be in the second square, and so on.Of course, the R1 programmers want to write the slogan on the poster themselves. To do this, they have a large (and a very heavy) ladder which was put exactly opposite the k-th square of the poster. To draw the i-th character of the slogan on the poster, you need to climb the ladder, standing in front of the i-th square of the poster. This action (along with climbing up and down the ladder) takes one hour for a painter. The painter is not allowed to draw characters in the adjacent squares when the ladder is in front of the i-th square because the uncomfortable position of the ladder may make the characters untidy. Besides, the programmers can move the ladder. In one hour, they can move the ladder either a meter to the right or a meter to the left.Drawing characters and moving the ladder is very tiring, so the programmers want to finish the job in as little time as possible. Develop for them an optimal poster painting plan!
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.PriorityQueue; import java.util.StringTokenizer; public class Main { private static BufferedWriter out; public static void main(String[] args) throws IOException { // The input and output streams boolean file = false; BufferedReader in; if (file) in = new BufferedReader(new FileReader("input.txt"), 32768); else in = new BufferedReader(new InputStreamReader(System.in), 32768); out = new BufferedWriter(new OutputStreamWriter(System.out)); StringTokenizer tok; // take input tok = new StringTokenizer(in.readLine()); int n = Integer.parseInt(tok.nextToken()); int k = Integer.parseInt(tok.nextToken()); String str = in.readLine(); // if we should go to the left if (k -1 < n - k) { // tell him to go left for (int i = 0; i < k-1; i++) System.out.println("LEFT"); // paint each character for (int i = 0; i < n; i++) { System.out.println("PRINT " +str.charAt(i)); if (i != n-1) System.out.println("RIGHT"); } } else { // tell him to go right for (int i = 0; i < n-k; i++) System.out.println("RIGHT"); for (int i = n-1; i >= 0; i--) { System.out.println("PRINT " + str.charAt(i)); if (i != 0) System.out.println("LEFT"); } } out.flush(); } }
Java
["2 2\nR1", "2 1\nR1", "6 4\nGO?GO!"]
1 second
["PRINT 1\nLEFT\nPRINT R", "PRINT R\nRIGHT\nPRINT 1", "RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G"]
NoteNote that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character.
Java 7
standard input
[ "implementation", "greedy" ]
e3a03f3f01a77a1983121bab4218c39c
The first line contains two integers, n and k (1 ≀ k ≀ n ≀ 100) β€” the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as n characters written without spaces. Each character of the slogan is either a large English letter, or digit, or one of the characters: '.', '!', ',', '?'.
900
In t lines, print the actions the programmers need to make. In the i-th line print: "LEFT" (without the quotes), if the i-th action was "move the ladder to the left"; "RIGHT" (without the quotes), if the i-th action was "move the ladder to the right"; "PRINT x" (without the quotes), if the i-th action was to "go up the ladder, paint character x, go down the ladder". The painting time (variable t) must be minimum possible. If there are multiple optimal painting plans, you can print any of them.
standard output
PASSED
17a458f2cfab5f34f5b58c2571392641
train_002.jsonl
1397837400
The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.The slogan of the company consists of n characters, so the decorators hung a large banner, n meters wide and 1 meter high, divided into n equal squares. The first character of the slogan must be in the first square (the leftmost) of the poster, the second character must be in the second square, and so on.Of course, the R1 programmers want to write the slogan on the poster themselves. To do this, they have a large (and a very heavy) ladder which was put exactly opposite the k-th square of the poster. To draw the i-th character of the slogan on the poster, you need to climb the ladder, standing in front of the i-th square of the poster. This action (along with climbing up and down the ladder) takes one hour for a painter. The painter is not allowed to draw characters in the adjacent squares when the ladder is in front of the i-th square because the uncomfortable position of the ladder may make the characters untidy. Besides, the programmers can move the ladder. In one hour, they can move the ladder either a meter to the right or a meter to the left.Drawing characters and moving the ladder is very tiring, so the programmers want to finish the job in as little time as possible. Develop for them an optimal poster painting plan!
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Slogan { public static void main(String ...args) throws IOException { BufferedReader in = new BufferedReader( new InputStreamReader(System.in)); String input = in.readLine(); String[] inputArray= input.split(" "); int n = Integer.parseInt(inputArray[0]); int k = Integer.parseInt(inputArray[1]); String slogan = in.readLine(); if( k <= n/2 ) { int counter = k; while(counter >=1){ if(counter != 1) System.out.println("LEFT"); counter--; } while(counter < n ){ System.out.println("PRINT "+slogan.charAt(counter)); if(counter != n-1) System.out.println("RIGHT"); counter++; } }else{ int counter = k; while(counter < n) { if(counter != n) System.out.println("RIGHT"); counter++; } while(counter >= 1) { System.out.println("PRINT "+slogan.charAt(counter-1)); if(counter !=1) System.out.println("LEFT"); counter--; } } } }
Java
["2 2\nR1", "2 1\nR1", "6 4\nGO?GO!"]
1 second
["PRINT 1\nLEFT\nPRINT R", "PRINT R\nRIGHT\nPRINT 1", "RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G"]
NoteNote that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character.
Java 7
standard input
[ "implementation", "greedy" ]
e3a03f3f01a77a1983121bab4218c39c
The first line contains two integers, n and k (1 ≀ k ≀ n ≀ 100) β€” the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as n characters written without spaces. Each character of the slogan is either a large English letter, or digit, or one of the characters: '.', '!', ',', '?'.
900
In t lines, print the actions the programmers need to make. In the i-th line print: "LEFT" (without the quotes), if the i-th action was "move the ladder to the left"; "RIGHT" (without the quotes), if the i-th action was "move the ladder to the right"; "PRINT x" (without the quotes), if the i-th action was to "go up the ladder, paint character x, go down the ladder". The painting time (variable t) must be minimum possible. If there are multiple optimal painting plans, you can print any of them.
standard output
PASSED
f4fc91c33304379624ea957c2ad1aee7
train_002.jsonl
1397837400
The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.The slogan of the company consists of n characters, so the decorators hung a large banner, n meters wide and 1 meter high, divided into n equal squares. The first character of the slogan must be in the first square (the leftmost) of the poster, the second character must be in the second square, and so on.Of course, the R1 programmers want to write the slogan on the poster themselves. To do this, they have a large (and a very heavy) ladder which was put exactly opposite the k-th square of the poster. To draw the i-th character of the slogan on the poster, you need to climb the ladder, standing in front of the i-th square of the poster. This action (along with climbing up and down the ladder) takes one hour for a painter. The painter is not allowed to draw characters in the adjacent squares when the ladder is in front of the i-th square because the uncomfortable position of the ladder may make the characters untidy. Besides, the programmers can move the ladder. In one hour, they can move the ladder either a meter to the right or a meter to the left.Drawing characters and moving the ladder is very tiring, so the programmers want to finish the job in as little time as possible. Develop for them an optimal poster painting plan!
256 megabytes
import java.util.Scanner; public class A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); String slogan = sc.next(); char[] slogans = slogan.toCharArray(); if(k>n*1.0/2){ for(int i = 0 ; i < n-k;i++){ System.out.println("RIGHT"); } for(int i = n-1;i>0;i--){ System.out.println("PRINT"+" "+slogans[i]); System.out.println("LEFT"); } System.out.println("PRINT"+" "+slogans[0]); }else{ for(int i = 1 ; i < k;i++){ System.out.println("LEFT"); } for(int i = 0;i<n-1;i++){ System.out.println("PRINT"+" "+slogans[i]); System.out.println("RIGHT"); } System.out.println("PRINT"+" "+slogans[n-1]); } } }
Java
["2 2\nR1", "2 1\nR1", "6 4\nGO?GO!"]
1 second
["PRINT 1\nLEFT\nPRINT R", "PRINT R\nRIGHT\nPRINT 1", "RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G"]
NoteNote that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character.
Java 7
standard input
[ "implementation", "greedy" ]
e3a03f3f01a77a1983121bab4218c39c
The first line contains two integers, n and k (1 ≀ k ≀ n ≀ 100) β€” the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as n characters written without spaces. Each character of the slogan is either a large English letter, or digit, or one of the characters: '.', '!', ',', '?'.
900
In t lines, print the actions the programmers need to make. In the i-th line print: "LEFT" (without the quotes), if the i-th action was "move the ladder to the left"; "RIGHT" (without the quotes), if the i-th action was "move the ladder to the right"; "PRINT x" (without the quotes), if the i-th action was to "go up the ladder, paint character x, go down the ladder". The painting time (variable t) must be minimum possible. If there are multiple optimal painting plans, you can print any of them.
standard output
PASSED
396b1a4ccb8f97d1b2e9238441a969b0
train_002.jsonl
1397837400
The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.The slogan of the company consists of n characters, so the decorators hung a large banner, n meters wide and 1 meter high, divided into n equal squares. The first character of the slogan must be in the first square (the leftmost) of the poster, the second character must be in the second square, and so on.Of course, the R1 programmers want to write the slogan on the poster themselves. To do this, they have a large (and a very heavy) ladder which was put exactly opposite the k-th square of the poster. To draw the i-th character of the slogan on the poster, you need to climb the ladder, standing in front of the i-th square of the poster. This action (along with climbing up and down the ladder) takes one hour for a painter. The painter is not allowed to draw characters in the adjacent squares when the ladder is in front of the i-th square because the uncomfortable position of the ladder may make the characters untidy. Besides, the programmers can move the ladder. In one hour, they can move the ladder either a meter to the right or a meter to the left.Drawing characters and moving the ladder is very tiring, so the programmers want to finish the job in as little time as possible. Develop for them an optimal poster painting plan!
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Strike2014R1A { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] parts; parts = br.readLine().split(" "); int n = Integer.parseInt(parts[0]); int k = Integer.parseInt(parts[1]); String slogan = br.readLine(); if (k - 1 < n - k) { for (int i = 0; i < k - 1; i++) { System.out.println("LEFT"); } for (int i = 0; i < n; i++) { System.out.println("PRINT " + slogan.charAt(i)); if (i != n - 1) { System.out.println("RIGHT"); } } } else { for (int i = 0; i < n - k; i++) { System.out.println("RIGHT"); } for (int i = n - 1; i >= 0; i--) { System.out.println("PRINT " + slogan.charAt(i)); if (i != 0) { System.out.println("LEFT"); } } } } }
Java
["2 2\nR1", "2 1\nR1", "6 4\nGO?GO!"]
1 second
["PRINT 1\nLEFT\nPRINT R", "PRINT R\nRIGHT\nPRINT 1", "RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G"]
NoteNote that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character.
Java 7
standard input
[ "implementation", "greedy" ]
e3a03f3f01a77a1983121bab4218c39c
The first line contains two integers, n and k (1 ≀ k ≀ n ≀ 100) β€” the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as n characters written without spaces. Each character of the slogan is either a large English letter, or digit, or one of the characters: '.', '!', ',', '?'.
900
In t lines, print the actions the programmers need to make. In the i-th line print: "LEFT" (without the quotes), if the i-th action was "move the ladder to the left"; "RIGHT" (without the quotes), if the i-th action was "move the ladder to the right"; "PRINT x" (without the quotes), if the i-th action was to "go up the ladder, paint character x, go down the ladder". The painting time (variable t) must be minimum possible. If there are multiple optimal painting plans, you can print any of them.
standard output
PASSED
d1213df91df73b6180e338c53f0620d4
train_002.jsonl
1397837400
The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.The slogan of the company consists of n characters, so the decorators hung a large banner, n meters wide and 1 meter high, divided into n equal squares. The first character of the slogan must be in the first square (the leftmost) of the poster, the second character must be in the second square, and so on.Of course, the R1 programmers want to write the slogan on the poster themselves. To do this, they have a large (and a very heavy) ladder which was put exactly opposite the k-th square of the poster. To draw the i-th character of the slogan on the poster, you need to climb the ladder, standing in front of the i-th square of the poster. This action (along with climbing up and down the ladder) takes one hour for a painter. The painter is not allowed to draw characters in the adjacent squares when the ladder is in front of the i-th square because the uncomfortable position of the ladder may make the characters untidy. Besides, the programmers can move the ladder. In one hour, they can move the ladder either a meter to the right or a meter to the left.Drawing characters and moving the ladder is very tiring, so the programmers want to finish the job in as little time as possible. Develop for them an optimal poster painting plan!
256 megabytes
import java.util.Scanner; public class A { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int k = scan.nextInt(); scan.nextLine(); String losung = scan.nextLine(); if(n - k < k){ for (int i = k - 1; i < n - 1; i++){ System.out.println("RIGHT"); } for(int i = n - 1; i >= 0; i--){ System.out.println("PRINT " + losung.charAt(i)); if (i != 0){ System.out.println("LEFT"); } } } else { for (int i = k - 1; i > 0; i--){ System.out.println("LEFT"); } for(int i = 0; i < n; i++){ System.out.println("PRINT " + losung.charAt(i)); if (i != n - 1){ System.out.println("RIGHT"); } } } } }
Java
["2 2\nR1", "2 1\nR1", "6 4\nGO?GO!"]
1 second
["PRINT 1\nLEFT\nPRINT R", "PRINT R\nRIGHT\nPRINT 1", "RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G"]
NoteNote that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character.
Java 7
standard input
[ "implementation", "greedy" ]
e3a03f3f01a77a1983121bab4218c39c
The first line contains two integers, n and k (1 ≀ k ≀ n ≀ 100) β€” the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as n characters written without spaces. Each character of the slogan is either a large English letter, or digit, or one of the characters: '.', '!', ',', '?'.
900
In t lines, print the actions the programmers need to make. In the i-th line print: "LEFT" (without the quotes), if the i-th action was "move the ladder to the left"; "RIGHT" (without the quotes), if the i-th action was "move the ladder to the right"; "PRINT x" (without the quotes), if the i-th action was to "go up the ladder, paint character x, go down the ladder". The painting time (variable t) must be minimum possible. If there are multiple optimal painting plans, you can print any of them.
standard output
PASSED
c26a21d60739f72736963b743fb8c256
train_002.jsonl
1397837400
The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building.The slogan of the company consists of n characters, so the decorators hung a large banner, n meters wide and 1 meter high, divided into n equal squares. The first character of the slogan must be in the first square (the leftmost) of the poster, the second character must be in the second square, and so on.Of course, the R1 programmers want to write the slogan on the poster themselves. To do this, they have a large (and a very heavy) ladder which was put exactly opposite the k-th square of the poster. To draw the i-th character of the slogan on the poster, you need to climb the ladder, standing in front of the i-th square of the poster. This action (along with climbing up and down the ladder) takes one hour for a painter. The painter is not allowed to draw characters in the adjacent squares when the ladder is in front of the i-th square because the uncomfortable position of the ladder may make the characters untidy. Besides, the programmers can move the ladder. In one hour, they can move the ladder either a meter to the right or a meter to the left.Drawing characters and moving the ladder is very tiring, so the programmers want to finish the job in as little time as possible. Develop for them an optimal poster painting plan!
256 megabytes
//package CoderStrike2014; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * * @author tino chagua */ public class A { /** * @param args the command line arguments */ public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] cad = br.readLine().split(" "); int n = Integer.valueOf(cad[0]); int k = Integer.valueOf(cad[1]); String str = br.readLine(); if (n - k < k - 1) { for (int i = k; i < n; i++) { System.out.println("RIGHT"); } for (int i = n - 1; i > 0; i--) { System.out.println("PRINT " + str.charAt(i) + "\n" + "LEFT"); } System.out.println("PRINT " + str.charAt(0)); } else { for (int i = k; i > 1; i--) { System.out.println("LEFT"); } for (int i = 0; i < n-1; i++) { System.out.println("PRINT " + str.charAt(i) + "\n" + "RIGHT"); } System.out.println("PRINT " + str.charAt(n - 1)); } } } /* 7 4 GO?eGO! */
Java
["2 2\nR1", "2 1\nR1", "6 4\nGO?GO!"]
1 second
["PRINT 1\nLEFT\nPRINT R", "PRINT R\nRIGHT\nPRINT 1", "RIGHT\nRIGHT\nPRINT !\nLEFT\nPRINT O\nLEFT\nPRINT G\nLEFT\nPRINT ?\nLEFT\nPRINT O\nLEFT\nPRINT G"]
NoteNote that the ladder cannot be shifted by less than one meter. The ladder can only stand in front of some square of the poster. For example, you cannot shift a ladder by half a meter and position it between two squares. Then go up and paint the first character and the second character.
Java 7
standard input
[ "implementation", "greedy" ]
e3a03f3f01a77a1983121bab4218c39c
The first line contains two integers, n and k (1 ≀ k ≀ n ≀ 100) β€” the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as n characters written without spaces. Each character of the slogan is either a large English letter, or digit, or one of the characters: '.', '!', ',', '?'.
900
In t lines, print the actions the programmers need to make. In the i-th line print: "LEFT" (without the quotes), if the i-th action was "move the ladder to the left"; "RIGHT" (without the quotes), if the i-th action was "move the ladder to the right"; "PRINT x" (without the quotes), if the i-th action was to "go up the ladder, paint character x, go down the ladder". The painting time (variable t) must be minimum possible. If there are multiple optimal painting plans, you can print any of them.
standard output
PASSED
33269a55e5272a20ecc49c29390703aa
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class A461 { public static void main(String args[])throws Exception { Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int n = sc.nextInt(); long sum = 0; int [] a = new int[n]; for( int i = 0 ; i < n ; i++ ) { a[i] = sc.nextInt(); } Arrays.sort(a); for( int i = 0; i < n-1 ; i++ ) { sum += (long)(i+2)*a[i]; } sum += (long)a[n-1]*n; pw.println(sum); pw.close(); } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
e2c30225b6206ee5b4fbef61f8ec695a
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class CF461A { public static void main(String[] args){ Scanner input = new Scanner(System.in); int n; long sum=0; n=input.nextInt(); int[] a = new int[n]; for (int i=0;i<n;i++){ a[i]=input.nextInt(); sum=sum+a[i]; } Arrays.sort(a); long answer=sum; for (int i=0;i<n-1;i++){ answer=answer+a[i]; sum=sum-a[i]; answer=answer+sum; } System.out.println(answer); } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
5bea03b0fbc2e093e439ce54eded1b2d
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
//Ссли Π² этой Π·Π°Π΄Π°Ρ‡Π΅ Π½ΡƒΠΆΠ½ΠΎ Π²Ρ‹Π²ΠΎΠ΄ΠΈΡ‚ΡŒ Ρ„ΠΎΡ€ΠΌΡƒΠ»Ρƒ, ΠΈ ΠΎΠ½ΠΎ Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚ -- я Π½Π΅ знаю, ΠΊΠ°ΠΊ ΠΎΠ½ΠΎ Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚ :) import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class Codeforces { private static final int INF = (int) 1e9; BufferedReader in; StringTokenizer st; public static void main(String[] args) throws Exception { new Codeforces().run(); } void run() throws Exception { in = new BufferedReader(new InputStreamReader(System.in)); int n = nextInt(); int[] a = new int[n]; long sum = 0; for (int i = 0; i < n; i++) { int x = nextInt(); sum += x; a[i] = x; } Arrays.sort(a); long ans = 0; for (int i = 0; i < n; i++) { ans += sum; if (i != n - 1) { ans += a[i]; sum -= a[i]; } } System.out.println(ans); } String next() throws IOException { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(in.readLine()); } return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
4d762fb1a167ef81bc968b35e8080a17
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.util.Arrays; /** * Created by bharani on 30/4/15. */ public class A461 { public static void main(String[] args) throws IOException{ BufferedReader ip = new BufferedReader(new InputStreamReader(System.in)); String s = ip.readLine(); int n = Integer.parseInt(s); int[] a = new int[n]; int i = 0; BigInteger sum = BigInteger.ZERO, flag=BigInteger.ZERO; s = ip.readLine(); String[] sp = s.split(" "); for(;i<n;i++) { a[i] = Integer.parseInt(sp[i]); sum = sum.add(BigInteger.valueOf(a[i])); } flag = sum; Arrays.sort(a); if(n>1) { sum = sum.multiply(BigInteger.valueOf(2)); for (i = 0; i < n - 2; i++) { flag = flag.subtract(BigInteger.valueOf(a[i])); sum = sum.add(flag); } } System.out.print(sum); } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
83f522d4850bab6f4ce7dcc5c297e9fc
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class ApplemanAndToastman { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] inputs = new int[n]; long sum = 0L; for(int i=0; i<n; i++) { inputs[i] = in.nextInt(); sum += inputs[i]; } Arrays.sort(inputs); long result = sum; for(int j=0; j<n-1; j++) { result += inputs[j] + (sum - inputs[j]); sum -= inputs[j]; } System.out.println(result); } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
0c4dc05fb673d9033e9905c69e503121
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.util.Scanner; public class MyClass { public static void quickSort(int[] arr, int lo, int hi) { if(lo<hi) { int p = partition(arr,lo,hi); int right; for(right = p + 1; right<hi;right++) { if(arr[right] != arr[p]) break; } quickSort(arr,lo,p-1); quickSort(arr,right,hi); } } public static int partition(int[] arr, int lo, int hi) { int pivot = arr[lo + (hi - lo)/2]; int cur = pivot; arr[lo + (hi - lo)/2] = arr[hi]; arr[hi] = cur; int index = lo; for(int i = lo; i <hi; i++) { if(arr[i] < pivot) { cur = arr[index]; arr[index] = arr[i]; arr[i] = cur; index++; } } cur = arr[index]; arr[index] = arr[hi]; arr[hi] = cur; return index; } public static void main(String[] args) { Scanner scan = new Scanner(System.in); int num = scan.nextInt(); int[] group = new int[num]; for(int i = 0; i <num; i++) { group[i] = scan.nextInt(); } quickSort(group, 0, num-1); long total= 0; for(int i = 0; i<num;i++) { total = total + ((long) (i+2)*(group[i])); } total = total - group[num-1]; System.out.println(total); } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
31afab888fc10d2407c48a8fcdc20087
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.util.Arrays; import java.util.Scanner; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author zpan004 */ public class Main{ Scanner sc; long[] arr; void start(){ sc = new Scanner(System.in); arr = new long[sc.nextInt()]; for (int i = 0; i < arr.length; i++){ arr[i] = sc.nextInt(); } Arrays.sort(arr); long sum = 0; for (int i = 0; i < arr.length; i++){ sum += arr[i] * (i+2); } sum -= arr[arr.length-1]; System.out.println(sum); } public static void main(String[] args){ new Main().start(); } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
a85db2b11e9f553b69b8dd1c087a1acc
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.math.BigInteger; import java.util.Arrays; import java.util.Scanner; public class A_461_Appleman_and_Toastman { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=input.nextInt(); int[] nums=new int[n]; for(int i=0;i<n;i++){ nums[i]=input.nextInt(); } Arrays.sort(nums); long sum=0; for(int i=0;i<n;i++){ sum+=(long)nums[i]*(long)(i+2); } sum-=nums[n-1]; System.out.println(sum); } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
9847f5983ceea55b93c8f06af702e37e
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.util.*; import java.io.*; public class A { public static void main(String[] args) throws IOException { BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); String line; StringTokenizer st; StringBuilder sb = new StringBuilder(); int n; int[] sequence; long score; int numElements; int start; int end; int remainderStart; int remainderEnd; long tossed; long rangeSum; while ((line = input.readLine()) != null) { n = Integer.parseInt(line); st = new StringTokenizer(input.readLine()); sequence = new int[n]; score = 0; tossed = 0; for (int i = 0; i < n; i ++) { sequence[i] = Integer.parseInt(st.nextToken()); } numElements = n; start = 0; end = n; rangeSum = sumGroup(start, end, sequence); Arrays.sort(sequence); while (numElements > 0) { score += (rangeSum - tossed); remainderStart = start; remainderEnd = ++start; if (numElements > 1) { score += sumGroup(remainderStart, remainderEnd, sequence); tossed += sumGroup(remainderStart, remainderEnd, sequence); } numElements --; } sb.append(score + "\n"); } System.out.print(sb.toString()); } public static long sumGroup(int start, int end, int[] sequence) { long sum = 0; for (int i = start; i < end; i++) { sum += sequence[i]; } return sum; } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
f50409e41b58b26b233972aa8949374d
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.PriorityQueue; import java.util.StringTokenizer; public class Solution{ /////////////////////////////////////////////////////////////////////////// static class FastScanner{ BufferedReader s; StringTokenizer st; public FastScanner(){ st = new StringTokenizer(""); s = new BufferedReader(new InputStreamReader(System.in)); } public FastScanner(File f) throws FileNotFoundException{ st = new StringTokenizer(""); s = new BufferedReader (new FileReader(f)); } public int nextInt() throws IOException{ if(st.hasMoreTokens()) return Integer.parseInt(st.nextToken()); else{ st = new StringTokenizer(s.readLine()); return nextInt(); } } public double nextDouble() throws IOException{ if(st.hasMoreTokens()) return Double.parseDouble(st.nextToken()); else{ st = new StringTokenizer(s.readLine()); return nextDouble(); } } public long nextLong() throws IOException{ if(st.hasMoreTokens()) return Long.parseLong(st.nextToken()); else{ st = new StringTokenizer(s.readLine()); return nextLong(); } } public String nextString() throws IOException{ if(st.hasMoreTokens()) return st.nextToken(); else{ st = new StringTokenizer(s.readLine()); return nextString(); } } public String readLine() throws IOException{ return s.readLine(); } public void close() throws IOException{ s.close(); } } //////////////////////////////////////////////////////////////////// // Number Theory long pow(long a,long b,long mod){ long x = 1; long y = a; while(b > 0){ if(b % 2 == 1){ x = (x*y); x %= mod; } y = (y*y); y %= mod; b /= 2; } return x; } public static int divisor(int x){ int limit = x; int numberOfDivisors = 0; for (int i=1; i < limit; ++i) { if (x % i == 0) { limit = x / i; if (limit != i) { numberOfDivisors++; } numberOfDivisors++; } } return numberOfDivisors; } void findSubsets(int array[]){ long numOfSubsets = 1 << array.length; for(int i = 0; i < numOfSubsets; i++){ int pos = array.length - 1; int bitmask = i; // System.out.print("{"); while(bitmask > 0){ if((bitmask & 1) == 1) // arr[array[pos]]++; bitmask >>= 1; pos--; } // ww.println(); } } public static int gcd(int a, int b){ return b == 0 ? a : gcd(b,a%b); } public static int lcm(int a,int b, int c){ return lcm(lcm(a,b),c); } public static int lcm(int a, int b){ return a*b/gcd(a,b); } //////////////////////////////////////////////////////////////////// // private static FastScanner s = new FastScanner(new File("input.txt")); // private static PrintWriter ww = new PrintWriter(new FileWriter("output.txt")); private static FastScanner s = new FastScanner(); private static PrintWriter ww = new PrintWriter(new OutputStreamWriter(System.out)); // private static Scanner s = new Scanner(System.in); @SuppressWarnings("unused") private static int[][] states = { {-1,0} , {1,0} , {0,-1} , {0,1} }; //////////////////////////////////////////////////////////////////// public static void main(String[] args) throws IOException{ new Solution().solve(); } //////////////////////////////////////////////////////////////////// void solve() throws IOException{ int n = s.nextInt(); int[] arr = new int[n]; for(int i=0;i<n;i++) arr[i] = s.nextInt(); Arrays.sort(arr); long ans = 0; long cnt = 0; if(n == 1){ ww.println(arr[0]); ww.close(); System.exit(0); } if(n == 2){ ww.println((2*arr[0])+(2*arr[1])); ww.close(); System.exit(0); } for(int i=0;i<n-2;i++){ if(i == 0) cnt+=2; else cnt+=1; ans += arr[i]*cnt; // cnt+=2; } ans += (cnt+1)*arr[n-2]; ans += (cnt+1)*arr[n-1]; ww.println(ans); s.close(); ww.close(); } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
e532e047d6e51c3b66ab2728ea01cbf5
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.util.*; import java.io.*; public class a461 { public static void main(String ar[])throws IOException { BufferedReader ob=new BufferedReader(new InputStreamReader(System.in)); //Scanner ob=new Scanner(System.in); int n=Integer.parseInt(ob.readLine()); String s[]=ob.readLine().split(" "); int arr[]=new int[n]; long sum=0,result=0; for(int i=0;i<n;i++) { arr[i]=Integer.parseInt(s[i]); sum+=arr[i]; } if(n==1) { System.out.println(sum); System.exit(0); } else { result=2*sum; Arrays.sort(arr); for(int i=0;i<n-2;i++) { sum=sum-arr[i]; result+=sum; } System.out.println(result); } } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
6d8389359702be264bc56fcc5c821dbb
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.util.*; public class a461 { public static void main(String ar[]) { Scanner ob=new Scanner(System.in); int n=ob.nextInt(); int arr[]=new int[n]; long sum=0,result=0; for(int i=0;i<n;i++) { arr[i]=ob.nextInt(); sum+=arr[i]; } if(n==1) { System.out.println(sum); System.exit(0); } else { result=2*sum; Arrays.sort(arr); for(int i=0;i<n-2;i++) { sum=sum-arr[i]; result+=sum; } System.out.println(result); } } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
3d19a2eb3bf308dea5503953b54653c3
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.io.OutputStreamWriter; import java.io.BufferedWriter; import java.util.Comparator; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.io.IOException; import java.util.Arrays; import java.util.InputMismatchException; import java.util.NoSuchElementException; import java.math.BigInteger; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } } class TaskA { public void solve(int testNumber, InputReader in, OutputWriter out) { int count = in.readInt(); int[] array = IOUtils.readIntArray(in, count); ArrayUtils.sort(array, IntComparator.DEFAULT); long answer = 0; for (int i = 0; i < count; i++) { answer += (long)Math.min(i + 2, count) * array[i]; } out.printLine(answer); } } class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public void close() { writer.close(); } public void printLine(long i) { writer.println(i); } } class IOUtils { public static int[] readIntArray(InputReader in, int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) array[i] = in.readInt(); return array; } } class ArrayUtils { public static int[] sort(int[] array, IntComparator comparator) { return sort(array, 0, array.length, comparator); } public static int[] sort(int[] array, int from, int to, IntComparator comparator) { if (from == 0 && to == array.length) new IntArray(array).inPlaceSort(comparator); else new IntArray(array).subList(from, to).inPlaceSort(comparator); return array; } } interface IntComparator { public static final IntComparator DEFAULT = new IntComparator() { public int compare(int first, int second) { if (first < second) return -1; if (first > second) return 1; return 0; } }; public int compare(int first, int second); } abstract class IntCollection { public abstract IntIterator iterator(); public abstract int size(); } interface IntIterator { public int value() throws NoSuchElementException; /* * @throws NoSuchElementException only if iterator already invalid */ public void advance() throws NoSuchElementException; public boolean isValid(); } abstract class IntList extends IntCollection implements Comparable<IntList> { private static final int INSERTION_THRESHOLD = 16; public abstract int get(int index); public abstract void set(int index, int value); public IntIterator iterator() { return new IntIterator() { private int size = size(); private int index = 0; public int value() throws NoSuchElementException { if (!isValid()) throw new NoSuchElementException(); return get(index); } public void advance() throws NoSuchElementException { if (!isValid()) throw new NoSuchElementException(); index++; } public boolean isValid() { return index < size; } }; } public IntList subList(final int from, final int to) { return new SubList(from, to); } private void swap(int first, int second) { if (first == second) return; int temp = get(first); set(first, get(second)); set(second, temp); } public IntSortedList inPlaceSort(IntComparator comparator) { quickSort(0, size() - 1, (Integer.bitCount(Integer.highestOneBit(size()) - 1) * 5) >> 1, comparator); return new IntSortedArray(this, comparator); } private void quickSort(int from, int to, int remaining, IntComparator comparator) { if (to - from < INSERTION_THRESHOLD) { insertionSort(from, to, comparator); return; } if (remaining == 0) { heapSort(from, to, comparator); return; } remaining--; int pivotIndex = (from + to) >> 1; int pivot = get(pivotIndex); swap(pivotIndex, to); int storeIndex = from; int equalIndex = to; for (int i = from; i < equalIndex; i++) { int value = comparator.compare(get(i), pivot); if (value < 0) swap(storeIndex++, i); else if (value == 0) swap(--equalIndex, i--); } quickSort(from, storeIndex - 1, remaining, comparator); for (int i = equalIndex; i <= to; i++) swap(storeIndex++, i); quickSort(storeIndex, to, remaining, comparator); } private void heapSort(int from, int to, IntComparator comparator) { for (int i = (to + from - 1) >> 1; i >= from; i--) siftDown(i, to, comparator, from); for (int i = to; i > from; i--) { swap(from, i); siftDown(from, i - 1, comparator, from); } } private void siftDown(int start, int end, IntComparator comparator, int delta) { int value = get(start); while (true) { int child = ((start - delta) << 1) + 1 + delta; if (child > end) return; int childValue = get(child); if (child + 1 <= end) { int otherValue = get(child + 1); if (comparator.compare(otherValue, childValue) > 0) { child++; childValue = otherValue; } } if (comparator.compare(value, childValue) >= 0) return; swap(start, child); start = child; } } private void insertionSort(int from, int to, IntComparator comparator) { for (int i = from + 1; i <= to; i++) { int value = get(i); for (int j = i - 1; j >= from; j--) { if (comparator.compare(get(j), value) <= 0) break; swap(j, j + 1); } } } public int hashCode() { int hashCode = 1; for (IntIterator i = iterator(); i.isValid(); i.advance()) hashCode = 31 * hashCode + i.value(); return hashCode; } public boolean equals(Object obj) { if (!(obj instanceof IntList)) return false; IntList list = (IntList)obj; if (list.size() != size()) return false; IntIterator i = iterator(); IntIterator j = list.iterator(); while (i.isValid()) { if (i.value() != j.value()) return false; i.advance(); j.advance(); } return true; } public int compareTo(IntList o) { IntIterator i = iterator(); IntIterator j = o.iterator(); while (true) { if (i.isValid()) { if (j.isValid()) { if (i.value() != j.value()) { if (i.value() < j.value()) return -1; else return 1; } } else return 1; } else { if (j.isValid()) return -1; else return 0; } i.advance(); j.advance(); } } private class SubList extends IntList { private final int to; private final int from; private int size; public SubList(int from, int to) { this.to = to; this.from = from; size = to - from; } public int get(int index) { if (index < 0 || index >= size) throw new IndexOutOfBoundsException(); return IntList.this.get(index + from); } public void set(int index, int value) { if (index < 0 || index >= size) throw new IndexOutOfBoundsException(); IntList.this.set(index + from, value); } public int size() { return size; } } } abstract class IntSortedList extends IntList { protected final IntComparator comparator; protected IntSortedList(IntComparator comparator) { this.comparator = comparator; } public void set(int index, int value) { throw new UnsupportedOperationException(); } public IntSortedList inPlaceSort(IntComparator comparator) { if (comparator == this.comparator) return this; throw new UnsupportedOperationException(); } protected void ensureSorted() { int size = size(); if (size == 0) return; int last = get(0); for (int i = 1; i < size; i++) { int current = get(i); if (comparator.compare(last, current) > 0) throw new IllegalArgumentException(); last = current; } } public IntSortedList subList(final int from, final int to) { return new IntSortedList(comparator) { private int size = to - from; public int get(int index) { if (index < 0 || index >= size) throw new IndexOutOfBoundsException(); return IntSortedList.this.get(index + from); } public int size() { return size; } }; } } class IntArray extends IntList { private final int[] array; public IntArray(int[] array) { this.array = array; } public int get(int index) { return array[index]; } public void set(int index, int value) { array[index] = value; } public int size() { return array.length; } } class IntSortedArray extends IntSortedList { private final int[] array; public IntSortedArray(IntCollection collection, IntComparator comparator) { super(comparator); array = new int[collection.size()]; int i = 0; for (IntIterator iterator = collection.iterator(); iterator.isValid(); iterator.advance()) array[i++] = iterator.value(); ensureSorted(); } public int get(int index) { return array[index]; } public int size() { return array.length; } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
b00a6ec1fb7f3f3ad74cdbed21ee7ec7
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.util.*; public class Apple { public static void main(String[] args) { Scanner input = new Scanner(System.in); long num = input.nextLong(); long score = 0; long[] numbers = new long[(int)num]; for (int i = 0; i < num; i++) { numbers[i] = input.nextLong(); } Arrays.sort(numbers); for (int i = 0; i < num - 1; i++) { score += (i+2)*numbers[i]; } score += num * numbers[(int)num-1]; System.out.println(score); } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
790749694c74c78d740b854b4ed51341
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.math.BigInteger; import java.util.Arrays; import java.util.Scanner; import sun.security.util.BigInt; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author Houssem */ public class Codeforces263div1 { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long[] t = new long[n]; for (int i = 0; i < n; i++) { t[i] = sc.nextLong(); } Arrays.sort(t); long s = 0; for (int i = 0; i < n - 1; i++) { s += t[i] * (i + 2); } s += t[n - 1] * n; System.out.println(s); } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
bbd8eb3974bedd64372882eba9c7b350
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.util.Arrays; import java.util.Scanner; /** * Created by Baka on 25.05.2016. */ public class YablovAndTostov { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); Long[] a = new Long[n]; long cs = 0; for (int i = 0; i < a.length; i++) { a[i] = scanner.nextLong(); cs += a[i]; } Arrays.sort(a); long r = 0; r += cs; for (int i = 1; i < a.length; i++) { r += a[i - 1]; cs = cs - a[i-1]; r += cs; } System.out.println(r); } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
83876a20cf9dd5d173b734e54ea35d01
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.io.*; import java.util.*; public class A{ public static boolean DEBUG = true; public static void main(String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); int n = nextInt(br); long[] lst = new long[n]; StringTokenizer st = getst(br); for(int i = 0; i < n; i++){ lst[i] = (long)nextInt(st); } Arrays.sort(lst); long ans = 0; for(int i = 0; i < n; i++){ ans += lst[i] * (i+2); } ans -= lst[n-1]; pw.println(ans); br.close(); pw.close(); } public static void debug(Object o){ if(DEBUG){ System.out.println(o); } } public static StringTokenizer getst(BufferedReader br) throws Exception{ return new StringTokenizer(br.readLine(), " "); } public static int nextInt(BufferedReader br) throws Exception{ return Integer.parseInt(br.readLine()); } public static int nextInt(StringTokenizer st) throws Exception{ return Integer.parseInt(st.nextToken()); } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
56b3f26355a0a822bc067bbc5bfb97f6
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.io.*; import java.math.BigDecimal; import java.math.BigInteger; import java.util.Arrays; import java.lang.*; import java.util.*; import java.math.*; import java.util.Collections; import java.util.Comparator; import java.util.StringTokenizer; import java.lang.String; public class Solution { public static void main(String[] args) { new Solution().myRun(); } FastInputScanner in; PrintWriter out; void solveTask() { int n = in.nextInt(); int [] a = new int [n]; a = in.nextIntArray(n); Arrays.sort(a); if (n == 1) { out.println(a[0]); } else { long answer = 0; for (int i = 0; i + 1 < n; ++i) { answer += (long)(i + 2) * a[i]; } answer += (long)(a[n - 1]) * n; out.println(answer); } } void myRun() { in = new FastInputScanner(System.in); out = new PrintWriter(new OutputStreamWriter(System.out)); solveTask(); out.close(); } void myRunIO(){ try { in = new FastInputScanner(new File("input.txt")); out = new PrintWriter(new FileWriter(new File("output.txt"))); solveTask(); out.close(); } catch(Exception exception){ exception.printStackTrace(); } } class FastInputScanner{ BufferedReader bufferedReader; StringTokenizer stringTokenizer; public FastInputScanner(File file){ try{ bufferedReader = new BufferedReader(new FileReader(file)); } catch(IOException exception){ exception.printStackTrace(); } } public FastInputScanner(InputStream inputStream){ bufferedReader = new BufferedReader(new InputStreamReader(inputStream), 32768); } String next(){ while(stringTokenizer == null || !stringTokenizer.hasMoreTokens()) { try { stringTokenizer = new StringTokenizer(bufferedReader.readLine()); } catch(IOException exception) { exception.printStackTrace(); } } return stringTokenizer.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } double nextDouble(){ return Double.parseDouble(next()); } float nextFloat(){ return Float.parseFloat(next()); } String nextLine(){ try { return bufferedReader.readLine(); } catch(Exception exception) { exception.printStackTrace(); } return ""; } long nextLong() { return Long.parseLong(next()); } BigInteger nextBigInteger() { return new BigInteger(next()); } BigDecimal nextBigDecimal() { return new BigDecimal(next()); } int[] nextIntArray(int n) { int a[] = new int[n]; for(int i = 0; i < n; i++) a[i] = Integer.parseInt(next()); return a; } long[] nextLongArray(int n){ long a[] = new long[n]; for(int i = 0; i < n; i++) a[i] = Long.parseLong(next()); return a; } } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
de2a4694ec0c90a6e11891705ee57649
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class A { public static void main(String[] args) { Scanner inScanner = new Scanner(System.in); int n = inScanner.nextInt(); long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = inScanner.nextInt(); } Arrays.sort(a); long score = 0; for (int i = 0; i < n; i++) { score += (i + 2) * a[i]; } score -= a[n - 1]; System.out.println(score); } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
850f0ab177859ccbecf785e3c880bf34
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.util.*; import java.io.*; import java.lang.*; import java.math.*; public class A { public static void main(String[] args) throws Exception { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); // Scanner scan = new Scanner(System.in); // PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); int n = Integer.parseInt(bf.readLine()); StringTokenizer st = new StringTokenizer(bf.readLine()); Integer[] a = new Integer[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken()); Arrays.sort(a); long answer = 0; for(int i=0; i<n-1; i++) answer += 1L*a[i]*(i+2); answer += 1L*a[n-1]*n; System.out.println(answer); // int n = Integer.parseInt(st.nextToken()); // int n = scan.nextInt(); // out.close(); System.exit(0); } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
f6623200c60cb6235dd7afb400b4aab1
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class cola { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] arr = new int[n]; long score = 0; for (int i = 0; i < n; i++) { arr[i] = in.nextInt(); score += arr[i]; } long sum = score; Arrays.sort(arr); score = sum * 2 - arr[n - 1]; sum -= arr[0]; int debut = 1; while (debut < n) { score += sum; sum -= arr[debut]; debut++; } System.out.println(score); } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
4627e0efbdcd8187e0258dc1fe8655dc
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class A263{ public static void main(String args[]){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long a[] = new long[300111]; long sum = 0, ans = 0; for(int i = 0; i < n; i++) { a[i] = sc.nextInt(); sum += a[i]; } Arrays.sort(a, 0, n); if(n == 1){ System.out.print(sum); return; } ans = sum; for(int i = 0; i < n - 1; i++){ ans +=sum; sum -= a[i]; } System.out.print(ans); } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
a65ae705b3a3990b25c40a86731b700e
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class AppleManAndToastMan461A { public static void main(String[] args) { Scanner in = new Scanner(System.in); int num = in.nextInt(); ArrayList<Integer> values = new ArrayList<Integer>(); while(num > 0){ num--; values.add(in.nextInt()); } in.close(); Collections.sort(values); long sum = 0; for(int i = 0; i < values.size(); i++){ sum += values.get(i); } long answer = sum; for(int i = 0; i < values.size() - 1; i++) { answer += sum; sum -= values.get(i); } System.out.println(answer); } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
7776c019870a0bb41c3cb61b51e15b14
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class A264 { public static void main(String[] args){ Scanner s=new Scanner(System.in); int n = Integer.parseInt(s.nextLine()); int f[] = new int[n]; String[] temp = s.nextLine().split(" "); for (int i = 0; i < n; i++){ f[i] = Integer.parseInt(temp[i]); } Arrays.sort(f); long ans = 0; for (int i = n-1; i >= 0; i--){ ans += (long)(i+2) * f[i]; } ans -= f[n-1]; System.out.println(ans); } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
661882ff4a3b88a0f8fc8f095d82d2a8
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class NextRound { static class Reader { BufferedReader r; StringTokenizer str; Reader() { r=new BufferedReader(new InputStreamReader(System.in)); } Reader(String fileName) throws FileNotFoundException { r=new BufferedReader(new FileReader(fileName)); } public String getNextToken() throws IOException { if(str==null||!str.hasMoreTokens()) { str=new StringTokenizer(r.readLine()); } return str.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(getNextToken()); } public long nextLong() throws IOException { return Long.parseLong(getNextToken()); } public double nextDouble() throws IOException { return Double.parseDouble(getNextToken()); } public String nextString() throws IOException { return getNextToken(); } public int[] intArray(int n) throws IOException { int a[]=new int[n]; for(int i=0;i<n;i++) a[i]=nextInt(); return a; } public long[] longArray(int n) throws IOException { long a[]=new long[n]; for(int i=0;i<n;i++) a[i]=nextLong(); return a; } public String[] stringArray(int n) throws IOException { String a[]=new String[n]; for(int i=0;i<n;i++) a[i]=nextString(); return a; } public long gcd(long a, long b) { if(b == 0){ return a; } return gcd(b, a%b); } } public static void main(String args[]) throws IOException{ Reader r=new Reader(); PrintWriter pr=new PrintWriter(System.out,false); int num=r.nextInt(); long arr[]=new long[num]; long sum=0; for(int a=0;a<num;a++) { arr[a]=r.nextLong(); } Arrays.sort(arr); for(int i=0;i<num;i++) { sum=sum+(i+2)*arr[i]; } pr.print(sum-arr[num-1]); pr.flush(); pr.close(); } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
37d912e0ca2b5b748e4dfb9d99add6a5
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.util.List; import java.io.InputStreamReader; import java.io.IOException; import java.math.BigDecimal; import java.util.Arrays; import java.util.ArrayList; import java.awt.Point; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.util.StringTokenizer; import java.math.BigInteger; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author Turaev Timur */ 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(); long[] a = in.nextLongArray(n); Arrays.sort(a); long ans = 0; for (int i = 0; i < n - 1; i++) { ans += a[i] * (i + 2); } ans += a[n-1] * n; out.print(ans); } } class InputReader { BufferedReader in; StringTokenizer stringTokenizer; public InputReader(InputStream inputStream) { in = new BufferedReader(new InputStreamReader(inputStream)); } public String next() { while (stringTokenizer == null || !stringTokenizer.hasMoreElements()) { try { stringTokenizer = new StringTokenizer(in.readLine()); } catch (IOException e) { e.printStackTrace(); } } return stringTokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public long[] nextLongArray(int size) { long[] array = new long[size]; for (int index = 0; index < size; ++index) { array[index] = nextLong(); } return array; } } class OutputWriter extends PrintWriter { final int DEFAULT_PRECISION = 12; int precision; String format, formatWithSpace; { precision = DEFAULT_PRECISION; format = createFormat(precision); formatWithSpace = format + " "; } public OutputWriter(OutputStream out) { super(out); } private String createFormat(int precision) { return "%." + precision + "f"; } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
b37adb470604c106aa3b49257a32c80a
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.io.InputStreamReader; import java.io.BufferedReader; import java.util.Arrays; import java.util.Comparator; import java.util.StringTokenizer; public class CF461A { public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); for(String ln;(ln=in.readLine())!=null;){ int N = Integer.parseInt(ln); StringTokenizer st = new StringTokenizer(in.readLine()); Integer[] m = new Integer[N]; long sum = 0; for(int i=0;i<N;++i){ m[i]=Integer.parseInt(st.nextToken()); sum+=m[i]; } Arrays.sort(m, new Comparator<Integer>() { public int compare(Integer o1, Integer o2) { return o1.intValue()-o2.intValue(); } }); long total = sum; if(N>=2){ sum*=2; long rest = 0; for(int i=0;i<N-2;++i){ rest+=m[i]; sum+= (total - rest); } } System.out.println(sum); } } } /** * 10 8 10 2 5 6 2 4 7 2 1 376 * */
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
0bd95c9371b0fdc4ef7a22d79cfda291
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
//package javaapplication1; import java.util.*; import java.io.*; public class JavaApplication1 implements Runnable { BufferedReader in; PrintWriter out; StringTokenizer tok = new StringTokenizer(""); final boolean OJ = System.getProperty("ONLINE_JUDGE") != null; void init() throws FileNotFoundException { if (OJ) { 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"); } } @Override public void run() { try { init(); solve(); out.close(); } catch(Exception e) { e.printStackTrace(); System.exit(-1); } } public static void main(String[] args) { new Thread(null, new JavaApplication1(), "", (1L << 20) * 256).start(); } String readString() { while(!tok.hasMoreTokens()) { try { tok = new StringTokenizer(in.readLine()); } catch(Exception e) { e.printStackTrace(); System.exit(-1); } } return tok.nextToken(); } int readInt() { return Integer.parseInt(readString()); } long readLong() { return Long.parseLong(readString()); } //////////////////////////////////////////////////////////////////////////////// void solve() { long ans = 0; int n; n = readInt(); long[] a = new long[n]; for(int i = 0; i < n; i++) { a[i] = readInt(); ans += a[i]; } Arrays.sort(a); ans += a[n - 1] * (n - 1); for(int i = n - 2; i >= 0; i--) { ans += a[i] * (i + 1); } out.println(ans); } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
3df203c927935e5e5c2b34faa8159243
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.PriorityQueue; import java.util.Scanner; import javax.swing.InputMap; public class ApplemanA { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(bf.readLine()); String nums[] = bf.readLine().split(" "); int temp; long sum = 0; long[] input = new long[n]; for (int i = 0; i < input.length; i++) { input[i] = Integer.parseInt(nums[i]); } Arrays.sort(input); // System.out.println(Arrays.toString(input)); long result = 0; for (int i = 0; i < input.length; i++) { if(input.length-1 != i) result += (i+2)*input[i]; else result += (i+1)*input[i]; } System.out.println(result); } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
6fa67970e14feedfdf67c16e509007a9
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class ApplemanandToastman { static long total = 0; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num_of_num = sc.nextInt(); int[] nums = new int[num_of_num]; long tempSum = 0; int minValue = 1000001; for (int i = 0; i < num_of_num; i++) { int tempValue = sc.nextInt(); tempSum += tempValue; nums[i] = tempValue; } sc.close(); Arrays.sort(nums); total += tempSum; int index = 0; while (index + 1 < nums.length) { total += tempSum; minValue = nums[index]; index++; tempSum -= minValue; } System.out.println(total); } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
b47e928a89a1a81410293e56e6f223f0
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; public class ApplemanandToastman { static long total = 0; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num_of_num = sc.nextInt(); List<Integer> nums = new ArrayList<Integer>(num_of_num); long tempSum = 0; int minValue = 1000001; for (int i = 0; i < num_of_num; i++) { int tempValue = sc.nextInt(); tempSum += tempValue; nums.add(tempValue); } sc.close(); Collections.sort(nums); total += tempSum; int index = 0; while (index + 1 < nums.size()) { total += tempSum; // minValue = findMinRemove(nums); // minValue = findMinRemove2(nums); minValue = nums.get(index); index++; tempSum -= minValue; } System.out.println(total); } public static int findMinRemove(List<Integer> list) { int minValue = 1000001; int minIndex = 0; for (int i = 0; i < list.size(); i++) { if (list.get(i) < minValue) { minValue = list.get(i); minIndex = i; } } list.remove(minIndex); return minValue; } public static int findMinRemove2(List<Integer> list) { int minValue = list.get(0); list.remove(0); return minValue; } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
6582bee89a6ed343813f8d33e36e6355
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.io.*; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Task461A { public static void main(String... args) throws NumberFormatException, IOException { Solution.main(System.in, System.out); } static class Scanner { private final BufferedReader br; private String[] cache; private int cacheIndex; Scanner(InputStream is) { br = new BufferedReader(new InputStreamReader(is)); cache = new String[0]; cacheIndex = 0; } int nextInt() throws IOException { if (cacheIndex >= cache.length) { cache = br.readLine().split(" "); cacheIndex = 0; } return Integer.parseInt(cache[cacheIndex++]); } long nextLong() throws IOException { if (cacheIndex >= cache.length) { cache = br.readLine().split(" "); cacheIndex = 0; } return Long.parseLong(cache[cacheIndex++]); } String next() throws IOException { if (cacheIndex >= cache.length) { cache = br.readLine().split(" "); cacheIndex = 0; } return cache[cacheIndex++]; } String nextLine() throws IOException { return br.readLine(); } void close() throws IOException { br.close(); } } static class Solution { public static void main(InputStream is, OutputStream os) throws NumberFormatException, IOException { PrintWriter pw = new PrintWriter(os); Scanner sc = new Scanner(is); int n = sc.nextInt(); List<Integer> in = new ArrayList<Integer>(); for (int i = 0; i < n; i++) { in.add(sc.nextInt()); } Collections.sort(in); long retVal = 0; for (int i = 0; i < in.size(); i++) { long i1 = i + 2; retVal += i1 * in.get(i); } retVal -= in.get(in.size() - 1); pw.println(retVal); pw.flush(); sc.close(); } } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
befe9925272a74e7a082b79b890cd14c
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.util.*; import java.io.*; public class test { 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()); } } static class Task { public void solve(int testNumber, InputReader in, PrintWriter out) { while(testNumber-->0) { int n=in.nextInt(); int arr[] =new int[n]; long ans=0; long cumm[] = new long[n]; for(int i=0;i<n;++i) { arr[i] = in.nextInt(); ans += arr[i]; } if(n==1) { out.println(ans); continue; } Arrays.sort(arr); for(int i=0;i<n;++i) { if(i==0) cumm[i] = arr[i]; else cumm[i] = cumm[i-1]+arr[i]; } for(int i=0;i<n;++i) { ans += arr[i]; if(i!=n-2) ans += cumm[n-1]-cumm[i]; //out.println(" i = "+i+" ans = "+ans); } out.println(ans); } } } 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(); int test = 1; solver.solve(test, in, out); out.close(); } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
acf829f26d6c1ae73f48cae30a0921f1
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; public class R263D1A { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); StringTokenizer st = new StringTokenizer(br.readLine()); long[] a = new long[n]; for(int i=0; i<n; i++){ a[i] = Integer.parseInt(st.nextToken()); } Arrays.sort(a); for(int i=n-1; i>0; i--) a[i-1]+=a[i]; long result=0; for(int i=0; i<n-1; i++) result += a[i]; result+=a[0]; System.out.println(result); } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
132db242a8fe86551ea2f146c8cdc061
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.lang.*; import java.io.*; import java.util.*; public class Toastman { public static void main(String[] args) throws java.lang.Exception { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(in, out); out.close(); } } class TaskA { public void solve(InputReader in, PrintWriter out) { int n = in.nextInt(); long[] sum = new long[n]; int i, j, k; for (i=0; i<n; ++i) sum[i] = in.nextLong(); Arrays.sort(sum); for (i=n-2; i>=0; --i) sum[i] += sum[i+1]; long ans = sum[0]; if (n > 1) { for (i=0; i<n-1; ++i) ans += sum[i]; } out.println(ans); } } class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer==null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
9c205b63252d86bb63e0f542353b5333
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.util.Scanner; import java.util.Arrays; import java.util.ArrayList; import java.util.Comparator; import java.util.Collections; public class Toastman { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int n = cin.nextInt(); long[] sums = new long[n]; //ArrayList<int> sums = for (int i=0; i<n; ++i) sums[i] = cin.nextInt(); //Collections.sort(sums, new OrderAsc()); Arrays.sort(sums); //print(sums); for (int i=n-2; i>=0; --i) sums[i] += sums[i+1]; //print(sums); long ans = sums[0]; if (n > 1) { for (int i=0; i<n-1; ++i) { //System.out.println(ans); ans += sums[i]; } } System.out.println(ans); } static void print(int[] a) { for (int i=0; i<a.length; ++i) System.out.print(a[i]+" "); System.out.println(); } } class OrderAsc implements Comparator{ @Override public int compare(Object arg0, Object arg1) { // TODO Auto-generated method stub if (arg0 instanceof Integer && arg1 instanceof Integer) return (long)arg1 > (long)arg0 ? 1:-1; return 0; } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
8d9d66d0d6a50f2dda777758e71e3138
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.util.Scanner; import java.util.Arrays; import java.util.ArrayList; import java.util.Comparator; import java.util.Collections; public class Toastman { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int n = cin.nextInt(); long[] sums = new long[n]; //ArrayList<int> sums = for (int i=0; i<n; ++i) sums[i] = cin.nextInt(); //Collections.sort(sums, new OrderAsc()); Arrays.sort(sums); //print(sums); for (int i=n-2; i>=0; --i) sums[i] += sums[i+1]; //print(sums); long ans = sums[0]; if (n > 1) { for (int i=0; i<n-1; ++i) { //System.out.println(ans); ans += sums[i]; } } System.out.println(ans); } static void print(int[] a) { for (int i=0; i<a.length; ++i) System.out.print(a[i]+" "); System.out.println(); } } class OrderAsc implements Comparator{ @Override public int compare(Object arg0, Object arg1) { // TODO Auto-generated method stub if (arg0 instanceof Long && arg1 instanceof Long) return (long)arg1 > (long)arg0 ? 1:-1; return 0; } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
2a06e6657babee162ba58f43f9ba02b5
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.io.BufferedWriter; 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.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.InputMismatchException; public class ac1 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub InputStream inputStream = System.in; OutputStream outputStream = System.out; FastReader in = new FastReader(inputStream); OutputWriter out = new OutputWriter(outputStream); int n = in.nextInt(); int a[] = new int[n]; long ans=0; for(int i=0;i<n;i++){ a[i] = in.nextInt(); ans+=a[i]; } Arrays.sort(a); ans = ans - a[n-1]; for(int i=n-1;i>=0;i--){ long tt = (i+1); tt = tt*(a[i]); ans+=tt; } out.println(ans); out.close(); } } class FastReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public FastReader(InputStream stream) { this.stream = stream; } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public 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 String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } public Long readLong() { return Long.parseLong(readString()); } public Double readDouble() { return Double.parseDouble(readString()); } } 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 println(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
63cb829e0384abe9475b5365afe00ac7
train_002.jsonl
1409061600
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.StreamTokenizer; import static java.lang.System.out; import java.util.Arrays; public class Main { static StreamTokenizer in; public static void main(String[] args) throws IOException { in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); int n = nextInt(); long[] arr = new long[n]; for(int i = 0; i < n; i++) arr[i] = nextInt(); Arrays.sort(arr); long sum = 0; for(int i = 0; i < n - 1; i++) sum += arr[i] * (i + 2); sum += arr[n-1] * n; out.println(sum); } static int nextInt() throws IOException { in.nextToken(); return (int)in.nval; } }
Java
["3\n3 1 5", "1\n10"]
2 seconds
["26", "10"]
NoteConsider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
Java 7
standard input
[ "sortings", "greedy" ]
4266948a2e793b4b461156af226e98fd
The first line contains a single integer n (1 ≀ n ≀ 3Β·105). The second line contains n integers a1, a2, ..., an (1 ≀ ai ≀ 106) β€” the initial group that is given to Toastman.
1,200
Print a single integer β€” the largest possible score.
standard output
PASSED
8deb6276ea183c0ea1193dc7754f652c
train_002.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
import java.util.*; import java.lang.*; public class marlin { public static void main(String args[]) { int n=0,k=0; Scanner in= new Scanner(System.in); n=in.nextInt(); k=in.nextInt(); char r1[]=new char[n]; char r2[]=new char[n]; char r3[]=new char[n]; char r4[]=new char[n]; for(int i=0; i<n; i++) { r1[i]='.';r2[i]='.';r3[i]='.';r4[i]='.'; } if(k%2==0) { for(int i=1; i<(k/2)+1; i++) { r2[i]='#';r3[i]='#'; } System.out.println("YES"); for(int i=0; i<n; i++) { System.out.print(r1[i]); } System.out.println(); for(int i=0; i<n; i++) { System.out.print(r2[i]); } System.out.println(); for(int i=0; i<n; i++) { System.out.print(r3[i]); } System.out.println(); for(int i=0; i<n; i++) { System.out.print(r4[i]); } System.out.println(); } else if((k%2!=0)&&(k<=n-2)) { for(int i=0; i<=(k-1)/2; i++) { r2[(n-1)/2 +i]='#'; r2[(n-1)/2 -i]='#'; } System.out.println("YES"); for(int i=0; i<n; i++) { System.out.print(r1[i]); } System.out.println(); for(int i=0; i<n; i++) { System.out.print(r2[i]); } System.out.println(); for(int i=0; i<n; i++) { System.out.print(r3[i]); } System.out.println(); for(int i=0; i<n; i++) { System.out.print(r4[i]); } System.out.println(); } else if((k%2!=0)&&(k>n-2)&&(k>4)) { for(int i=1; i<=(k+1)/2; i++) r2[i]='#'; for(int i=1; i<=(k+1)/2; i++) r3[i]='#'; r2[(k+1)/2 -1]='.'; System.out.println("YES"); for(int i=0; i<n; i++) { System.out.print(r1[i]); } System.out.println(); for(int i=0; i<n; i++) { System.out.print(r2[i]); } System.out.println(); for(int i=0; i<n; i++) { System.out.print(r3[i]); } System.out.println(); for(int i=0; i<n; i++) { System.out.print(r4[i]); } System.out.println(); } else System.out.println("NO"); } }
Java
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
f0f87c3a493925b2ff5436d3efbcc114
train_002.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } static class TaskB { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int k = in.nextInt(); char[][] ans = new char[4][n]; Arrays.fill(ans[0], '.'); Arrays.fill(ans[1], '.'); Arrays.fill(ans[2], '.'); Arrays.fill(ans[3], '.'); if (k % 2 == 0) { for (int i = 1; i < n && k > 0; i++, k -= 2) { ans[1][i] = '#'; ans[2][i] = '#'; } } else if (k == 1 || k == 3) { for (int i = 0; i < k; i++) { ans[1][(n - k) / 2 + i] = '#'; } } else { int len = Math.min(k - 2, n - 2); for (int i = 0; i < len; i++) { ans[1][1 + i] = '#'; } ans[2][1] = '#'; ans[2][len] = '#'; k -= Math.min(k, n); for (int i = 0; i < k; i++) { ans[2][2 + i] = '#'; } } out.println("YES"); out.println(ans[0]); out.println(ans[1]); out.println(ans[2]); out.println(ans[3]); } } static class InputReader { private StringTokenizer tokenizer; private BufferedReader reader; public InputReader(InputStream inputStream) { reader = new BufferedReader(new InputStreamReader(inputStream)); } private void fillTokenizer() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (Exception e) { throw new RuntimeException(e); } } } public String next() { fillTokenizer(); return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
6a1d2e7ff7c8d3875936304298c7059e
train_002.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } static class TaskB { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int k = in.nextInt(); char[][] ans = new char[4][n]; Arrays.fill(ans[0], '.'); Arrays.fill(ans[1], '.'); Arrays.fill(ans[2], '.'); Arrays.fill(ans[3], '.'); if (k % 2 == 0) { for (int i = 1; i <= k / 2; i++) { ans[1][i] = '#'; ans[2][i] = '#'; } } else if (k == 1 || k == 3) { for (int i = 0; i < k; i++) { ans[1][(n - k) / 2 + i] = '#'; } } else { int len = Math.min(k - 2, n - 2); for (int i = 0; i < len; i++) { ans[1][1 + i] = '#'; } ans[2][1] = '#'; ans[2][len] = '#'; k -= Math.min(k, n); for (int i = 0; i < k; i++) { ans[2][2 + i] = '#'; } } out.println("YES"); out.println(ans[0]); out.println(ans[1]); out.println(ans[2]); out.println(ans[3]); } } static class InputReader { private StringTokenizer tokenizer; private BufferedReader reader; public InputReader(InputStream inputStream) { reader = new BufferedReader(new InputStreamReader(inputStream)); } private void fillTokenizer() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (Exception e) { throw new RuntimeException(e); } } } public String next() { fillTokenizer(); return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }
Java
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
4d5bb696dad26439f59c08b0d5314db8
train_002.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
import java.math.BigInteger; import java.util.*; public class Main { public static void main(String args[]) { Scanner sc =new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); System.out.println("YES"); int x[][]=new int[4][a]; if(b%2==0){ for(int n=1;n<a-1;n++){ if(b==0)break; else{ b-=2; x[1][n]=1; x[2][n]=1; } } } else{ x[2][a/2]=1; b--; for(int n=1;n<=2;n++){ if(b==0)break; for(int m=a/2-1;m>=1;m--){ if(b==0)break; b-=2; x[n][m]=1; x[n][a-m-1]=1; } } } for(int n=0;n<4;n++){ for(int m=0;m<a;m++){ if(x[n][m]==0)System.out.print("."); else System.out.print("#"); } System.out.println(); } } }
Java
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
32a265fd82eb055b1a6336e37b277d87
train_002.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
import java.util.*; public class B { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); char[][] grid = new char[4][n]; if(k%2==0){ System.out.println("YES"); for(int i=0;i<n;i++){ for(int j=0;j<4;j++){ if(i==0 || i==n-1 || j==0 || j==3) grid[j][i] = '.'; else{ if(k>0){ grid[j][i] = '#'; k--; } else grid[j][i] = '.'; } } } for(int i=0;i<4;i++){ for(int j=0;j<n;j++){ System.out.print(grid[i][j]); } System.out.println(); } } else{ System.out.println("YES"); int kk = k; int il=0; int jl=0; for(int i=0;i<4;i++){ for(int j=0;j<n;j++){ if(i==0 || i==3 || j==0 || j==(n-1)) grid[i][j] = '.'; else{ if(k>0 && j>=(n-k)/2 && i==1){ grid[i][j] = '#'; k--; if(k==0){ il=i; jl=j; } } else if(k>0 && i==2){ grid[i][j] = '#'; k--; if(k==0){ il=i; jl=j; } } else grid[i][j] = '.'; } } } if(il==2){ grid[il][jl] = '.'; grid[il][n-2] = '#'; } for(int i=0;i<4;i++){ for(int j=0;j<n;j++){ System.out.print(grid[i][j]); } System.out.println(); } } } }
Java
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
fde929b774d7ba91f69c5ac415d5db31
train_002.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Scanner; public class Solution { private static final boolean DEBUG = false; private static void solve(int columnCount, int hotelCount) { boolean[][] grid = new boolean[4][columnCount]; int first = Math.min(hotelCount, columnCount - 2); int second = hotelCount - first; if (first % 2 != 0) grid[1][columnCount / 2] = true; for (int j = 1; j <= first / 2; j++) { grid[1][columnCount / 2 - j] = true; grid[1][columnCount / 2 + j] = true; } if (second % 2 != 0) grid[2][columnCount / 2] = true; for (int j = 1; j <= second / 2; j++) { grid[2][columnCount / 2 - j] = true; grid[2][columnCount / 2 + j] = true; } if (grid != null) { System.out.println("YES"); //System.out.println(hotelCount); for (int i = 0; i < 4; i++) { for (int j = 0; j < columnCount; j++) { System.out.print(grid[i][j] ? '#' : '.'); } System.out.println(); } } else { System.out.println("NO"); } } public static void main(String[] args) throws FileNotFoundException { long beginTime = System.nanoTime(); InputStream is = DEBUG ? new FileInputStream("resources/codeforcesedu43/ProblemB-1.in") : System.in; try (Scanner scanner = new Scanner(new BufferedReader(new InputStreamReader(is)))) { int columnCount = scanner.nextInt(); int hotelCount = scanner.nextInt(); solve(columnCount, hotelCount); } System.err.println( "Done in " + ((System.nanoTime() - beginTime) / 1e9) + " seconds."); } }
Java
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
a3cb9f34427373dd54efacc6b113dd3d
train_002.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
import java.util.Scanner; public class Test{ public static void main(String[] args){ Scanner input = new Scanner(System.in); int shir = input.nextInt(); int hotels = input.nextInt(); if (hotels % 2 == 0 && hotels <= (shir - 2) * 2){ System.out.println("YES"); paintLine(shir); paintEvenLine(shir, hotels / 2); paintEvenLine(shir, hotels / 2); paintLine(shir); } else if (hotels % 2 != 0 && hotels <= (shir - 2)){ // } else if (hotels % 2 != 0 && hotels <= (shir - 2)){ System.out.println("YES"); paintLine(shir); paintSymLine(shir, hotels); paintLine(shir); paintLine(shir); } else if (hotels % 2 != 0 && hotels > (shir - 2) && hotels <= (shir - 2) * 2){ System.out.println("YES"); paintLine(shir); paintEvenLine(shir, shir - 2); int new_hotels = hotels - (shir - 2); paintInvertedLine(shir, new_hotels); //System.out.println(new_hotels); paintLine(shir); } else { System.out.println("NO"); } } static void paintLine(int n){ for (int i = 0; i < n - 1; i++){ System.out.print("."); } System.out.println("."); } static void paintEvenLine(int n, int even){ System.out.print("."); for (int i = 0; i < even; i++){ System.out.print("#"); } for (int i = 0; i < n - even - 2; i++){ System.out.print("."); } System.out.println("."); } static void paintInvertedLine(int n, int hotels){ System.out.print(".#"); for (int i = 0; i < n - (hotels - 1) - 3; i++){ System.out.print("."); } for (int i = 0; i < hotels - 1; i++){ System.out.print("#"); } System.out.println("."); } static void paintSymLine(int n,int hotels){ System.out.print("."); for (int i = 0; i < ((n - hotels) / 2) - 1; i++){ System.out.print("."); } for (int i = 0; i < hotels; i++){ System.out.print("#"); } for (int i = 0; i < ((n - hotels) / 2) - 1; i++){ System.out.print("."); } System.out.println("."); } }
Java
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
d502165ca5d8970cc69503d0a54d7eae
train_002.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
import java.io.*; import java.util.*; public class Contest480B { static final int INF = (int) 1e8; static final int MOD = (int) 1e9 + 7; public static BlockReader input; public static PrintStream output; public static Debug debug; public static void main(String[] args) throws FileNotFoundException { init(); solve(); destroy(); } public static void init() throws FileNotFoundException { if (System.getProperty("ONLINE_JUDGE") == null) { input = new BlockReader(new FileInputStream("E:\\DATABASE\\TESTCASE\\codeforces\\Contest480B.in")); output = System.out; } else { input = new BlockReader(System.in); output = new PrintStream(new BufferedOutputStream(System.out), false); } debug = new Debug(); debug.enter("main"); } public static void solve() { int column = input.nextInteger(); int k = input.nextInteger(); char[][] data = new char[4][column]; for (int i = 0; i < 4; i++) { Arrays.fill(data[i], '.'); } if (k % 2 == 0) { output.println("YES"); int half = k / 2; for (int i = 1; i <= half; i++) { data[1][i] = data[2][i] = '#'; } print(data); return; } if (k <= column - 2) { output.println("YES"); int begin = (column - k) / 2; for (int i = begin, until = k + begin; i < until; i++) { data[1][i] = '#'; } print(data); return; } output.println("YES"); for (int i = 1, until = column - 1; i < until; i++) { data[1][i] = '#'; } k -= column - 2; for (int i = 1; k > 0; k -= 2, i++) { data[2][i] = data[2][column - i - 1] = '#'; } print(data); } public static void print(char[][] data) { int r = data.length; int c = data[0].length; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { output.print(data[i][j]); } output.println(); } } public static void destroy() { output.flush(); debug.exit(); debug.statistic(); } public static class Debug { boolean debug = System.getProperty("ONLINE_JUDGE") == null; Deque<ModuleRecorder> stack = new ArrayDeque<>(); Map<String, Module> fragmentMap = new HashMap<>(); public void enter(String module) { if (debug) { stack.push(new ModuleRecorder(getModule(module))); } } public Module getModule(String moduleName) { Module module = fragmentMap.get(moduleName); if (module == null) { module = new Module(moduleName); fragmentMap.put(moduleName, module); } return module; } public void exit() { if (debug) { ModuleRecorder fragment = stack.pop(); fragment.exit(); } } public void statistic() { if (!debug) { return; } if (stack.size() > 0) { throw new RuntimeException("Exist unexited tag"); } System.out.println("\n------------------------------------------"); System.out.println("memory used " + ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) >> 20) + "M"); System.out.println("\n------------------------------------------"); for (Module module : fragmentMap.values()) { System.out.println(String.format("Module %s : enter %d : cost %d", module.moduleName, module.enterTime, module.totaltime)); } System.out.println("------------------------------------------"); } public static class ModuleRecorder { Module fragment; long time; public ModuleRecorder(Module fragment) { this.fragment = fragment; time = System.currentTimeMillis(); } public void exit() { fragment.totaltime += System.currentTimeMillis() - time; fragment.enterTime++; } } public static class Module { String moduleName; long totaltime; long enterTime; public Module(String moduleName) { this.moduleName = moduleName; } } } public static class BlockReader { static final int EOF = -1; InputStream is; byte[] dBuf; int dPos, dSize, next; StringBuilder builder = new StringBuilder(); public BlockReader(InputStream is) { this(is, 8192); } public BlockReader(InputStream is, int bufSize) { this.is = is; dBuf = new byte[bufSize]; next = nextByte(); } public int nextByte() { while (dPos >= dSize) { if (dSize == -1) { return EOF; } dPos = 0; try { dSize = is.read(dBuf); } catch (Exception e) { } } return dBuf[dPos++]; } public String nextBlock() { builder.setLength(0); skipBlank(); while (next != EOF && !Character.isWhitespace(next)) { builder.append((char) next); next = nextByte(); } return builder.toString(); } public void skipBlank() { while (Character.isWhitespace(next)) { next = nextByte(); } } public int nextInteger() { skipBlank(); int ret = 0; boolean rev = false; if (next == '+' || next == '-') { rev = next == '-'; next = nextByte(); } while (next >= '0' && next <= '9') { ret = (ret << 3) + (ret << 1) + next - '0'; next = nextByte(); } return rev ? -ret : ret; } public int nextBlock(char[] data, int offset) { skipBlank(); int index = offset; int bound = data.length; while (next != EOF && index < bound && !Character.isWhitespace(next)) { data[index++] = (char) next; next = nextByte(); } return index - offset; } public boolean hasMore() { skipBlank(); return next != EOF; } } }
Java
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
823dc61a4426d39147f22753a9acf465
train_002.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class Main2 { private FastScanner scanner = new FastScanner(); public static void main(String[] args) { new Main2().solve(); } private void solve() { int n = scanner.nextInt(), k = scanner.nextInt(); char[][] ans = new char[4][n]; for (char[] ch : ans) { Arrays.fill(ch, '.'); } if (k % 2 == 0) { for (int i = 0; i < k / 2; i++) { ans[1][i + 1] = '#'; ans[2][i + 1] = '#'; } } else { ans[1][n / 2] = '#'; for (int i = 0; i < Math.min((n - 3) / 2, (k - 1) / 2); i++) { ans[1][n / 2 + (i + 1)] = '#'; ans[1][n / 2 - (i + 1)] = '#'; } if (k > n - 2) { ans[2][n - 2] = '#'; for (int i = 0; i < k - (n - 2) - 1; i++) { ans[2][i + 1] = '#'; } } } System.out.println("YES"); for (int i = 0; i < 4; i++) { for (int j = 0; j < n; j++) { System.out.print(ans[i][j]); } System.out.println(); } } long gcd(long a, long b) { if (b != 0) { return gcd(b, a % b); } return a; } class FastScanner { BufferedReader reader; StringTokenizer tokenizer; FastScanner() { reader = new BufferedReader(new InputStreamReader(System.in), 32768); tokenizer = null; } String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] nextA(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = scanner.nextInt(); } return a; } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } } }
Java
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
dcc3f12845bc42abb6b7b1459a682da7
train_002.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
import java.util.*; import java.math.*; import java.io.*; public class Solution{ public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); System.out.println("YES"); char[][] rep = new char[4][n]; for(int i=0;i<4;i++) Arrays.fill(rep[i],'.'); if(k%2==0){ for(int i=1;i<n-1;i++){ if(k==0) break; rep[1][i] = '#'; rep[2][i] = '#'; k -= 2; } }else{ k--; rep[2][n/2] = '#'; int c = 1; int kk = k; for(int i=n/2 + 1;i<n-1 && i<=n/2 + kk/2;i++){ rep[c][i] = '#'; if(c==1) c = 2; else c = 1; k--; } c = 1; for(int i=n/2-1;i>0;i--){ if(k==0) break; rep[c][i] = '#'; if(c==1) c = 2; else c = 1; k--; } if(k>0){ rep[c][1] = '#'; rep[c][n-2] = '#'; k -= 2; for(int i=2;i<n-2;i++){ if(k==0) break; if(rep[1][i]=='.') rep[1][i] = '#'; if(rep[2][i]=='.') rep[2][i] = '#'; k--; } } } for(int i=0;i<4;i++){ for(int j=0;j<n;j++){ System.out.print(rep[i][j]); } System.out.println(""); } } }
Java
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
5694dc7d8fecf58a861057cdf655457a
train_002.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
import java.sql.Array; import java.util.*; import java.io.*; public class Main { public static void main(String[] args) { InputReader in = new InputReader(System.in); PrintWriter out = new PrintWriter(System.out); TaskB.solve(in, out); out.close(); } static class TaskA { static public void solve(InputReader in, PrintWriter out) { String s = in.nextString(); int cnt1 = 0, cnt2 = 0; for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == 'o') cnt1++; else cnt2++; } if (cnt1 == 0 || cnt2 % cnt1 == 0) out.print("YES"); else out.print("NO"); } } static class TaskB { static void print(char[][] mat, PrintWriter out) { out.println("YES"); for (int i = 0; i < mat.length; i++) { for (int j = 0; j < mat[i].length; j++) out.print(mat[i][j]); out.println(); } } static public void solve(InputReader in, PrintWriter out) { int n = in.nextInt(); int k = in.nextInt(); char[][] mat = new char[4][n]; for (int i = 0; i < 4; i++) for (int j = 0; j < n; j++) mat[i][j] = '.'; for (int i = 1, j = n - 2; i <= j && k > 1; i++, j--) { mat[1][i] = mat[1][j] = '#'; if (i != j) k -= 2; else k--; } for (int i = 1, j = n - 2; i <= j && k > 1; i++, j--) { mat[2][i] = mat[2][j] = '#'; if (i != j) k -= 2; else k--; } if (k == 1) { if (mat[1][n / 2] == '.') mat[1][n / 2] = '#'; else mat[2][n / 2] = '#'; } print(mat, out); } } public static class Pair<T extends Comparable<T>, Y extends Comparable<Y>> implements Comparable<Pair<T, Y>> { public T first; public Y second; Pair() { first = null; second = null; } Pair(T first, Y second) { this.first = first; this.second = second; } public int compareTo(Pair<T, Y> p) { int a = first.compareTo(p.first); if (a != 0) return a; a = second.compareTo(p.second); return a; } } public static class InputReader { BufferedReader reader; StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public String nextString() { 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(nextString()); } public long nextLong() { return Long.parseLong(nextString()); } public double nextDouble() { return Double.parseDouble(nextString()); } } }
Java
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
33d074fa5192f2b81e43fc8045f4fade
train_002.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { static boolean[][] field = new boolean[4][101]; public static void main(String[] args) { // Scanner reader = new Scanner(System.in); InputReader reader = new InputReader(); int n = reader.nextInt(); int k = reader.nextInt(); System.out.println("YES"); for (int i = 1; i < n - 1; i++) { for (int j = 1; j < 3; j++) { if (k <= 1) { break; } k -= 2; field[j][i] = true; field[j][n - 1 - i] = true; if (n - 1 - i == i) { k++; } } } if (k > 0 && !field[1][n / 2]) { field[1][n / 2] = true; k--; } if (k > 0) { field[2][n / 2] = true; } for (int i = 0; i < 4; i++) { for (int j = 0; j < n; j++) { if (field[i][j]) { System.out.print('#'); continue; } System.out.print('.'); } System.out.println(); } } } class InputReader { BufferedReader buf; StringTokenizer tok; InputReader() { buf = new BufferedReader(new InputStreamReader(System.in)); } boolean hasNext() { while (tok == null || !tok.hasMoreElements()) { try { tok = new StringTokenizer(buf.readLine()); } catch (Exception e) { return false; } } return true; } String next() { if (hasNext()) return tok.nextToken(); return null; } String nextLine() throws IOException { return buf.readLine(); } char nextChar() { return next().charAt(0); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } static void deBug(int n, int m, int[][] array) { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { System.out.print(array[i][j] + " "); } System.out.println(); } } /* * BigInteger nextBigInteger() { return new BigInteger(next()); } * * BigDecimal nextBigDecimal() { return new BigDecimal(next()); } */ } // wow, thanks for your code review!
Java
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
3a0772aa0619d4f1d7b2ed47cbc8ab2f
train_002.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
import java.util.Scanner; public class B { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(), k = sc.nextInt(); int r = 2, c = n - 2; boolean[][] mid = new boolean[r][c]; if(k > r * c){ System.out.println("NO"); return; } for(int i = 0; i < c; ++i){ if(k < 2) break; int cr = i % 2, cc = i / 2; mid[cr][cc] = true; mid[cr][c - 1 - cc] = true; if(cc == c - 1 - cc) k--; else k -= 2; } if(k == 1){ mid[r - 1][c / 2] = true; } System.out.println("YES"); for(int i = -1; i < r + 1; ++i){ for(int j = -1; j < c + 1; ++j){ if(i >= 0 && i < r && j >= 0 && j < c && mid[i][j]){ System.out.print('#'); } else{ System.out.print('.'); } } System.out.println(); } } }
Java
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
0d869dc7ba6532a593159142e55d2b48
train_002.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
import java.math.BigDecimal; import java.math.BigInteger; import java.math.MathContext; import java.math.RoundingMode; import java.util.*; public class Main { public static void main(String args[]) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int k = in.nextInt(); if(k % 2 == 0) { System.out.println("YES"); for(int i = 0; i < n; i++) { System.out.print("."); } System.out.println(); System.out.print("."); int cols = k / 2; for(int i = 0; i < cols; i++) { System.out.print("#"); } for(int i = cols+1; i < n;i++) { System.out.print("."); } System.out.println(); System.out.print("."); for(int i = 0; i < cols; i++) { System.out.print("#"); } for(int i = cols+1; i < n;i++) { System.out.print("."); } System.out.println(); for(int i = 0; i < n; i++) { System.out.print("."); } System.out.println(); } /*else if(k <= n-2) { System.out.println("YES"); for(int i = 0; i < n; i++) { System.out.print("."); } System.out.println(); int temp = (n-k)/2; for(int i = 0; i < temp; i++) { System.out.print("."); } for(int i = 0; i < k; i++) { System.out.print("#"); } for(int i = 0; i < temp; i++) { System.out.print("."); } System.out.println(); for(int i = 0; i < n; i++) { System.out.print("."); } System.out.println(); for(int i = 0; i < n; i++) { System.out.print("."); } System.out.println(); } */else { System.out.println("YES"); for(int i = 0; i < n; i++) { System.out.print("."); } System.out.println(); if(k <= n-2) { int temp = (n-k)/2; for(int i = 0; i < temp; i++) { System.out.print("."); } for(int i = 0; i < k; i++) { System.out.print("#"); } for(int i = 0; i < temp; i++) { System.out.print("."); } System.out.println(); for(int i = 0; i < n; i++) { System.out.print("."); } System.out.println(); } else { System.out.print("."); for(int i = 0; i < n-2; i++) { System.out.print("#"); } System.out.print("."); System.out.println(); k -= n-2; System.out.print("."); int temp = k/2; for(int i = 0; i < temp; i++) { System.out.print("#"); } for(int i = 0; i < n-2-k; i++) { System.out.print("."); } for(int i = 0; i < temp; i++) { System.out.print("#"); } System.out.print("."); System.out.println(); } for(int i = 0; i < n; i++) { System.out.print("."); } System.out.println(); } } }
Java
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
138d955e2810f178fe095fe79714eaba
train_002.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
// TODAY I WILL BECOME EXPERT ! import java.util.*; import java.math.*; import java.io.*; public class q_6 { static Scanner sc; public static void main(String[] args){ sc = new Scanner(System.in); int n = getInt(); int k = getInt(); int v = k; int x1 = 1; int c1 = 1; int x2 = 1; int c2 = n-2; int[][] mat = new int[4][n]; for(int i=0 ; i<k ;){ if(v>=2){ if(c2-c1>=1){ mat[x1][c1++]=1; mat[x2][c2--]=1; i+=2; v-=2; } else { if(x1==1){ x1=2; x2=2; c1=1; c2=n-2; } else { if(v==2){ if(mat[1][n/2]==0 && mat[2][n/2]==0){ mat[1][n/2] = mat[2][n/2] = 1; i+=2; v-=2; } else { System.out.println("NO"); return; } } else { System.out.println("NO"); return; } } } } else { if(mat[1][n/2]==0){ mat[1][n/2]=1; v--; i++; } else { if(mat[2][n/2]==0){ mat[2][n/2]=1; v--; i++; } else { System.out.println("NO"); return; } } } } System.out.println("YES"); int cc = 0; for(int i=0 ; i<4 ; i++){ for(int j=0 ; j<n ; j++){ if(mat[i][j]==1){ cc++; } System.out.print((mat[i][j]==0)?('.'):('#')); } System.out.println(); } } public static int getInt(){ return sc.nextInt(); } public static String getString(){ return sc.next(); } public static String nextLine(){ return sc.nextLine(); } public static long nextLong(){ return sc.nextLong(); } }
Java
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
c27440282ffae4b986039694f90583a7
train_002.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
import java.util.Arrays; import java.util.Scanner; //accidentally stabbed my hand while cutting avacado :( //still programming tho :) public class Marlin { public static void main(String[] args) { Scanner scan=new Scanner(System.in); int n=scan.nextInt(), k=scan.nextInt(); char[][] a=new char[4][n]; for(char[] c:a)Arrays.fill(c,'.'); if(k%2==0) { for(int i=0;i<k/2;i++) { a[1][i+1]=a[2][i+1]='#'; } } else if(k>n-2) { a[1][1]=a[2][1]=a[1][n-2]=a[2][n-2]='#'; k-=(n==3)?2:4; //fill in the rest for(int i=1;i<3;i++) { for(int j=2;j<n-2;j++) { if(k>0) { a[i][j]='#'; k--; } } } } else { for(int i=1;i<3;i++) { for(int j=0;j<n-1;j++) { if(k>0) { a[i][(int)((n+0.5)/2)-j]='#'; a[i][(int)((n+0.5)/2)+j]='#'; k-=j==0?1:2; } } } } System.out.println("YES"); for(char[] c:a) System.out.println(new String(c)); } }
Java
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
6b0df9ac639d72b866f6aa4afc8864aa
train_002.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class B2 { public static void main(String[] args) { FastScanner fs=new FastScanner(); int width=fs.nextInt()-2; int toPlace=fs.nextInt(); boolean[][] board=new boolean[width][2]; if (toPlace>=width) { toPlace-=width; for (int i=0; i<width; i++) { board[i][0]=true; } } for (int i=0; i<toPlace/2; i++) { board[i][1]=true; board[width-i-1][1]=true; } if (toPlace%2==1) { board[width/2][1]=true; } /*else if (toPlace%2==0) { for (int i=0; i<toPlace/2; i++) board[i][1]=board[i][0]=true; }*/ System.out.println("YES"); for (int i=0; i<width+2; i++) { System.out.print('.'); } System.out.println(); System.out.print('.'); for (int i=0; i<width; i++) System.out.print(board[i][0]?'#':'.'); System.out.println('.'); System.out.print('.'); for (int i=0; i<width; i++) System.out.print(board[i][1]?'#':'.'); System.out.println('.'); for (int i=0; i<width+2; i++) { System.out.print('.'); } // System.out.println(); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); public String next() { while (!st.hasMoreElements()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } } }
Java
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
4ef68bb1611295cf58160e1a4029827b
train_002.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
/** * Date: 8 May, 2018 * Link: * * @author Prasad-Chaudhari * @email prasadc8897@gmail.com */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class newProgram4 { public static void main(String[] args) throws IOException { // TODO code application logic here FastIO2 in = new FastIO2(); int n = in.ni(); int k = in.ni(); char c[][] = new char[4][n]; for (int i = 0; i < 4; i++) { Arrays.fill(c[i], '.'); } if (k % 2 == 0) { for (int i = 1; i < n - 1; i++) { if (k > 0) { c[1][i] = '#'; k--; } if (k > 0) { c[2][i] = '#'; k--; } } } else { c[1][n / 2] = '#'; k--; for (int i = n / 2 - 1; i >= 1; i--) { if (k > 0) { c[1][i] = '#'; k--; } if (k > 0) { c[1][n - 1 - i] = '#'; k--; } } if (k > 0) { for (int i = 1; i <n/2; i++) { if (k > 0) { c[2][i] = '#'; k--; } if (k > 0) { c[2][n - 1 - i] = '#'; k--; } } } if(k>0){ c[2][n/2]='#'; k--; } } if (k == 0) { System.out.println("Yes"); for (int i = 0; i < 4; i++) { System.out.println(c[i]); } } else { System.out.println("NO"); } } static class FastIO2 { private final BufferedReader br; private String s[]; private int index; public FastIO2() throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); 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; } 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
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
6a941904d0a2f8f4fa7c7b3f3ab9bb6f
train_002.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
import java.util.*; /** * * @author comp */ public class Olimp { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int k = in.nextInt(); System.out.println("YES"); if(k%2==0){ for (int i = 0; i < 4; i++) { for (int j = 0; j < n; j++) { if((i==1||i==2) && j!=0 && j<=k/2){ System.out.print("#"); } else System.out.print("."); } System.out.println(""); } } else if(k==n-2){ for (int i = 0; i < 4; i++) { for (int j = 0; j < n; j++) { if(i==1 && (j>0 && j<n-1)){ System.out.print("#"); } else System.out.print("."); } System.out.println(""); } } else if(k<n-2){ for (int i = 0; i < 4; i++) { for (int j = 0; j < n; j++) { if (i==1 && (j>0 && j<=(k-1)/2 || j<n-1 && j>=n-(k-1)/2-1)){ System.out.print("#"); } else if (i==2 && j==n/2){ System.out.print("#"); } else System.out.print("."); } System.out.println(""); } } else if(k>n-2){ for (int i = 0; i < 4; i++) { for (int j = 0; j < n; j++) { if(i==1 && (j>0 && j<n-1)){ System.out.print("#"); } else if(i==2 && (j>0 && j<k-n+2 || j==n-2)){ System.out.print("#"); } else System.out.print("."); } System.out.println(""); } } } }
Java
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
2d19bae5e7048f11ac59bbda5b570783
train_002.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; import java.util.Arrays; import java.util.NoSuchElementException; public class Main { private static final PrintStream ps = System.out; private static final InputStream IS = System.in; private static final byte[] BUFFER = new byte[1024]; private static int ptr = 0; private static int buflen = 0; public static void main(String[] args) { int n = ni(); int k = ni(); char[][] a = new char[4][]; for (int i = 0; i < 4; i++) { a[i] = new char[n]; Arrays.fill(a[i], '.'); } if (k >= n) { ps.println("YES"); for (int i = 1; i <= n-2; i++) { a[1][i] = '#'; } a[2][1] = '#'; a[2][n-2] = '#'; for (int i = 0; i < k-n; i++) { a[2][i+2] = '#'; } pa(a); return; } else if (k % 2 == 0) { ps.println("YES"); for (int i = 0; i < k/2; i++) { a[1][i+1] = '#'; a[2][i+1] = '#'; } pa(a); } else { ps.println("YES"); a[1][n/2] = '#'; for (int i = 0; i <= k/2; i++) { a[1][n/2 + i] = '#'; a[1][n/2 - i] = '#'; } pa(a); } } private static void pa(char[][] a) { for (int i = 0; i < a.length; i++) { for (int j = 0; j < a[i].length; j++) { ps.print(a[i][j]); } if (i != a.length-1) ps.println(); } } private static boolean hasNextByte() { if (ptr < buflen) return true; else { ptr = 0; try { buflen = IS.read(BUFFER); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) return false; } return true; } private static int readByte() { if (hasNextByte()) return BUFFER[ptr++]; else return -1; } private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126; } public static boolean hasNext() { while (hasNextByte() && !isPrintableChar(BUFFER[ptr])) ptr++; return hasNextByte(); } public static String n() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while (isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public static long nl() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) throw new NumberFormatException(); while (true) { if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; } else if (b == -1 || !isPrintableChar(b)) return minus ? -n : n; else throw new NumberFormatException(); b = readByte(); } } public static int ni() { long nl = nl(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public static double nextDouble() { return Double.parseDouble(n()); } private static int[] nia(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = ni(); return a; } }
Java
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
42bd551ab7aa23f8980f15000315f109
train_002.jsonl
1525791900
The city of Fishtopia can be imagined as a grid of $$$4$$$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $$$(1,1)$$$, people who stay there love fishing at the Tuna pond at the bottom-right cell $$$(4, n)$$$. The second village is located at $$$(4, 1)$$$ and its people love the Salmon pond at $$$(1, n)$$$.The mayor of Fishtopia wants to place $$$k$$$ hotels in the city, each one occupying one cell. To allow people to enter the city from anywhere, hotels should not be placed on the border cells.A person can move from one cell to another if those cells are not occupied by hotels and share a side.Can you help the mayor place the hotels in a way such that there are equal number of shortest paths from each village to its preferred pond?
256 megabytes
//980B //Marlin import java.util.Arrays; import java.util.Scanner; public class Marlin { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int hotels = sc.nextInt(); char[][] grid = new char[5][n + 1]; for(char[] x : grid) Arrays.fill(x, '.'); for(int i = 2; i < 4; i++) for(int j = 2; j < n; j++) if(hotels > 0 && j <= (n + 1 - j)) { if(j == (n + 1 - j)) { grid[i][j] = '#'; hotels--; } else if(hotels > 1) { grid[i][j] = '#'; grid[i][n + 1 - j] = '#'; hotels -= 2; } } System.out.println("YES"); for(int i = 1; i < 5; i++) { for(int j = 1; j < n + 1; j++) System.out.print(grid[i][j]); System.out.println(); } } }
Java
["7 2", "5 3"]
1 second
["YES\n.......\n.#.....\n.#.....\n.......", "YES\n.....\n.###.\n.....\n....."]
null
Java 8
standard input
[ "constructive algorithms" ]
2669feb8200769869c4b2c29012059ed
The first line of input contain two integers, $$$n$$$ and $$$k$$$ ($$$3 \leq n \leq 99$$$, $$$0 \leq k \leq 2\times(n-2)$$$), $$$n$$$ is odd, the width of the city, and the number of hotels to be placed, respectively.
1,600
Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO". If it is possible, print an extra $$$4$$$ lines that describe the city, each line should have $$$n$$$ characters, each of which is "#" if that cell has a hotel on it, or "." if not.
standard output
PASSED
7d1f2160144fd32ef54376e34c4b04be
train_002.jsonl
1330804800
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); int[] mas = new int[4]; int result, ost; for(int i = 0; i < t; i++) { mas[scan.nextInt() - 1]++; } ost = mas[0]; ost -= mas[2]; result = (int)Math.ceil((float)mas[1] / 2); ost -= (mas[1] & 1) * 2; result += mas[2] + mas[3]; if(ost > 0) { result += ost / 4; if ((ost & 3) > 0) { result++; } } System.out.println(result); } }
Java
["5\n1 2 4 3 3", "8\n2 3 4 4 2 1 3 1"]
3 seconds
["4", "5"]
NoteIn the first test we can sort the children into four cars like this: the third group (consisting of four children), the fourth group (consisting of three children), the fifth group (consisting of three children), the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
Java 11
standard input
[ "implementation", "*special", "greedy" ]
371100da1b044ad500ac4e1c09fa8dcb
The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group.
1,100
Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus.
standard output
PASSED
751e761651505caa1b9c6f22c4f1f1b9
train_002.jsonl
1330804800
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
256 megabytes
import java.util.*; public class ClassA { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int loops = sc.nextInt(); int n1=0; int n2=0; int n3=0; int n4=0; for(int i=0;i<loops;i++) { int num = sc.nextInt(); if(num==1) { n1++; }else if(num==2) { n2++; }else if(num==3) { n3++; }else if(num==4) { n4++; } } int taxino=n4; while(n1!=0||n2!=0||n3!=0) { if(n3!=0 && n1!=0) { taxino++; n3--; n1--; }else if(n2>=2) { taxino++; n2=n2-2; }else if(n2!=0 && n1>=2) { taxino++; n2--; n1=n1-2; }else if(n2!=0 && n1!=0) { taxino++; n2--; n1--; }else if(n1 !=0) { if(n1%4!=0) { taxino=taxino+(n1/4)+1; n1=0; }else { taxino=taxino+(n1/4); n1=0; } }else if (n2 !=0) { if(n2%4!=0) { taxino=taxino+(n2/4)+1; n2=0; }else { taxino=taxino+(n2/4); n2=0;} } else if (n3 !=0) { taxino=taxino+n3; n3=0; } } System.out.println(taxino); } }
Java
["5\n1 2 4 3 3", "8\n2 3 4 4 2 1 3 1"]
3 seconds
["4", "5"]
NoteIn the first test we can sort the children into four cars like this: the third group (consisting of four children), the fourth group (consisting of three children), the fifth group (consisting of three children), the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
Java 11
standard input
[ "implementation", "*special", "greedy" ]
371100da1b044ad500ac4e1c09fa8dcb
The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group.
1,100
Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus.
standard output
PASSED
2c085fdcc7eccb8c1cdbcbd5185aceee
train_002.jsonl
1330804800
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
256 megabytes
import java.util.*; import java.lang.*; public class Main{ public static void main(String args[]){ Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int group[] = new int[n]; int count[] = new int[5]; for(int i = 0; i < n; i++){ group[i] = scan.nextInt(); count[group[i]]++; } int taxi = count[4]; count[4] = 0; taxi += (count[2]/2); count[2] = count[2]%2; if(count[1] >= count[3]){ taxi += count[3]; count[1] = count[1] - count[3]; count[3] = 0; taxi += count[1]/4; count[1] = count[1]%4; if(count[1] + count[2]*2 <= 4 && count[1] + count[2]*2 > 0){ taxi++; count[1] = 0; count[2] = 0; } else if(count[1] == 3 && count[2] == 1){ taxi += 2; count[1] = 0; count[2] = 0; } } else{ taxi += count[1]; count[3] = count[3] - count[1]; count[1] = 0; taxi += count[3] + count[2]; } System.out.println(taxi); } }
Java
["5\n1 2 4 3 3", "8\n2 3 4 4 2 1 3 1"]
3 seconds
["4", "5"]
NoteIn the first test we can sort the children into four cars like this: the third group (consisting of four children), the fourth group (consisting of three children), the fifth group (consisting of three children), the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
Java 11
standard input
[ "implementation", "*special", "greedy" ]
371100da1b044ad500ac4e1c09fa8dcb
The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group.
1,100
Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus.
standard output
PASSED
7abc19edb3373f9c3b65b779aa88141a
train_002.jsonl
1330804800
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
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 x; int n1=0, n2=0, n3=0; int car = 0; for(int i=1; i<=n; i++) { x = input.nextInt(); if(x==4) { car++; } if(x==3) { n3++; } if(x==2) { n2++; } if(x==1) { n1++; } } car+=n3; n1 = n1-n3; if(n2%2==0) { car+=(n2/2); } else if(n2%2==1){ car+=(n2+1)/2; n1-=2; } if(n1 > 0) { car+=Math.ceil((double) n1/4); } System.out.println(car); } }
Java
["5\n1 2 4 3 3", "8\n2 3 4 4 2 1 3 1"]
3 seconds
["4", "5"]
NoteIn the first test we can sort the children into four cars like this: the third group (consisting of four children), the fourth group (consisting of three children), the fifth group (consisting of three children), the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
Java 11
standard input
[ "implementation", "*special", "greedy" ]
371100da1b044ad500ac4e1c09fa8dcb
The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group.
1,100
Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus.
standard output
PASSED
678a0423f29beea2cdd3f8a7e7b15e5e
train_002.jsonl
1330804800
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
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 x; //JR Jahed int n1=0, n2=0, n3=0; int car = 0; for(int i=1; i<=n; i++) { x = input.nextInt(); if(x==4) { car++; } if(x==3) { n3++; } if(x==2) { n2++; } if(x==1) { n1++; } } car+=n3; n1 = n1-n3; if(n2%2==0) { car+=(n2/2); } else if(n2%2==1){ car+=(n2+1)/2; n1-=2; } if(n1 > 0) { car+=Math.ceil((double) n1/4); } System.out.println(car); } }
Java
["5\n1 2 4 3 3", "8\n2 3 4 4 2 1 3 1"]
3 seconds
["4", "5"]
NoteIn the first test we can sort the children into four cars like this: the third group (consisting of four children), the fourth group (consisting of three children), the fifth group (consisting of three children), the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
Java 11
standard input
[ "implementation", "*special", "greedy" ]
371100da1b044ad500ac4e1c09fa8dcb
The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group.
1,100
Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus.
standard output
PASSED
d4ef285987b72b12923916e8bdef463d
train_002.jsonl
1330804800
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
256 megabytes
import java.util.Scanner; public class main { public static void main(String[] args) { Scanner ssd = new Scanner(System.in); int count_1=0; int count_2=0; int count_3=0; int result = 0; int temp; int n = ssd.nextInt(); int array[] = new int[n]; for (int t = 0; t < n; t++) { temp= ssd.nextInt(); if(temp==4) result++; else if(temp==1)count_1++; else if(temp==2)count_2++; else if(temp==3)count_3++; } int t; for(t=0;t<count_1&&t<count_3;t++){ }result+=t;count_1-=t;count_3-=t; result+=count_3; result+=count_2/2; count_2=count_2 % 2; result+=count_1/4; count_1=count_1 % 4; if(count_1==0&&count_2==0){ System.out.println(result); }else{ if(count_1==0)result++; else if(count_2==0)result++; else if(count_1==3)result+=2; else result++; System.out.println(result); } }}
Java
["5\n1 2 4 3 3", "8\n2 3 4 4 2 1 3 1"]
3 seconds
["4", "5"]
NoteIn the first test we can sort the children into four cars like this: the third group (consisting of four children), the fourth group (consisting of three children), the fifth group (consisting of three children), the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
Java 11
standard input
[ "implementation", "*special", "greedy" ]
371100da1b044ad500ac4e1c09fa8dcb
The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group.
1,100
Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus.
standard output
PASSED
996661bf46dfa71fde871ac97486aec3
train_002.jsonl
1330804800
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
256 megabytes
import java.util.Scanner; public class practice { public static void main(String[] args) { Scanner inp=new Scanner(System.in); int c1=0,c2=0,c3=0,c4=0; int n=inp.nextInt(),h; inp.nextLine(); while(n-->0) { h=inp.nextInt(); if(h==1)c1++; else if(h==2)c2++; else if(h==3)c3++; else c4++; } int s=0; s+=c4; s+=c3; c1-=c3; if(c1<0)c1=0; s+=c2/2; if(c2%2==1) { s+=1; c1-=2; } if(c1>0) { s+=c1/4; c1%=4; if(c1>0) { s+=1; } } System.out.println(s); inp.close(); } }
Java
["5\n1 2 4 3 3", "8\n2 3 4 4 2 1 3 1"]
3 seconds
["4", "5"]
NoteIn the first test we can sort the children into four cars like this: the third group (consisting of four children), the fourth group (consisting of three children), the fifth group (consisting of three children), the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
Java 11
standard input
[ "implementation", "*special", "greedy" ]
371100da1b044ad500ac4e1c09fa8dcb
The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group.
1,100
Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus.
standard output
PASSED
4e3511d5e2bc954bbd9ee7944355653c
train_002.jsonl
1330804800
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
256 megabytes
import java.util.Scanner; public class Taxi { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int temp; int counter = 0; int[] arr = new int[] { 0, 0, 0, 0, 0 }; for (int i = 0; i < n; i++) { temp = scanner.nextInt(); arr[temp]++; } counter = arr[4]; // add all the 4s arr[4] = 0; // while we can get pairs of [1, 3] if (arr[1] > 0 && arr[3] > 0) { int min = Math.min(arr[1], arr[3]); arr[1] -= min; arr[3] -= min; counter += min; } if (arr[2] > 1) { while (arr[2] > 1) { counter++; arr[2] -= 2; } } while (arr[1] > 3) { counter++; arr[1] -= 4; } if (arr[1] == 2 && arr[2] == 1) { counter++; arr[1] = 0; arr[2] = 0; } if (arr[1] > 0 && arr[2] > 0) { int min = Math.min(arr[1], arr[2]); arr[1] -= min; arr[2] -= min; counter += min; } if (arr[1] < 4 && arr[1] > 0) { arr[1] = 0; counter++; } // while we can get pairs of [1, 2] for (int i = 1; i <= 4; i++) { counter += arr[i]; } System.out.print(counter); scanner.close(); } }
Java
["5\n1 2 4 3 3", "8\n2 3 4 4 2 1 3 1"]
3 seconds
["4", "5"]
NoteIn the first test we can sort the children into four cars like this: the third group (consisting of four children), the fourth group (consisting of three children), the fifth group (consisting of three children), the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
Java 11
standard input
[ "implementation", "*special", "greedy" ]
371100da1b044ad500ac4e1c09fa8dcb
The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group.
1,100
Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus.
standard output
PASSED
0de62572ab364d98a15a22c5aea069b4
train_002.jsonl
1330804800
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); long n = scanner.nextLong(); int cnt = 0; int cntOf1 = 0; int cntOf2 = 0; int cntOf3 = 0; for (int i = 0; i < n; i++) { int a = scanner.nextInt(); if (a == 1) { cntOf1++; } else if (a == 2) { cntOf2++; } else if (a == 3) { cntOf3++; } else { cnt++; } } if (cntOf2 % 2 == 0) { cnt += cntOf2 / 2; cntOf2 = 0; } else { cnt += cntOf2 / 2; cntOf2 = 1; } while (cntOf3 != 0) { if (cntOf1 == 0) { cnt += cntOf3; break; } else { cnt++; cntOf1--; cntOf3--; } } if (cntOf2 == 1 && cntOf1 >= 2) { cntOf2--; cntOf1 -= 2; cnt++; } else { if (cntOf2 == 1 && cntOf1 == 1) { cnt++; cntOf2--; cntOf1--; } if (cntOf2 == 1) { cnt++; cntOf2--; } if (cntOf1 % 4 != 0) { cnt += cntOf1 / 4 + 1; cntOf1 = 0; } else { cnt += cntOf1 / 4; cntOf1 = 0; } } if (cntOf1 % 4 != 0 && cntOf1 > 0) { cnt += cntOf1 / 4 + 1; cntOf1 = 0; } if (cntOf1 % 4 == 0 && cntOf1 > 0) { cnt += cntOf1 / 4; } System.out.println(cnt); } }
Java
["5\n1 2 4 3 3", "8\n2 3 4 4 2 1 3 1"]
3 seconds
["4", "5"]
NoteIn the first test we can sort the children into four cars like this: the third group (consisting of four children), the fourth group (consisting of three children), the fifth group (consisting of three children), the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
Java 11
standard input
[ "implementation", "*special", "greedy" ]
371100da1b044ad500ac4e1c09fa8dcb
The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group.
1,100
Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus.
standard output
PASSED
3f24ff75d09c2b6d940f040d5c967574
train_002.jsonl
1330804800
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
256 megabytes
import java.util.Scanner ; import java.util.Arrays ; public class Main { // it returns number of cars used // it modifies numbber of ones to those left // at the end no 3's will be left static int getRidOfThrees(int[] countOfNumbers) { int combined_one_three = Integer.min(countOfNumbers[3], countOfNumbers[1]); int ans = combined_one_three; // now add any 3's if left ans += countOfNumbers[3] - combined_one_three; // Update counts countOfNumbers[3] = 0; countOfNumbers[1] -= combined_one_three; return ans; } // Update count of two's and return the numbebr of cars used static int getRidOfTwos(int[] countOfNumbers) { int are_any_left = (countOfNumbers[2]%2); int cars_used = countOfNumbers[2]/2 ; // update counts countOfNumbers[2] = are_any_left; return cars_used; } static int getRidOfOnes(int[] countOfNumbers) { int ans = countOfNumbers[1]/4; countOfNumbers[1] %= 4; return ans; } public static void main(String[] args) { Scanner myObj = new Scanner(System.in) ; int m = myObj.nextInt() ; int[] countOfNumbers = new int[5] ; for(int i = 0; i < m; ++i) { int x = myObj.nextInt(); countOfNumbers[x] ++; } // get rid of 4's int ans = countOfNumbers[4]; // get rid of 3's ans += getRidOfThrees(countOfNumbers); // get rid of 2's! ans += getRidOfTwos(countOfNumbers); // get rid of 1's ans += getRidOfOnes(countOfNumbers); // you have at most 3 1's and 1 2. if(countOfNumbers[1] == 3 && countOfNumbers[2] == 1) { ans += 2; } else if(countOfNumbers[1] > 0 || countOfNumbers[2] > 0) { ans += 1; } System.out.println(ans) ; } }
Java
["5\n1 2 4 3 3", "8\n2 3 4 4 2 1 3 1"]
3 seconds
["4", "5"]
NoteIn the first test we can sort the children into four cars like this: the third group (consisting of four children), the fourth group (consisting of three children), the fifth group (consisting of three children), the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
Java 11
standard input
[ "implementation", "*special", "greedy" ]
371100da1b044ad500ac4e1c09fa8dcb
The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group.
1,100
Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus.
standard output
PASSED
2fe09b898c512627614c53a73de79d0f
train_002.jsonl
1330804800
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); int[] groups = new int[n]; for (int i = 0; i < n; ++i){ groups[i] = s.nextInt(); } Arrays.sort(groups); int cars = 0; int right = n-1, left = 0; while(right >= 0 && groups[right] == 4){ ++cars; --right; } while (left < right){ if (groups[left]+groups[right] < 4){ int sum = groups[left]+groups[right]; left++; while (left < right && sum+groups[left] <= 4){ sum += groups[left]; left++; } cars++; --right; }else if (groups[left]+groups[right] == 4){ cars++; left++; --right; }else{ cars++; --right; } } if (left == right){ cars++; // if its like -> 1 2 3 (2) will not be reached } //System.out.println(Arrays.toString(groups)); System.out.println(cars); } }
Java
["5\n1 2 4 3 3", "8\n2 3 4 4 2 1 3 1"]
3 seconds
["4", "5"]
NoteIn the first test we can sort the children into four cars like this: the third group (consisting of four children), the fourth group (consisting of three children), the fifth group (consisting of three children), the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
Java 11
standard input
[ "implementation", "*special", "greedy" ]
371100da1b044ad500ac4e1c09fa8dcb
The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group.
1,100
Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus.
standard output
PASSED
1dc42fd38544191c31a8f94b5c71acee
train_002.jsonl
1330804800
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
256 megabytes
import java.util.*; import java.io.*; public class Solution{ public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String input = br.readLine(); StringTokenizer st = new StringTokenizer(input, " "); int total = Integer.parseInt(st.nextToken()); input = br.readLine(); st = new StringTokenizer(input, " "); int[] in = new int[total]; for(int i = 0; i<in.length; i++){ in[i] = Integer.parseInt(st.nextToken()); } Arrays.sort(in); int count = 0; //Solution starts here //redo for efficiency using single loop int i = 0; int j = in.length-1; int taxi = 0; int sum = in[j]; while(i!=j){ if(sum+in[i]>4 || sum==4){ j--; taxi++; sum = in[j]; } else{ sum+=in[i]; i++; } } System.out.println(taxi+1); } }
Java
["5\n1 2 4 3 3", "8\n2 3 4 4 2 1 3 1"]
3 seconds
["4", "5"]
NoteIn the first test we can sort the children into four cars like this: the third group (consisting of four children), the fourth group (consisting of three children), the fifth group (consisting of three children), the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
Java 11
standard input
[ "implementation", "*special", "greedy" ]
371100da1b044ad500ac4e1c09fa8dcb
The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group.
1,100
Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus.
standard output
PASSED
4daab9b00096583a1a44bd44fe8cf48d
train_002.jsonl
1330804800
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
256 megabytes
import java.util.Scanner; public class _01Taxi { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int nGroups = sc.nextInt(); int[] arr = new int[4]; int res = 0; while (nGroups > 0) { int next = sc.nextInt(); if (next == 4) res++; else arr[next]++; nGroups--; } while (arr[1] > 0 && arr[3] > 0) { arr[1]--; arr[3]--; res++; } while (arr[2] >= 2) { arr[2] -= 2; res++; } while (arr[2] > 0 && arr[1] >= 2) { arr[2]--; arr[1] -= 2; res++; } while (arr[1] >= 4) { arr[1] -= 4; res++; } if (arr[2] != 0 && arr[1] != 0 || arr[2] != 0 || arr[1] != 0) res++; System.out.println(res + arr[3]); } }
Java
["5\n1 2 4 3 3", "8\n2 3 4 4 2 1 3 1"]
3 seconds
["4", "5"]
NoteIn the first test we can sort the children into four cars like this: the third group (consisting of four children), the fourth group (consisting of three children), the fifth group (consisting of three children), the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
Java 11
standard input
[ "implementation", "*special", "greedy" ]
371100da1b044ad500ac4e1c09fa8dcb
The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group.
1,100
Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus.
standard output
PASSED
0de12b4c7b9cf723b5549c1f5a2cf0c2
train_002.jsonl
1330804800
After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≀ si ≀ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?
256 megabytes
import java.util.Scanner; public class asss { public static void main(String args[]) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int arr[]=new int[n]; int once=0,twice=0,thrice=0,fours=0; for(int x=0;x<n;x++) { arr[x]=sc.nextInt(); if(arr[x]==1) once++; else if(arr[x]==2) twice++; else if(arr[x]==3) thrice++; else if(arr[x]==4) fours++; } int l=n; int taxi=0; taxi+=fours; l-=fours; if(thrice!=0) while(thrice!=0) { thrice--; if(once!=0) { once--; } taxi++; } if(twice!=0) { int temp=twice/2; taxi+=temp; twice=twice-(temp*2); if(twice!=0) { taxi++; twice--; if(once!=0) { if(once>1) once-=2; else once--; } } } if(once!=0) { int temp=once/4; taxi+=temp; once=once-(temp*4); if(once!=0) { taxi++; } } System.out.println(taxi); } }
Java
["5\n1 2 4 3 3", "8\n2 3 4 4 2 1 3 1"]
3 seconds
["4", "5"]
NoteIn the first test we can sort the children into four cars like this: the third group (consisting of four children), the fourth group (consisting of three children), the fifth group (consisting of three children), the first and the second group (consisting of one and two children, correspondingly). There are other ways to sort the groups into four cars.
Java 11
standard input
[ "implementation", "*special", "greedy" ]
371100da1b044ad500ac4e1c09fa8dcb
The first line contains integer n (1 ≀ n ≀ 105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≀ si ≀ 4). The integers are separated by a space, si is the number of children in the i-th group.
1,100
Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus.
standard output
PASSED
04fa03de7c7c08d05057ead0df79d8aa
train_002.jsonl
1455807600
IT City administration has no rest because of the fame of the Pyramids in Egypt. There is a project of construction of pyramid complex near the city in the place called Emerald Walley. The distinction of the complex is that its pyramids will be not only quadrangular as in Egypt but also triangular and pentagonal. Of course the amount of the city budget funds for the construction depends on the pyramids' volume. Your task is to calculate the volume of the pilot project consisting of three pyramids β€” one triangular, one quadrangular and one pentagonal.The first pyramid has equilateral triangle as its base, and all 6 edges of the pyramid have equal length. The second pyramid has a square as its base and all 8 edges of the pyramid have equal length. The third pyramid has a regular pentagon as its base and all 10 edges of the pyramid have equal length.
64 megabytes
import java.io.*; import java.util.*; public class q { public static void main(String[] args) throws IOException { input.init(System.in); PrintWriter out = new PrintWriter(System.out); double a = input.nextLong(), b = input.nextLong(), c = input.nextLong(); double res = 0; res += a*a*a / (6*Math.sqrt(2)); res += b*b * (b*Math.sqrt(2)) / 6; res += c*c*c * (5 + Math.sqrt(5)) / 24; out.println(res); out.close(); } public static class input { static BufferedReader reader; static StringTokenizer tokenizer; static void init(InputStream input) { reader = new BufferedReader(new InputStreamReader(input)); tokenizer = new StringTokenizer(""); } static String next() throws IOException { while (!tokenizer.hasMoreTokens()) tokenizer = new StringTokenizer(reader.readLine()); return tokenizer.nextToken(); } static int nextInt() throws IOException { return Integer.parseInt(next()); } static double nextDouble() throws IOException { return Double.parseDouble(next()); } static long nextLong() throws IOException { return Long.parseLong(next()); } } }
Java
["2 5 3"]
0.5 seconds
["38.546168065709"]
null
Java 7
standard input
[ "geometry", "math" ]
560bc97986a355d461bd462c4e1ea9db
The only line of the input contains three integers l3, l4, l5 (1 ≀ l3, l4, l5 ≀ 1000) β€” the edge lengths of triangular, quadrangular and pentagonal pyramids correspondingly.
1,700
Output one number β€” the total volume of the pyramids. Absolute or relative error should not be greater than 10 - 9.
standard output
PASSED
5d8dd77362d8d95f1595a17974726548
train_002.jsonl
1455807600
IT City administration has no rest because of the fame of the Pyramids in Egypt. There is a project of construction of pyramid complex near the city in the place called Emerald Walley. The distinction of the complex is that its pyramids will be not only quadrangular as in Egypt but also triangular and pentagonal. Of course the amount of the city budget funds for the construction depends on the pyramids' volume. Your task is to calculate the volume of the pilot project consisting of three pyramids β€” one triangular, one quadrangular and one pentagonal.The first pyramid has equilateral triangle as its base, and all 6 edges of the pyramid have equal length. The second pyramid has a square as its base and all 8 edges of the pyramid have equal length. The third pyramid has a regular pentagon as its base and all 10 edges of the pyramid have equal length.
64 megabytes
import java.util.*; public class q { public static void main(String[] args){ Scanner br = new Scanner(System.in); long l3= br.nextLong(); long l4 = br.nextLong(); long l5 = br.nextLong(); double ans = 0; //double h1 = Math.sqrt(l3*l3 - (.5*.5*l3*l3)); ans+=(Math.sqrt(2)*l3*l3*l3)/12.0; ans+=(l4*l4 * .5*Math.sqrt(2)*l4)/3.0; ans+=((5+Math.sqrt(5))*l5*l5*l5)/ 24.0; System.out.println(ans); } }
Java
["2 5 3"]
0.5 seconds
["38.546168065709"]
null
Java 7
standard input
[ "geometry", "math" ]
560bc97986a355d461bd462c4e1ea9db
The only line of the input contains three integers l3, l4, l5 (1 ≀ l3, l4, l5 ≀ 1000) β€” the edge lengths of triangular, quadrangular and pentagonal pyramids correspondingly.
1,700
Output one number β€” the total volume of the pyramids. Absolute or relative error should not be greater than 10 - 9.
standard output
PASSED
dee06181dc070e46bdaa01eb58e3c10e
train_002.jsonl
1455807600
IT City administration has no rest because of the fame of the Pyramids in Egypt. There is a project of construction of pyramid complex near the city in the place called Emerald Walley. The distinction of the complex is that its pyramids will be not only quadrangular as in Egypt but also triangular and pentagonal. Of course the amount of the city budget funds for the construction depends on the pyramids' volume. Your task is to calculate the volume of the pilot project consisting of three pyramids β€” one triangular, one quadrangular and one pentagonal.The first pyramid has equilateral triangle as its base, and all 6 edges of the pyramid have equal length. The second pyramid has a square as its base and all 8 edges of the pyramid have equal length. The third pyramid has a regular pentagon as its base and all 10 edges of the pyramid have equal length.
64 megabytes
import java.io.IOException; import java.util.*; public class Pyramids { public static void main(String[] args) { FasterScanner sc = new FasterScanner(); int l1[] = sc.nextIntArray(3); double[] l2 = new double[l1.length]; for(int i = 0; i < l1.length; i++) { l2[i] = l1[i]; } double triangle = Math.pow(l2[0],3.0)/(6.0*Math.sqrt(2.0)); double square = (Math.sqrt(2.0)*Math.pow(l2[1],3.0))/(6.0); double pentagon = ((5.0 + Math.sqrt(5.0))*Math.pow(l2[2],3.0))/(24.0); double total = triangle + square + pentagon; System.out.println(total); } public static class FasterScanner { private byte[] buf = new byte[1024]; private int curChar; private int numChars; public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = System.in.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 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
["2 5 3"]
0.5 seconds
["38.546168065709"]
null
Java 7
standard input
[ "geometry", "math" ]
560bc97986a355d461bd462c4e1ea9db
The only line of the input contains three integers l3, l4, l5 (1 ≀ l3, l4, l5 ≀ 1000) β€” the edge lengths of triangular, quadrangular and pentagonal pyramids correspondingly.
1,700
Output one number β€” the total volume of the pyramids. Absolute or relative error should not be greater than 10 - 9.
standard output
PASSED
b2a16362502bc5d34b3e06c86e36e5f6
train_002.jsonl
1455807600
IT City administration has no rest because of the fame of the Pyramids in Egypt. There is a project of construction of pyramid complex near the city in the place called Emerald Walley. The distinction of the complex is that its pyramids will be not only quadrangular as in Egypt but also triangular and pentagonal. Of course the amount of the city budget funds for the construction depends on the pyramids' volume. Your task is to calculate the volume of the pilot project consisting of three pyramids β€” one triangular, one quadrangular and one pentagonal.The first pyramid has equilateral triangle as its base, and all 6 edges of the pyramid have equal length. The second pyramid has a square as its base and all 8 edges of the pyramid have equal length. The third pyramid has a regular pentagon as its base and all 10 edges of the pyramid have equal length.
64 megabytes
import java.io.*; import java.util.*; import java.math.*; public class BlitzQ { public static void main(String[] args) { Scanner in = new Scanner(System.in); double vol1 = volOfPyramid(in.nextInt(), 3); double vol2 = volOfPyramid(in.nextInt(), 4); double vol3 = volOfPyramid(in.nextInt(), 5); System.out.println(vol1+vol2+vol3); } public static double volOfPyramid(int length, int baseEdges){ if(length<=0 || baseEdges<3) return 0; //start by calculating the distance from a corner to the center of the shape //*-----. //|* | //| * | //| * | //| | //| | //.-----. //so an isosolese triangle is formed with 2 sides of length x, the angle between them 2pi/baseEdges and a base of length 'length' //so... // * <- angle pi/baseEdges // ** // x *** // **** // ***** // length/2 //so ... sin(pi/baseEdges) = length/(2x) // x = length/(2*sin(pi/baseEdges)) double x = length/(2*Math.sin(Math.PI/baseEdges)); //looking along the line calculated you get a triangle // * // ** // l *** h // **** // ***** // x //so we can calculate the height since we know h^2 + x^2 = l^2 // h = sqrt(l^2 - x^2) double h = Math.sqrt((length*length) - (x*x)); //calculate the base area //Area of regular polygon given side length A = (s^2 * n)/(4 * tan(pi/n)) double base = (length*length*baseEdges)/(4*Math.tan(Math.PI/baseEdges)); return (1.0/3)*base*h; } }
Java
["2 5 3"]
0.5 seconds
["38.546168065709"]
null
Java 7
standard input
[ "geometry", "math" ]
560bc97986a355d461bd462c4e1ea9db
The only line of the input contains three integers l3, l4, l5 (1 ≀ l3, l4, l5 ≀ 1000) β€” the edge lengths of triangular, quadrangular and pentagonal pyramids correspondingly.
1,700
Output one number β€” the total volume of the pyramids. Absolute or relative error should not be greater than 10 - 9.
standard output
PASSED
f098f6e8960c445c1578b63f19000dd8
train_002.jsonl
1455807600
IT City administration has no rest because of the fame of the Pyramids in Egypt. There is a project of construction of pyramid complex near the city in the place called Emerald Walley. The distinction of the complex is that its pyramids will be not only quadrangular as in Egypt but also triangular and pentagonal. Of course the amount of the city budget funds for the construction depends on the pyramids' volume. Your task is to calculate the volume of the pilot project consisting of three pyramids β€” one triangular, one quadrangular and one pentagonal.The first pyramid has equilateral triangle as its base, and all 6 edges of the pyramid have equal length. The second pyramid has a square as its base and all 8 edges of the pyramid have equal length. The third pyramid has a regular pentagon as its base and all 10 edges of the pyramid have equal length.
64 megabytes
import java.io.InputStreamReader; import java.io.IOException; import java.util.InputMismatchException; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; QuickScanner in = new QuickScanner(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskQ solver = new TaskQ(); solver.solve(1, in, out); out.close(); } } class TaskQ { public void solve(int testNumber, QuickScanner in, PrintWriter out) { double res=0; for(int i=3;i<=5;i++) { double l=in.nextDouble(); l=l*l*l; res+=l*solve(i); } out.printf("%.10f\n",res); } double solve(int n) { double h1=1/2.0/Math.tan(Math.PI/n); double h2=Math.sqrt(3)/2.0; double h=Math.sqrt(h2*h2-h1*h1); double S=h1/2.0; return n/3.0*S*h; } } class QuickScanner { BufferedReader in; StringTokenizer token; String delim; public QuickScanner(InputStream inputStream) { this.in=new BufferedReader(new InputStreamReader(inputStream)); this.delim=" \n\t"; this.token=new StringTokenizer("",delim); } public boolean hasNext() { while(!token.hasMoreTokens()) { try { String s=in.readLine(); if(s==null) return false; token=new StringTokenizer(s,delim); } catch (IOException e) { throw new InputMismatchException(); } } return true; } public String next() { hasNext(); return token.nextToken(); } public double nextDouble() { return Double.parseDouble(next()); } }
Java
["2 5 3"]
0.5 seconds
["38.546168065709"]
null
Java 7
standard input
[ "geometry", "math" ]
560bc97986a355d461bd462c4e1ea9db
The only line of the input contains three integers l3, l4, l5 (1 ≀ l3, l4, l5 ≀ 1000) β€” the edge lengths of triangular, quadrangular and pentagonal pyramids correspondingly.
1,700
Output one number β€” the total volume of the pyramids. Absolute or relative error should not be greater than 10 - 9.
standard output
PASSED
b9d0e12807823218cfc87db80b59d825
train_002.jsonl
1455807600
IT City administration has no rest because of the fame of the Pyramids in Egypt. There is a project of construction of pyramid complex near the city in the place called Emerald Walley. The distinction of the complex is that its pyramids will be not only quadrangular as in Egypt but also triangular and pentagonal. Of course the amount of the city budget funds for the construction depends on the pyramids' volume. Your task is to calculate the volume of the pilot project consisting of three pyramids β€” one triangular, one quadrangular and one pentagonal.The first pyramid has equilateral triangle as its base, and all 6 edges of the pyramid have equal length. The second pyramid has a square as its base and all 8 edges of the pyramid have equal length. The third pyramid has a regular pentagon as its base and all 10 edges of the pyramid have equal length.
64 megabytes
import java.awt.geom.AffineTransform; import java.awt.geom.Point2D; import java.io.*; import java.util.*; public class EECQ { private static StringTokenizer st; public static void nextLine(BufferedReader br) throws IOException { st = new StringTokenizer(br.readLine()); } public static int nextInt() { return Integer.parseInt(st.nextToken()); } public static String next() { return st.nextToken(); } public static long nextLong() { return Long.parseLong(st.nextToken()); } public static double nextDouble() { return Double.parseDouble(st.nextToken()); } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); nextLine(br); double l3 = nextDouble(); double l4 = nextDouble(); double l5 = nextDouble(); double ans1 = Math.sqrt(2) / 12 * Math.pow(l3, 3); double base2 = Math.sqrt(2) / 2 * l4; double h2 = Math.sqrt(l4 * l4 - base2 * base2); double ans2 = l4 * l4 * h2 / 3; double base3 = 0.25 * Math.sqrt(5 * (5 + 2 * Math.sqrt(5))) * l5 * l5; double hyp3 = (l5 / 2) / Math.sin(Math.toRadians(36)); double h3 = Math.sqrt(l5 * l5 - hyp3 * hyp3); double ans3 = base3 * h3 / 3; System.out.printf("%.9f\n", ans1 + ans2 + ans3); } }
Java
["2 5 3"]
0.5 seconds
["38.546168065709"]
null
Java 7
standard input
[ "geometry", "math" ]
560bc97986a355d461bd462c4e1ea9db
The only line of the input contains three integers l3, l4, l5 (1 ≀ l3, l4, l5 ≀ 1000) β€” the edge lengths of triangular, quadrangular and pentagonal pyramids correspondingly.
1,700
Output one number β€” the total volume of the pyramids. Absolute or relative error should not be greater than 10 - 9.
standard output
PASSED
84c3b3a8690a7c0baec47eb2c36d8de8
train_002.jsonl
1379172600
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own. Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String [] a = new String [n]; for (int i =0; i<n; i++) { a[i] = sc.next(); } int blocks = 1; for (int i=1; i<n; i++) { if( a[i-1].charAt(1) == (a[i].charAt(0)) ) { blocks++; } } System.out.println(blocks); } }
Java
["6\n10\n10\n10\n01\n10\n10", "4\n01\n01\n10\n10"]
1 second
["3", "2"]
NoteThe first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.The second testcase has two groups, each consisting of two magnets.
Java 11
standard input
[ "implementation" ]
6c52df7ea24671102e4c0eee19dc6bba
The first line of the input contains an integer n (1 ≀ n ≀ 100000) β€” the number of magnets. Then n lines follow. The i-th line (1 ≀ i ≀ n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
800
On the single line of the output print the number of groups of magnets.
standard output
PASSED
680c1ce2b4146e5b238aa805625b816a
train_002.jsonl
1379172600
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own. Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
256 megabytes
import java.util.Scanner; public class Magnets { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(); int counter = 1; int oldG = 0; for (int i = 0; i < n; i++) { int g = input.nextInt(); if (i != 0){ if (oldG == 01 && g == 10){ counter ++; } if (oldG == 10 && g == 01){ counter ++; } } oldG = g; } System.out.println(counter); } }
Java
["6\n10\n10\n10\n01\n10\n10", "4\n01\n01\n10\n10"]
1 second
["3", "2"]
NoteThe first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.The second testcase has two groups, each consisting of two magnets.
Java 11
standard input
[ "implementation" ]
6c52df7ea24671102e4c0eee19dc6bba
The first line of the input contains an integer n (1 ≀ n ≀ 100000) β€” the number of magnets. Then n lines follow. The i-th line (1 ≀ i ≀ n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
800
On the single line of the output print the number of groups of magnets.
standard output
PASSED
a517eff28b8721961e525c075909d800
train_002.jsonl
1379172600
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own. Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
256 megabytes
import java.util.Scanner; public class Magnets { public static void main(String args[]){ int n,t,d=1; Scanner sc = new Scanner(System.in); n = sc.nextInt(); int a[]=new int[n]; for(int i=0;i<n;i++) { t = sc.nextInt(); a[i]=t; if(i>0 && a[i]!=a[i-1]) d++; } System.out.println(d); } }
Java
["6\n10\n10\n10\n01\n10\n10", "4\n01\n01\n10\n10"]
1 second
["3", "2"]
NoteThe first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.The second testcase has two groups, each consisting of two magnets.
Java 11
standard input
[ "implementation" ]
6c52df7ea24671102e4c0eee19dc6bba
The first line of the input contains an integer n (1 ≀ n ≀ 100000) β€” the number of magnets. Then n lines follow. The i-th line (1 ≀ i ≀ n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
800
On the single line of the output print the number of groups of magnets.
standard output
PASSED
76d7c7787b1f749e76a2bfe2566a0ac0
train_002.jsonl
1379172600
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own. Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n=scan.nextInt(); if(n==1){ System.out.println(1); System.exit(0); } int d=1; int present=0; int previous=0; for(int i=0;i<n;i++){ int v =scan.nextInt(); if(i==0) previous=v; else{ present=v; if((previous==1&&present==10)||(previous==10 && present==1)){ d++; previous=present; } } } System.out.println(d); } }
Java
["6\n10\n10\n10\n01\n10\n10", "4\n01\n01\n10\n10"]
1 second
["3", "2"]
NoteThe first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.The second testcase has two groups, each consisting of two magnets.
Java 11
standard input
[ "implementation" ]
6c52df7ea24671102e4c0eee19dc6bba
The first line of the input contains an integer n (1 ≀ n ≀ 100000) β€” the number of magnets. Then n lines follow. The i-th line (1 ≀ i ≀ n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
800
On the single line of the output print the number of groups of magnets.
standard output
PASSED
31840d6ee69dca9297776f8706019898
train_002.jsonl
1379172600
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own. Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
256 megabytes
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t= scan.nextInt(); int temp=0,count=0; for(int i=0;i<t;i++){ int n = scan.nextInt(); if(n!=temp) count++; temp=n; } System.out.println(count); } }
Java
["6\n10\n10\n10\n01\n10\n10", "4\n01\n01\n10\n10"]
1 second
["3", "2"]
NoteThe first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.The second testcase has two groups, each consisting of two magnets.
Java 11
standard input
[ "implementation" ]
6c52df7ea24671102e4c0eee19dc6bba
The first line of the input contains an integer n (1 ≀ n ≀ 100000) β€” the number of magnets. Then n lines follow. The i-th line (1 ≀ i ≀ n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
800
On the single line of the output print the number of groups of magnets.
standard output
PASSED
6416988c4aba9bfe2ee5a4ea40d59004
train_002.jsonl
1379172600
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own. Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
256 megabytes
import java.io.*; import java.util.*; import java.lang.*; public class VF{ public static void main(String args[]){ try{ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); char c[]=new char[n]; for(int i=0;i<n;i++) c[i]=sc.next().charAt(0); int count=1; if(n!=1) { for(int i=0;i<n-1;i++) { if(c[i]!=c[i+1]) count++; } } System.out.println(count); } catch(Exception e){} } }
Java
["6\n10\n10\n10\n01\n10\n10", "4\n01\n01\n10\n10"]
1 second
["3", "2"]
NoteThe first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.The second testcase has two groups, each consisting of two magnets.
Java 11
standard input
[ "implementation" ]
6c52df7ea24671102e4c0eee19dc6bba
The first line of the input contains an integer n (1 ≀ n ≀ 100000) β€” the number of magnets. Then n lines follow. The i-th line (1 ≀ i ≀ n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
800
On the single line of the output print the number of groups of magnets.
standard output
PASSED
47ae4815a9b612f93574f67401cfd0c5
train_002.jsonl
1379172600
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own. Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n=0,result=0,max=0; n=sc.nextInt(); int count=0; int[] team=new int[n]; for(int i=0;i<n;i++) { team[i]=sc.nextInt(); } String temp=""; for(int i=0;i<n-1;i++) { if(Math.abs(team[i]-team[i+1])==9) { count++; } if(count>max) { max=count; } } System.out.print(max+1); } }
Java
["6\n10\n10\n10\n01\n10\n10", "4\n01\n01\n10\n10"]
1 second
["3", "2"]
NoteThe first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.The second testcase has two groups, each consisting of two magnets.
Java 11
standard input
[ "implementation" ]
6c52df7ea24671102e4c0eee19dc6bba
The first line of the input contains an integer n (1 ≀ n ≀ 100000) β€” the number of magnets. Then n lines follow. The i-th line (1 ≀ i ≀ n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
800
On the single line of the output print the number of groups of magnets.
standard output
PASSED
824dd446efb446015532bd17cd9792de
train_002.jsonl
1379172600
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own. Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
256 megabytes
import java.util.*; public class temp { public static void main(String[] args) { Scanner sc= new Scanner(System.in); int len = sc.nextInt(); int[] data = new int[len]; for(int i=0; i<len; i++) data[i] = sc.nextInt(); int count =1; for(int i=0; i<len-1; i++) { if(data[i] != data[i+1]) count++; } System.out.println(count); } }
Java
["6\n10\n10\n10\n01\n10\n10", "4\n01\n01\n10\n10"]
1 second
["3", "2"]
NoteThe first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.The second testcase has two groups, each consisting of two magnets.
Java 11
standard input
[ "implementation" ]
6c52df7ea24671102e4c0eee19dc6bba
The first line of the input contains an integer n (1 ≀ n ≀ 100000) β€” the number of magnets. Then n lines follow. The i-th line (1 ≀ i ≀ n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
800
On the single line of the output print the number of groups of magnets.
standard output
PASSED
27e8a6b7597b7090235b01af3c551122
train_002.jsonl
1379172600
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own. Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
256 megabytes
import java .util.Scanner ; import java.util.*; public class cf2{ public static void main(String[] args ){ Scanner s =new Scanner (System.in); int n =s.nextInt(); int[] arr =new int[n]; for(int i =0; i<n; i++){ arr[i]=s.nextInt(); } int max =1; int count=1; for(int j=1; j<n; j++){ if(arr[j]!=arr[j-1]){ count++; if(max<count){ max=count; } } /*else { count=1; }*/ } System.out.println(max); } }
Java
["6\n10\n10\n10\n01\n10\n10", "4\n01\n01\n10\n10"]
1 second
["3", "2"]
NoteThe first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.The second testcase has two groups, each consisting of two magnets.
Java 11
standard input
[ "implementation" ]
6c52df7ea24671102e4c0eee19dc6bba
The first line of the input contains an integer n (1 ≀ n ≀ 100000) β€” the number of magnets. Then n lines follow. The i-th line (1 ≀ i ≀ n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
800
On the single line of the output print the number of groups of magnets.
standard output
PASSED
1cac1bf16b282b37654cabceaafa4014
train_002.jsonl
1379172600
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other.Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own. Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed.
256 megabytes
import java.util.LinkedHashMap; import java.util.Scanner; public class Magnets { public static void main(String[] args) { Scanner scan = new Scanner(System.in); LinkedHashMap<String,Integer> map = new LinkedHashMap<String,Integer>(); int n = scan.nextInt(); int groups = 1; String[] magnets = new String[n]; for(int i = 0 ; i < n;i++) { magnets[i] = scan.next(); if( i > 0 && magnets[i].charAt(0) == magnets[i-1].charAt(1)) groups++; //If the first letter is 0 and previous entry has 1 before then its a new group } System.out.println(groups); } }
Java
["6\n10\n10\n10\n01\n10\n10", "4\n01\n01\n10\n10"]
1 second
["3", "2"]
NoteThe first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets.The second testcase has two groups, each consisting of two magnets.
Java 11
standard input
[ "implementation" ]
6c52df7ea24671102e4c0eee19dc6bba
The first line of the input contains an integer n (1 ≀ n ≀ 100000) β€” the number of magnets. Then n lines follow. The i-th line (1 ≀ i ≀ n) contains either characters "01", if Mike put the i-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position.
800
On the single line of the output print the number of groups of magnets.
standard output