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
5c2b6d0601ec10d0e3ed1381b6d724b2
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.util.Scanner; public class Cf232 { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); int k = s.nextInt(); int[] a = new int[2*n]; for(int i = 0; i < 2*n; i++){ a[i] = i + 1; } for(int i = 0; i < k; i++){ int buf = a[2*i]; a[2*i] = a[2*i+1]; a[2*i + 1] = buf; } for(int i = 0; i < 2*n; i++){ System.out.print(a[i] + " "); } } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
87e1943e49d1f7fc65dcb6ac3eaf911c
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.io.InputStreamReader; import java.io.IOException; import java.util.InputMismatchException; import java.io.PrintStream; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Reader; import java.io.Writer; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author Nipuna Samarasekara */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastScanner in = new FastScanner(inputStream); FastPrinter out = new FastPrinter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } } class TaskB { ///////////////////////////////////////////////////////////// public void solve(int testNumber, FastScanner in, FastPrinter out) { int n=in.nextInt(),k=in.nextInt(); int[] A=new int[2*n]; for (int i = 0; i < 2*n; i++) { A[i]=2*n-i; } for (int i = 0; i < k; i++) { //deb(A); int t=A[2*i]; A[2*i]=A[2*i+1]; A[2*i+1]=t; } out.printArray(A); } } class FastScanner extends BufferedReader { public FastScanner(InputStream is) { super(new InputStreamReader(is)); } public int read() { try { int ret = super.read(); // if (isEOF && ret < 0) { // throw new InputMismatchException(); // } // isEOF = ret == -1; return ret; } catch (IOException e) { throw new InputMismatchException(); } } static boolean isWhiteSpace(int c) { return c >= 0 && c <= 32; } public int nextInt() { int c = read(); while (isWhiteSpace(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int ret = 0; while (c >= 0 && !isWhiteSpace(c)) { if (c < '0' || c > '9') { throw new NumberFormatException("digit expected " + (char) c + " found"); } ret = ret * 10 + c - '0'; c = read(); } return ret * sgn; } public String readLine() { try { return super.readLine(); } catch (IOException e) { return null; } } } class FastPrinter extends PrintWriter { public FastPrinter(OutputStream out) { super(out); } public FastPrinter(Writer out) { super(out); } public void printArray(int[] a) { for (int i = 0; i < a.length; i++) { if (i > 0) { print(' '); } print(a[i]); } println(); } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
14c0f7707c7b94a5a47a696ddd1f7fbe
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.util.*; public class Main { public static void main(String[] args){ Scanner cin = new Scanner(System.in); int n = cin.nextInt(); int k = cin.nextInt(); boolean[] vis = new boolean[2*n+1]; if (k != 0){ System.out.print(k+1+" "+1); vis[k+1] = vis[1] = true; } for (int i = 1 ; i <= 2*n ; ++i){ if (!vis[i])System.out.print(" "+i); } System.out.println(); } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
da698e5ace50bc48d61e50e9ab3c2526
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.util.*; import java.io.*; import java.lang.*; import java.math.*; public class C { public static void main(String[] args) throws Exception { // BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); // StringTokenizer st = new StringTokenizer(bf.readLine()); Scanner scan = new Scanner(System.in); // PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); // int n = Integer.parseInt(bf.readLine()); // int n = Integer.parseInt(st.nextToken()); int n = scan.nextInt(); int k = scan.nextInt(); if(n == 1 && k == 0) System.out.println("1 2"); else if(k == 0) { for(int i=2*n; i>=1; i--) System.out.print(i + " "); } else { System.out.print("1 " + (1+k) + " "); for(int i=2; i<=k; i++) System.out.print((i+k) + " " + i + " "); for(int i=2*n; i>=2*k+1; i--) { System.out.print(i + " "); } } // out.close(); System.exit(0); } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
e2e112b29de2d448f6b8a097dbcb4077
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; /* * 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 Ivan */ public class secondProblem { /** * @param args the command line arguments */ public static void main(String[] args) throws IOException { FastReader sc=new FastReader(System.in); int n=sc.nextInt(); int k=sc.nextInt(); int[] arr=new int[2*n]; for(int i=0;i<2*n;i++) arr[i]=2*n-i; int toCancel=n-k; int i=0,temp; while(toCancel!=0){ temp=arr[i]; arr[i]=arr[i+1]; arr[i+1]=temp; toCancel--; i+=2; } for(int ctr=0;ctr<2*n;ctr++) System.out.print(arr[ctr]+" "); } } class FastReader { public BufferedReader reader; public StringTokenizer tokenizer; public FastReader(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() throws IOException{ return Integer.parseInt(next()); } public long nextL() throws IOException{ return Long.parseLong(next()); } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
3c00c4371614f0489bf2c37d098965e1
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class B { static StringTokenizer st; static BufferedReader br; static PrintWriter pw; public static void main(String[] args) throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int n = nextInt(); int k = nextInt(); int[]a = new int[2*n+1]; for (int i = 2; i <= 2*k; i += 2) { a[i-1] = i-1; a[i] = i; } for (int i = 2*k+2; i <= 2*n; i += 2) { a[i-1] = i; a[i] = i-1; } for (int i = 1; i <= 2*n; i++) { pw.print(a[i]+" "); } pw.println(); pw.close(); } private static int nextInt() throws IOException { return Integer.parseInt(next()); } private static long nextLong() throws IOException { return Long.parseLong(next()); } private static double nextDouble() throws IOException { return Double.parseDouble(next()); } private static String next() throws IOException { while (st==null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
34457234a700a2eb0898757e85027eec
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
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(); int k = sc.nextInt(); for(int i = 1; i <= n; i++){ if(k > 0){ System.out.print(2*i + " " + (2*i-1)); k--; } else{ System.out.print((2*i-1) + " " + 2*i); } if(i != n){ System.out.print(" "); } } } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
a85c77d980bab225e7c44bbb8147dcac
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.io.InputStreamReader; import java.io.IOException; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } } class TaskB { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int k = 2*in.nextInt(); int mg = 1; int dk = k; while (k > 0){ out.print((mg + 1)+" "+mg); k -= 2; out.print(" "); mg += 2; } for (int i = dk; i < 2*n; i++) { out.print(mg+++" "); } } } class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
ba8fa59637ef6b307b5b6b43429ba9c5
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.util.*; import java.io.*; public class Main implements Runnable { public void solve() throws IOException { int N = nextInt(); int K = nextInt(); int[] a = new int[2 * N]; for(int i = 0; i < 2 * N; i++) a[i] = i + 1; for(int i = 0; i < K; i++){ int t = a[2 * i]; a[2 * i] = a[2 * i + 1]; a[2 * i + 1] = t; } for(int i = 0; i < a.length; i++) System.out.print(a[i] + " "); System.out.println(); } //----------------------------------------------------------- public static void main(String[] args) { new Main().run(); } public void run() { try { in = new BufferedReader(new InputStreamReader(System.in)); tok = null; solve(); in.close(); } catch (IOException e) { System.exit(0); } } public String nextToken() throws IOException { while (tok == null || !tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); } return tok.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(nextToken()); } public long nextLong() throws IOException { return Long.parseLong(nextToken()); } public double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } BufferedReader in; StringTokenizer tok; }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
bd17165b4a60fcd6cb85a04de4244e8b
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.StringTokenizer; public class _359B { public static void main(String[] args) throws Exception { Reader.init(System.in); BufferedWriter cout = new BufferedWriter(new OutputStreamWriter(System.out)); int n = Reader.nextInt(); int k = Reader.nextInt(); int[] a = new int[2 * n + 1]; for (int i=1; i<a.length; i++) a[i] = i; for (int i=1; i<=k; i++) ArrayUtil.swap(a, 2 * i - 1, 2 * i); for (int i=1; i<a.length; i++) cout.write(String.format("%d ", a[i])); cout.close(); } static class Pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<Pair<U, V>> { final U _1; final V _2; private Pair(U key, V val) { this._1 = key; this._2 = val; } public static <U extends Comparable<U>, V extends Comparable<V>> Pair<U, V> instanceOf(U _1, V _2) { return new Pair<U, V>(_1, _2); } @Override public String toString() { return _1 + " " + _2; } @Override public int hashCode() { int res = 17; res = res * 31 + _1.hashCode(); res = res * 31 + _2.hashCode(); return res; } @Override public int compareTo(Pair<U, V> that) { int res = this._1.compareTo(that._1); if (res < 0 || res > 0) return res; else return this._2.compareTo(that._2); } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!(obj instanceof Pair)) return false; Pair<?, ?> that = (Pair<?, ?>) obj; return _1.equals(that._1) && _2.equals(that._2); } } /** Class for buffered reading int and double values */ static class Reader { static BufferedReader reader; static StringTokenizer tokenizer; /** call this method to initialize reader for InputStream */ static void init(InputStream input) { reader = new BufferedReader(new InputStreamReader(input)); tokenizer = new StringTokenizer(""); } /** get next word */ static String next() throws IOException { while (!tokenizer.hasMoreTokens()) { // TODO add check for eof if necessary tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } static int nextInt() throws IOException { return Integer.parseInt(next()); } static double nextDouble() throws IOException { return Double.parseDouble(next()); } } static class ArrayUtil { static void swap(int[] a, int i, int j) { int tmp = a[i]; a[i] = a[j]; a[j] = tmp; } static void swap(long[] a, int i, int j) { long tmp = a[i]; a[i] = a[j]; a[j] = tmp; } static void swap(double[] a, int i, int j) { double tmp = a[i]; a[i] = a[j]; a[j] = tmp; } static void swap(char[] a, int i, int j) { char tmp = a[i]; a[i] = a[j]; a[j] = tmp; } static void swap(boolean[] a, int i, int j) { boolean tmp = a[i]; a[i] = a[j]; a[j] = tmp; } static void reverse(int[] a, int i, int j) { for (; i < j; i++, j--) swap(a, i, j); } static void reverse(long[] a, int i, int j) { for (; i < j; i++, j--) swap(a, i, j); } static void reverse(double[] a, int i, int j) { for (; i < j; i++, j--) swap(a, i, j); } static void reverse(char[] a, int i, int j) { for (; i < j; i++, j--) swap(a, i, j); } static void reverse(boolean[] a, int i, int j) { for (; i < j; i++, j--) swap(a, i, j); } static long sum(int[] a) { int sum = 0; for (int i : a) sum += i; return sum; } static long sum(long[] a) { long sum = 0; for (long i : a) sum += i; return sum; } static double sum(double[] a) { double sum = 0; for (double i : a) sum += i; return sum; } static int max(int[] a) { int max = Integer.MIN_VALUE; for (int i : a) if (i > max) max = i; return max; } static int min(int[] a) { int min = Integer.MAX_VALUE; for (int i : a) if (i < min) min = i; return min; } static long max(long[] a) { long max = Long.MIN_VALUE; for (long i : a) if (i > max) max = i; return max; } static long min(long[] a) { long min = Long.MAX_VALUE; for (long i : a) if (i < min) min = i; return min; } } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
cbedb4b78c9ee91941d8128768bc899f
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.io.*; import java.util.*; public class Permut{ public static void main(String[] args) throws IOException{ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); k = n-k; for (int i=1; i<n+1; i++) { if (k > 0) { System.out.print(2*i+" "); System.out.print(2*i-1+" "); } else{ System.out.print(2*i-1+" "); System.out.print(2*i+" "); } k--; } } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
c9e0194540a6131945721b29262cd18e
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; public class Task359B { 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++]); } String next() throws IOException { if (cacheIndex >= cache.length) { cache = br.readLine().split(" "); cacheIndex = 0; } return cache[cacheIndex++]; } 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(); int k = sc.nextInt(); for (int i = 0; i < n - k; i++) { pw.print(2 * i + 1); pw.print(" "); pw.print(2 * i + 2); pw.print(" "); } for (int i = n - k; i < n; i++) { pw.print(2 * i + 2); pw.print(" "); pw.print(2 * i + 1); pw.print(" "); } pw.flush(); sc.close(); } } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
2c745c975271de99d1db2d663790d52a
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.util.Scanner; public class Permutation { /** * @param args */ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); int[]ans=new int[2*n+1]; for(int i=1;i<=2*n;i+=2){ if(k>0){ ans[i]=i+1; ans[i+1]=i; k--; } else { ans[i]=i; ans[i+1]=i+1; } } for(int i=1;i<ans.length;i++){ System.out.print(ans[i]+" "); } } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
de6901d58c166191196e318d375028d8
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.util.*; import java.io.*; import java.lang.reflect.Array; import java.math.*; 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); int t = 1; Task solver = new Task(); while ((t --) > 0) solver.solve(in, out); out.close(); } } class Task{ void solve (InputReader cin , PrintWriter cout) { int n = cin.nextInt() , k = cin.nextInt (); for (int i = 0 ; i < n ; i ++) { if (i >= k) cout.print((2 * i + 1) + " " + (2 * i + 2)); else cout.print((2 * i + 2) + " " + (2 * i + 1)); cout.print(" "); } } } class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public BigInteger nextBigInteger() { return new BigInteger(next()); } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
030f337f8cb6355006eaa74a9bef8c53
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int k = in.nextInt(); int arr[] = new int[2 * n]; for (int i = 0; i < arr.length; i++) { arr[i] = i + 1; } for (int i = 1; i <= k; i++) { int temp = arr[2 * i - 2]; arr[2 * i - 2] = arr[2 * i - 1]; arr[2 * i - 1] = temp; } for (int i = 0; i < arr.length; i++) { System.out.print(arr[i] + " "); } } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
5a4e446c1e2b1b700150332679c55b06
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import static java.lang.Math.*; import static java.lang.System.currentTimeMillis; import static java.lang.System.exit; import static java.lang.System.arraycopy; import static java.util.Arrays.sort; import static java.util.Arrays.binarySearch; import static java.util.Arrays.fill; import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws IOException { try { if (new File("input.txt").exists()) System.setIn(new FileInputStream("input.txt")); } catch (SecurityException e) { } new Main().run(); } BufferedReader in; PrintWriter out; StringTokenizer st = new StringTokenizer(""); private void run() throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); in.close(); out.close(); } final int MAXN = 100001; int[] a = new int[MAXN]; private void solve() throws IOException { int n = nextInt() * 2, k = nextInt(); for(int i = 1; i <= n; i++) a[i] = i; for(int i = 1; i <= k; i++){ int t = a[2*i]; a[2*i] = a[2*i-1]; a[2*i-1] = t; } for(int i = 1; i <= n; i++){ if(i == 1) out.print(a[i]); else out.println(" "+a[i]); } } void chk(boolean b) { if (b) return; System.out.println(new Error().getStackTrace()[1]); exit(999); } void deb(String fmt, Object... args) { System.out.printf(Locale.US, fmt + "%n", args); } String nextToken() throws IOException { while (!st.hasMoreTokens()) st = new StringTokenizer(in.readLine()); return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } String nextLine() throws IOException { st = new StringTokenizer(""); return in.readLine(); } boolean EOF() throws IOException { while (!st.hasMoreTokens()) { String s = in.readLine(); if (s == null) return true; st = new StringTokenizer(s); } return false; } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
2f805f5a541418d963176274dc8e7a59
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { /** * @param args */ public static void main(String[] args)throws IOException { BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(buf.readLine()); int n = Integer.parseInt(st.nextToken()); int k= Integer.parseInt(st.nextToken()); int j = n - 2 * k; int b = (n - j)/2; int a = (j + n)/2; int i = 1; for( int l = 1; l <= a; l ++){ System.out.print((i + 1)+" "+ (i)+" "); i += 2; } for(int l = 1; l <= b; l++){ System.out.print((i)+" "+ (i + 1)+" "); i+=2; } System.out.println(); } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
898fa8c996c737a4064910b1d9d162de
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.PrintWriter; import java.util.InputMismatchException; 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); PrintWriter out = new PrintWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } } class TaskB { public void solve(int testNumber, InputReader in, PrintWriter out) { int N=in.readInt(); int K=in.readInt(); for (int i=1;i<=N;i++){ if(i<=K) out.print(2*i+" "+(2*i-1)+" "); else out.print(2*i-1+" "+(2*i)+" "); } } } 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); } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
099d2183d5e223a7a8dfadd77be6df3f
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.util.Scanner; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author KHALED */ public class Permutation { public static void main(String[] args) { Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int k=scan.nextInt(); for (int i = 2*n; i > 0; i-=2) { if(i!=2*n) System.out.print(" "); if(k>0) System.out.print((i-1)+" "+i); else System.out.print(i+" "+(i-1)); k--; } } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
79fea2123a50c74d7fabb792860baa41
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.io.IOException; import java.io.OutputStreamWriter; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.OutputStream; import java.io.PrintWriter; import java.util.NoSuchElementException; import java.io.Writer; import java.math.BigInteger; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author Nguyen Trung Hieu - vuondenthanhcong11@gmail.com */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskB solver = new TaskB(); solver.solve(1, in, out); out.close(); } } class TaskB { public void solve(int testNumber, InputReader in, OutputWriter out) { int count = in.readInt() * 2; int k = in.readInt(); boolean[] visited = new boolean[count + 1]; if (k > 0) { out.print((count - k) + " " + (count)); visited[count - k] = visited[count] = true; } int left = 1; int right = count; while (left < right) { while (left < right && visited[right]) right--; if (left >= right) break; out.print(" " + right); while (left < right && visited[left]) left++; if (left >= right) break; out.print(" " + left); visited[left] = visited[right] = true; } } } class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object...objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void close() { writer.close(); } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
cd197dcbe9afe9f0a6d1e3799fdb3993
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.io.*; import java.math.BigInteger; import java.util.*; import static java.lang.Math.*; public class solver implements Runnable { final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null; BufferedReader in; PrintWriter out; StringTokenizer tok = new StringTokenizer(""); void init() throws FileNotFoundException{ if (ONLINE_JUDGE){ in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); }else{ in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); } } String readString() throws IOException{ while(!tok.hasMoreTokens()){ try{ tok = new StringTokenizer(in.readLine()); }catch (Exception e){ return null; } } return tok.nextToken(); } String readString(String delim) throws IOException{ while(!tok.hasMoreTokens()){ try{ tok = new StringTokenizer(in.readLine()); }catch (Exception e){ return null; } } return tok.nextToken(delim); } int readInt() throws IOException{ return Integer.parseInt(readString()); } int readInt(String delim) throws IOException{ return Integer.parseInt(readString(delim)); } long readLong() throws IOException{ return Long.parseLong(readString()); } long readLong(String delim) throws IOException{ return Long.parseLong(readString(delim)); } double readDouble() throws IOException{ return Double.parseDouble(readString()); } double readDouble(String delim) throws IOException{ return Double.parseDouble(readString(delim)); } char readChar() throws IOException { char val = 0; do{ val = (char) in.read(); }while(val == '\n' || val == '\r'); return val; } public class Pair<T1,T2> { public T1 x1; public T2 x2; public Pair(){}; public Pair(T1 x1, T2 x2){ this.x1 = x1; this.x2 = x2; } } public class Point extends Pair<Integer, Integer>{ } //---------------------------------------- boolean[][] arr; public void solve() throws IOException { int n =readInt(), k = readInt(); for (int i = 1; i <= k; i++){ out.print(2*i + " "+ (2*i-1) + " "); } for (int i = k+1; i<=n;i++){ out.print((2*i-1) + " " + 2*i + " "); } } //---------------------------------------- public static void main(String[] args){ new Thread(null, new solver(), "", 256 * (1L << 20)).start(); } long timeBegin, timeEnd; void time(){ timeEnd = System.currentTimeMillis(); System.err.println("Time = " + (timeEnd - timeBegin)); } public void run(){ try{ timeBegin = System.currentTimeMillis(); init(); solve(); out.close(); time(); }catch (Exception e){ e.printStackTrace(System.err); System.exit(-1); } } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
cec596bff5ac3421773d5ee424fea23a
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.util.Scanner; public class B { public static void main(String args[]) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int k = in.nextInt(); int ans[] = new int [n*2]; for(int i = 0; i < (n<<1); i++) ans[i] = i+1; for(int i = 0; i < k; i++) { int tmp = ans[i*2]; ans[i*2] = ans[i*2+1]; ans[i*2+1] = tmp; } System.out.print(ans[0]); for(int i = 1; i < n*2; i++) { System.out.print(" "); System.out.print(ans[i]); } return ; } public static long gcd(long a, long b) { if(a<0) return gcd(-a, b); if(b<0) return gcd(a, -b); return (b==0)?a:gcd(b,a%b); } public static long lcm(long a, long b) { if(a<0) return lcm(-a, b); if(b<0) return lcm(a, -b); return a*(b/gcd(a,b)); } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
62369d7dddd4cb663518242101518a3b
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.io.IOException; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.InputMismatchException; import java.util.Scanner; public class c209_1 { public static void main(String[] args) { FasterScanner s = new FasterScanner(); int n=s.nextInt(),c=0,c1=0; int k=s.nextInt(); for(int i=0;i<n;i++){ if(i<k){ System.out.print((2*i+2)+" "+(2*i+1)+" "); } else{ System.out.print((2*i+1)+" "+(2*i+2)+" "); } } } 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
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
691d15f29c006d252f67dc3e08f97157
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.io.*; import java.util.*; public class b1 { public static void main(String[] args) throws FileNotFoundException { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(); int k = in.nextInt(); for (int i = 0; i < k; i++) { out.print((2 * i + 2) + " " + (2 * i + 1) + " "); } for (int i = k; i < n; i++) { out.print((2 * i + 1) + " " + (2 * i + 2) + " "); } out.close(); } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
faf6fa91a8d8e74a0b21d5ee7cab1c75
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.io.*; import java.util.*; public class solver { BufferedReader in; PrintWriter out; StringTokenizer tok; final boolean OJ=System.getProperty("ONLINE_JUDGE")!=null; String readString() throws IOException{ while (tok==null || !tok.hasMoreTokens()){ tok=new StringTokenizer(in.readLine()); } return tok.nextToken(); } int readInt() throws NumberFormatException, IOException{ return Integer.parseInt(readString()); } void init() throws FileNotFoundException{ in = (OJ)?new BufferedReader(new InputStreamReader(System.in)):new BufferedReader(new FileReader("input.txt")); out = (OJ)?new PrintWriter(System.out):new PrintWriter("output.txt"); } void TaskA() throws NumberFormatException, IOException{ int n=readInt(); int m=readInt(); int[][] a=new int[n][m]; for (int i=0;i<n;i++){ for (int j=0;j<m;j++){ a[i][j]=readInt(); } } for (int i=0;i<m;i++){ if (a[0][i]==1 || a[n-1][i]==1){ System.out.println(2); return; } } for (int i=0;i<n;i++){ if (a[i][0]==1 || a[i][m-1]==1){ System.out.println(2); return; } } System.out.println(4); } void TaskB() throws NumberFormatException, IOException{ int n=readInt(); int k=readInt(); int j=1; for (int i=0;i<2*k;i++){ int m=j*2-1; int mm=j*2; if (i%2==0){ out.print(m+" "+mm+" "); }else{ out.print(mm+" "+m+" "); } j++; } for (int i=4*k;i<2*n;i++){ out.print((i+1)+" "); } } void solve() throws NumberFormatException, IOException{ TaskB(); out.flush(); } public void Run() throws NumberFormatException, IOException{ init(); solve(); out.close(); } public static void main(String[] args) throws NumberFormatException, IOException { new solver().Run(); } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
d23ecca8d0a7f240f3d25130de546600
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
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(); int k = sc.nextInt(); for (int i = 1; i <= 2*k; i += 2) { System.out.print((i + 1) + " " + (i)+" "); } for (int i = 2 * k + 1; i <= 2 * n; i += 2) { System.out.print((i) + " " + (i + 1)+" "); } } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
536c0948a30926e2392231574568ceb9
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.util.Scanner; public class permutation{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int twon = 2*n; int twok = 2*k; int[] a = new int[twon]; if( k == 0){ a[0] = 1; a[1] = 2; } else{ a[1] = 1; a[0] = 1 + k; } int i = 2; int j; if(a[0] == 2 || a[1] == 2) j = 3; else j = 2; while( i < twon){ a[i] = j; j++; if( j == a[0]) j++; i++; } for( i = 0; i < twon; i++) System.out.print(a[i] + " "); } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
f302c7d24323fbbc4c9e292a1fca809f
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.util.*; //Scanner; public class R209_Div2_B //Name: Permutation { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int[] a = new int[n * 2]; int num = 2; if (k == 0) { a[0] = 1; a[1] = 2; } else { a[0] = k + 1; a[1] = 1; } for (int i = 2; i < n * 2; i++) { if (num == a[0] || num == a[1]) num++; a[i] = num; num++; } StringBuilder sb = new StringBuilder(); sb.append(a[0]); for (int i = 1; i < n * 2; i++) sb.append(" " + a[i]); System.out.println(sb); sc.close(); } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
28eedbc73a38eba77e03336e117f8d90
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.util.Scanner; public class Main { public static void main(String arg0[]){ Scanner in=new Scanner(System.in); int n=in.nextInt(); int m=in.nextInt(); int k=m+n; int a[]=new int [2*n+2]; for (int i=1;i<=n;i++){ a[i*2-1]=i+n; a[2*i]=i; } if(m!=0){a[2*m-1]=2*n; a[2*n]=n+m; a[2*n-1]=n; } for (int i=1;i<=2*n;i++){ if (i!=1) System.out.print(" "); System.out.print(a[i]); } System.out.println(); } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
610cef704cae7da21013e609852be949
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.util.Scanner; public class study { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int k = scan.nextInt(); int[] table = new int[2 * n]; if(n%2 == 1){ int n1 = n-1; } else { int n1 = n; } int k1=0; for(k1=0;k1<k;k1++){ table[0 + 4 * k1] = 3 + 4 * k1; table[1 + 4 * k1] = 2 + 4 * k1; table[2 + 4 * k1] = 1 + 4 * k1; table[3 + 4 * k1] = 4 + 4 * k1; } for(int i=4+4*(k1-1);i<table.length;i++){ table[i] = i+1; } for(int i=0;i<table.length;i++){ System.out.print(table[i] +" "); } } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
9a7e471e7996135324a6eb9d22066881
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Collection; import java.util.Locale; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { new Thread(null, new Runnable() { public void run() { try { long prevTime = System.currentTimeMillis(); new Main().run(); System.err.println("Total time: " + (System.currentTimeMillis() - prevTime) + " ms"); System.err.println("Memory status: " + memoryStatus()); } catch (IOException e) { e.printStackTrace(); } } }, "1", 1L << 24).start(); } void run() throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); Object o = solve(); if (o != null) out.println(o); out.close(); in.close(); } private Object solve() throws IOException { int n = ni(); int k = ni(); int[] arr = new int[2*n]; for(int i =0;i<2*n;i++) arr[i]=i+1; for(int i =0;i<2*n && k>0;i+=2,k--) swap(arr,i,i+1); printArray(arr); return null; } private void swap(int[] arr, int i, int j) { int t = arr[i]; arr[i]=arr[j]; arr[j]=t; } BufferedReader in; PrintWriter out; StringTokenizer st = new StringTokenizer(""); String nextToken() throws IOException { while (!st.hasMoreTokens()) st = new StringTokenizer(in.readLine()); return st.nextToken(); } int ni() throws IOException { return Integer.parseInt(nextToken()); } long nl() throws IOException { return Long.parseLong(nextToken()); } double nd() throws IOException { return Double.parseDouble(nextToken()); } int[] nia(int size) throws IOException { int[] ret = new int[size]; for (int i = 0; i < size; i++) ret[i] = ni(); return ret; } long[] nla(int size) throws IOException { long[] ret = new long[size]; for (int i = 0; i < size; i++) ret[i] = nl(); return ret; } double[] nda(int size) throws IOException { double[] ret = new double[size]; for (int i = 0; i < size; i++) ret[i] = nd(); return ret; } String nextLine() throws IOException { st = new StringTokenizer(""); return in.readLine(); } boolean EOF() throws IOException { while (!st.hasMoreTokens()) { String s = in.readLine(); if (s == null) return true; st = new StringTokenizer(s); } return false; } void printRepeat(String s, int count) { for (int i = 0; i < count; i++) out.print(s); } void printArray(int[] array) { for (int i = 0; i < array.length; i++) { if (i > 0) out.print(' '); out.print(array[i]); } out.println(); } void printArray(long[] array) { for (int i = 0; i < array.length; i++) { if (i > 0) out.print(' '); out.print(array[i]); } out.println(); } void printArray(double[] array) { for (int i = 0; i < array.length; i++) { if (i > 0) out.print(' '); out.print(array[i]); } out.println(); } void printArray(double[] array, String spec) { for (int i = 0; i < array.length; i++) { if (i > 0) out.print(' '); out.printf(Locale.US, spec, array[i]); } out.println(); } void printArray(Object[] array) { boolean blank = false; for (Object x : array) { if (blank) out.print(' '); else blank = true; out.print(x); } out.println(); } @SuppressWarnings("rawtypes") void printCollection(Collection collection) { boolean blank = false; for (Object x : collection) { if (blank) out.print(' '); else blank = true; out.print(x); } out.println(); } static String memoryStatus() { return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() >> 20) + "/" + (Runtime.getRuntime().totalMemory() >> 20) + " MB"; } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
13b826440ef2c01259dff4a60be819bb
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); OutputStream out = new BufferedOutputStream(System.out); String[] input = br.readLine().split(" "); int n = Integer.parseInt(input[0]); int k = Integer.parseInt(input[1]); for (int i = 0; i < n; i++){ if (i > 0){ out.write(" ".getBytes()); } if (k > 0){ out.write(Integer.toString(2 * i + 2).getBytes()); out.write(" ".getBytes()); out.write(Integer.toString(2 * i + 1).getBytes()); } else { out.write(Integer.toString(2 * i + 1).getBytes()); out.write(" ".getBytes()); out.write(Integer.toString(2 * i + 2).getBytes()); } k--; } out.flush(); } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
ba15ecad07df6d3c26280d0c38f4ac40
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.util.Scanner; public class cod1 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int x=sc.nextInt(); int y=sc.nextInt(); int a=0; int b=0; int swap=0; for(int i=1; i<=x;i++){ b = i*2; a = b-1; if(y>0){ y--; } else { swap = a; a = b; b = swap; } System.out.print(a+" "+b+" "); } } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
3ad2bbe26e3fefc291a05954e64a968d
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.io.*; import java.util.*; public class Permutation2 { public static void main(String[] args) throws IOException { BufferedReader f = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(f.readLine()); int n = Integer.parseInt(st.nextToken()); int k = Integer.parseInt(st.nextToken()); int[] a = new int[2*n]; for (int i = 0; i < 2*n; i++) a[i] = i+1; for (int i = 0; i < k; i++) { int temp = a[2*i]; a[2*i] = a[2*i+1]; a[2*i+1] = temp; } for (int i = 0; i < 2*n; i++) System.out.print(a[i]+" "); System.out.println(); } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
01d6e131ee59d795892039ff0ef3b152
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; import java.util.StringTokenizer; public class Main_B { static PrintWriter pw = new PrintWriter(System.out); static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } } static InputReader scan = new Main_B.InputReader(System.in); public static void main(String[] args) { // TODO Auto-generated method stub int n, k; n = scan.nextInt(); k = scan.nextInt(); int ccc = n; int[] ans = new int[n * 2]; for (int ii = 0; ii < n; ii++) { if (ccc > k) { ans[2 * ii + 1] = (ii + 1) * 2 - 1; ans[2 * ii] = (ii + 1) * 2; ccc--; } else { ans[2 * ii + 1] = (ii + 1) * 2; ans[2 * ii] = (ii + 1) * 2 - 1; } } // StringBuilder sbuild = new StringBuilder(); for (int ii = 0; ii < ans.length - 1; ii++) { pw.print(ans[ii] + " "); } pw.println(ans[ans.length - 1]); pw.close(); } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
db11a166ebb8f5109907d9848de9a5b5
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.util.*; public class Main{ public static void main(String[] args){ Scanner in = new Scanner(System.in); int n = in.nextInt(), k = in.nextInt(); System.out.print(k + 1); for(int i = 1; i<=2*n; i++) if(i != k + 1) System.out.print(" " + i); } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
862acde3f6becee0d9ac4c12add9e2e3
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
//package codeforces; import java.io.BufferedReader; import java.io.Closeable; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.PriorityQueue; import java.util.Queue; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; public class B implements Closeable { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); PrintWriter writer = new PrintWriter(System.out); StringTokenizer stringTokenizer; B() throws IOException { // reader = new BufferedReader(new FileReader("cycle2.in")); // writer = new PrintWriter(new FileWriter("cycle2.out")); } String next() throws IOException { while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) { stringTokenizer = new StringTokenizer(reader.readLine()); } return stringTokenizer.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } final int MOD = 1000 * 1000 * 1000 + 9; int sum(int a, int b) { a += b; return a >= MOD ? a - MOD : a; } int product(int a, int b) { return (int) (1l * a * b % MOD); } @SuppressWarnings("unchecked") void solve() throws IOException { int n = nextInt(), k = nextInt(); for(int i = 0; i < n; i++) { int a = 2 * i + 1; int b = a + 1; if(i < k) { writer.print(a + " " + b + " "); } else { writer.print(b + " " + a + " "); } } } public static void main(String[] args) throws IOException { try (B b = new B()) { b.solve(); } } @Override public void close() throws IOException { reader.close(); writer.close(); } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
04cb937fba8f7ac52f293da9a14861bc
train_003.jsonl
1383379200
A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≀ n. Help him find permutation a of length 2n, such that it meets this equation: .
256 megabytes
import java.util.*; import java.io.*; public class c359B { FastScanner in; PrintWriter out; final int inf = 2147483647; public void solve() throws IOException { int n = in.nextInt(); int k = in.nextInt(); for (int i = 0; i < n; i++) { if (i > 0) out.print(" "); if (k > 0) out.print((2 * i + 2) + " " + (2 * i + 1)); else out.print((2 * i + 1) + " " + (2 * i + 2)); k--; } } public void run() { try { in = new FastScanner(); out = new PrintWriter(System.out); solve(); out.close(); } catch (IOException e) { e.printStackTrace(); } } class FastScanner { BufferedReader br; StringTokenizer st; FastScanner() { try { br = new BufferedReader(new InputStreamReader(System.in)); } catch (Exception e) { e.printStackTrace(); } } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextDouble() { return Double.parseDouble(next()); } } public static void main(String[] args) { new c359B().run(); } }
Java
["1 0", "2 1", "4 0"]
1 second
["1 2", "3 2 1 4", "2 7 4 6 1 3 5 8"]
NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.
Java 7
standard input
[ "dp", "constructive algorithms", "math" ]
82de6d4c892f4140e72606386ec2ef59
The first line contains two integers n and k (1 ≀ n ≀ 50000, 0 ≀ 2k ≀ n).
1,400
Print 2n integers a1, a2, ..., a2n β€” the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.
standard output
PASSED
ab1b477891eb0a0b0b9b9280c5bd0a62
train_003.jsonl
1506335700
Polycarp is in really serious trouble β€” his house is on fire! It's time to save the most valuable items. Polycarp estimated that it would take ti seconds to save i-th item. In addition, for each item, he estimated the value of di β€” the moment after which the item i will be completely burned and will no longer be valuable for him at all. In particular, if ti β‰₯ di, then i-th item cannot be saved.Given the values pi for each of the items, find a set of items that Polycarp can save such that the total value of this items is maximum possible. Polycarp saves the items one after another. For example, if he takes item a first, and then item b, then the item a will be saved in ta seconds, and the item b β€” in ta + tb seconds after fire started.
256 megabytes
/* ID: davidzh8 PROG: subset LANG: JAVA */ import java.io.*; import java.util.*; import java.lang.*; public class fire { static long startTime = System.nanoTime(); public static void main(String[] args) throws Exception { boolean debug = (true); FastScanner sc = new FastScanner("fire.in", debug); FastWriter pw = new FastWriter("fire.out", debug); int N= sc.ni(); Item[] arr= new Item[N]; int[][] dp= new int[N+1][2001]; ArrayList<Integer>[][] list= new ArrayList[N+1][2001]; for (int i = 0; i < N+1; i++) { list[i]= new ArrayList[2001]; for (int j = 0; j < 2001; j++) { list[i][j]= new ArrayList<>(); } } for (int i = 0; i < N; i++) { arr[i]= new Item(sc.ni(), sc.ni(), sc.ni(), i+1); } Arrays.sort(arr); for (int i = 0; i < N+1; i++) { for (int j = 0; j < 2001; j++) { dp[i][j]=0; } } dp[0][0]=0; for (int i = 1; i <= N; i++) { for (int j = 0; j < 2001; j++) { dp[i][j]= dp[i-1][j]; for(int num: list[i-1][j]) list[i][j].add(num); if(j>=arr[i-1].save && j<arr[i-1].burn){ if(dp[i-1][j-arr[i-1].save]+arr[i-1].val > dp[i][j]){ dp[i][j]= dp[i-1][j-arr[i-1].save]+arr[i-1].val; list[i][j]= new ArrayList<>(); for(int num: list[i-1][j-arr[i-1].save]) list[i][j].add(num); list[i][j].add(arr[i-1].i); } } // System.out.print(dp[i][j]+" "); } //System.out.println(); } int best= 0; int idxi=0; int idxj=0; for (int i = 1; i <N+1; i++) { for (int j = 0; j < 2001; j++) { if(dp[i][j]>=best){ best=dp[i][j]; idxi=i; idxj=j; } } } pw.println(best); pw.println(list[idxi][idxj].size()); for(int i: list[idxi][idxj]){ pw.print(i+" "); } /* while(curval!=0){ int notake= dp[idxi-1][idxj]; if(idxj-arr[idxi-1].save<0) break; int take= dp[idxi-1][idxj-arr[idxi-1].save]; if(curval==notake) { curval=notake; idxi=idxi-1; } else { curval = take; idxj = idxj - arr[idxi-1].save; idxi = idxi - 1; res.addFirst(arr[idxi].i); } } ArrayDeque<Integer>res= new ArrayDeque<>(); pw.println(res.size()); while(res.size()>0) pw.print(res.poll()+" "); */ long endTime = System.nanoTime(); //System.out.println("Execution Time: " + (endTime - startTime) / 1e9 + " s"); pw.close(); } static class Item implements Comparable<Item>{ int save; int burn; int val; int i; public Item(int a, int b, int c, int d){ save=a; burn=b; val=c; i=d; } public int compareTo(Item obj){ return this.burn-obj.burn; } } static class djset { int N; int[] parent; // Creates a disjoint set of size n (0, 1, ..., n-1) public djset(int n) { parent = new int[n]; N = n; for (int i = 0; i < n; i++) parent[i] = i; } public int find(int v) { // I am the club president!!! (root of the tree) if (parent[v] == v) return v; // Find my parent's root. int res = find(parent[v]); // Attach me directly to the root of my tree. parent[v] = res; return res; } public boolean union(int v1, int v2) { // Find respective roots. int rootv1 = find(v1); int rootv2 = find(v2); // No union done, v1, v2 already together. if (rootv1 == rootv2) return false; // Attach tree of v2 to tree of v1. parent[rootv2] = rootv1; return true; } } static class FastScanner { InputStream dis; byte[] buffer = new byte[1 << 17]; int pointer = 0; public FastScanner(String fileName, boolean debug) throws Exception { if (debug) dis = System.in; else dis = new FileInputStream(fileName); } int ni() throws Exception { int ret = 0; byte b; do { b = nextByte(); } while (b <= ' '); boolean negative = false; if (b == '-') { negative = true; b = nextByte(); } while (b >= '0' && b <= '9') { ret = 10 * ret + b - '0'; b = nextByte(); } return (negative) ? -ret : ret; } long nl() throws Exception { long ret = 0; byte b; do { b = nextByte(); } while (b <= ' '); boolean negative = false; if (b == '-') { negative = true; b = nextByte(); } while (b >= '0' && b <= '9') { ret = 10 * ret + b - '0'; b = nextByte(); } return (negative) ? -ret : ret; } byte nextByte() throws Exception { if (pointer == buffer.length) { dis.read(buffer, 0, buffer.length); pointer = 0; } return buffer[pointer++]; } String next() throws Exception { StringBuffer ret = new StringBuffer(); byte b; do { b = nextByte(); } while (b <= ' '); while (b > ' ') { ret.appendCodePoint(b); b = nextByte(); } return ret.toString(); } } static class FastWriter { public PrintWriter pw; public FastWriter(String name, boolean debug) throws IOException { if (debug) { pw = new PrintWriter(System.out); } else { pw = new PrintWriter(new BufferedWriter(new FileWriter(new File(name)))); } } public void println(Object text) { pw.println(text); } public void print(Object text) { pw.print(text); } public void close() { pw.close(); } public void flush() { pw.flush(); } } }
Java
["3\n3 7 4\n2 6 5\n3 7 6", "2\n5 6 1\n3 3 5"]
2 seconds
["11\n2\n2 3", "1\n1\n1"]
NoteIn the first example Polycarp will have time to save any two items, but in order to maximize the total value of the saved items, he must save the second and the third item. For example, he can firstly save the third item in 3 seconds, and then save the second item in another 2 seconds. Thus, the total value of the saved items will be 6 + 5 = 11.In the second example Polycarp can save only the first item, since even if he immediately starts saving the second item, he can save it in 3 seconds, but this item will already be completely burned by this time.
Java 11
standard input
[ "dp", "sortings" ]
f7a784dd4add8a0e892921c130068933
The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of items in Polycarp's house. Each of the following n lines contains three integers ti, di, pi (1 ≀ ti ≀ 20, 1 ≀ di ≀ 2 000, 1 ≀ pi ≀ 20) β€” the time needed to save the item i, the time after which the item i will burn completely and the value of item i.
2,000
In the first line print the maximum possible total value of the set of saved items. In the second line print one integer m β€” the number of items in the desired set. In the third line print m distinct integers β€” numbers of the saved items in the order Polycarp saves them. Items are 1-indexed in the same order in which they appear in the input. If there are several answers, print any of them.
standard output
PASSED
4f682274af044c59eded83de77a77cc7
train_003.jsonl
1506335700
Polycarp is in really serious trouble β€” his house is on fire! It's time to save the most valuable items. Polycarp estimated that it would take ti seconds to save i-th item. In addition, for each item, he estimated the value of di β€” the moment after which the item i will be completely burned and will no longer be valuable for him at all. In particular, if ti β‰₯ di, then i-th item cannot be saved.Given the values pi for each of the items, find a set of items that Polycarp can save such that the total value of this items is maximum possible. Polycarp saves the items one after another. For example, if he takes item a first, and then item b, then the item a will be saved in ta seconds, and the item b β€” in ta + tb seconds after fire started.
256 megabytes
import java.io.*; import java.util.*; import java.lang.*; // .--------------. // | Try First One| // '--------------' // | .--------------. // | | | // V V | // .--------------. | // | AC. |<---. | // '--------------' | | // (True)| |(False) | | // .--------' | | | // | V | | // | .--------------. | | // | | Try Again |----' | // | '--------------' | // | | // | .--------------. | // '->| Try Next One |-------' // '--------------' public class Fire { //Start Stub static long startTime = System.nanoTime(); //Globals Go Here //Globals End public static void main(String[] args) throws IOException { FastScanner sc = new FastScanner("Fire.in", true); FastWriter pw = new FastWriter("Fire.out", true); int N= sc.ni(); Edge[] arr= new Edge[N]; int dp[][]= new int[N+1][2001]; for (int i = 0; i < N; i++) { int a= sc.ni(); int b= sc.ni(); int c=sc.ni(); arr[i]= new Edge(a,b,c, i); } Arrays.sort(arr); for (int i = 0; i <= N; i++) { for (int j = 0; j < 2001; j++) { dp[i][j]= (int) -1e9; } } dp[0][0]=0; for (int i = 0; i < N; i++) { for (int j = 0; j+arr[i].ti< arr[i].di; j++) { if (dp[i][j] != (int) -1e9){ dp[i+1][j+ arr[i].ti]= Math.max(dp[i][j] + arr[i].val, dp[i+1][j+ arr[i].ti]); } } for (int j = 0; j < 2001; j++) { dp[i+1][j]= Math.max(dp[i+1][j], dp[i][j]); } } int best=0; for (int i = 0; i < 2001; i++) { if (dp[N][i] > dp[N][best]){ best= i; } } int res= dp[N][best]; // find the order Stack<Integer> list= new Stack<>(); for (int i = N; i > 0; i--) { if(dp[i][best] != dp[i-1][best]) { list.push(arr[i-1].i+1); best -= arr[i-1].ti; } } pw.println(res); pw.println(list.size()); while (list.size()>0){ pw.print(list.peek()+ " "); list.pop(); } /* End Stub */ long endTime = System.nanoTime(); //System.out.println("Execution Time: " + (endTime - startTime) / 1e9 + " s"); pw.close(); } static class Edge implements Comparable<Edge>{ int ti, di, val, i; public Edge(int a, int b, int c, int i){ this.ti=a; this.di=b; this.val=c; this.i=i; } public int compareTo(Edge obj){ return di-obj.di; } } static class SegmentTree { public long[] arr; public long[] tree; public int N; //Zero initialization public SegmentTree(int n) { N = n; arr = new long[N]; tree = new long[4 * N + 1]; } public long query(int treeIndex, int lo, int hi, int i, int j) { // query for arr[i..j] if (lo > j || hi < i) return 0; if (i <= lo && j >= hi) return tree[treeIndex]; int mid = lo + (hi - lo) / 2; if (i > mid) return query(2 * treeIndex + 2, mid + 1, hi, i, j); else if (j <= mid) return query(2 * treeIndex + 1, lo, mid, i, j); long leftQuery = query(2 * treeIndex + 1, lo, mid, i, mid); long rightQuery = query(2 * treeIndex + 2, mid + 1, hi, mid + 1, j); // merge query results return merge(leftQuery, rightQuery); } public void update(int treeIndex, int lo, int hi, int arrIndex, long val) { if (lo == hi) { tree[treeIndex] = val; arr[arrIndex] = val; return; } int mid = lo + (hi - lo) / 2; if (arrIndex > mid) update(2 * treeIndex + 2, mid + 1, hi, arrIndex, val); else if (arrIndex <= mid) update(2 * treeIndex + 1, lo, mid, arrIndex, val); // merge updates tree[treeIndex] = merge(tree[2 * treeIndex + 1], tree[2 * treeIndex + 2]); } public long merge(long a, long b) { return (a + b); } } static class djset { int N; int[] parent; // Creates a disjoint set of size n (0, 1, ..., n-1) public djset(int n) { parent = new int[n]; N = n; for (int i = 0; i < n; i++) parent[i] = i; } public int find(int v) { // I am the club president!!! (root of the tree) if (parent[v] == v) return v; // Find my parent's root. int res = find(parent[v]); // Attach me directly to the root of my tree. parent[v] = res; return res; } public boolean union(int v1, int v2) { // Find respective roots. int rootv1 = find(v1); int rootv2 = find(v2); // No union done, v1, v2 already together. if (rootv1 == rootv2) return false; // Attach tree of v2 to tree of v1. parent[rootv2] = rootv1; return true; } } static class FastScanner { public BufferedReader br; public StringTokenizer st; public InputStream is; public FastScanner(String name, boolean debug) throws IOException { if (debug) { is = System.in; } else { is = new FileInputStream(name); } br = new BufferedReader(new InputStreamReader(is), 32768); st = null; } public String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return st.nextToken(); } public int ni() { return Integer.parseInt(next()); } public long nl() { return Long.parseLong(next()); } public double nd() { return Double.parseDouble(next()); } public String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { throw new RuntimeException(e); } return str; } } static class FastWriter { public PrintWriter pw; public FastWriter(String name, boolean debug) throws IOException { if (debug) { pw = new PrintWriter(System.out); } else { pw = new PrintWriter(new BufferedWriter(new FileWriter(new File(name)))); } } public void println(Object text) { pw.println(text); } public void print(Object text) { pw.print(text); } public void close() { pw.close(); } public void flush() { pw.flush(); } } }
Java
["3\n3 7 4\n2 6 5\n3 7 6", "2\n5 6 1\n3 3 5"]
2 seconds
["11\n2\n2 3", "1\n1\n1"]
NoteIn the first example Polycarp will have time to save any two items, but in order to maximize the total value of the saved items, he must save the second and the third item. For example, he can firstly save the third item in 3 seconds, and then save the second item in another 2 seconds. Thus, the total value of the saved items will be 6 + 5 = 11.In the second example Polycarp can save only the first item, since even if he immediately starts saving the second item, he can save it in 3 seconds, but this item will already be completely burned by this time.
Java 11
standard input
[ "dp", "sortings" ]
f7a784dd4add8a0e892921c130068933
The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of items in Polycarp's house. Each of the following n lines contains three integers ti, di, pi (1 ≀ ti ≀ 20, 1 ≀ di ≀ 2 000, 1 ≀ pi ≀ 20) β€” the time needed to save the item i, the time after which the item i will burn completely and the value of item i.
2,000
In the first line print the maximum possible total value of the set of saved items. In the second line print one integer m β€” the number of items in the desired set. In the third line print m distinct integers β€” numbers of the saved items in the order Polycarp saves them. Items are 1-indexed in the same order in which they appear in the input. If there are several answers, print any of them.
standard output
PASSED
ae08261b04ee31e0ed9f0a20a240c785
train_003.jsonl
1506335700
Polycarp is in really serious trouble β€” his house is on fire! It's time to save the most valuable items. Polycarp estimated that it would take ti seconds to save i-th item. In addition, for each item, he estimated the value of di β€” the moment after which the item i will be completely burned and will no longer be valuable for him at all. In particular, if ti β‰₯ di, then i-th item cannot be saved.Given the values pi for each of the items, find a set of items that Polycarp can save such that the total value of this items is maximum possible. Polycarp saves the items one after another. For example, if he takes item a first, and then item b, then the item a will be saved in ta seconds, and the item b β€” in ta + tb seconds after fire started.
256 megabytes
import java.util.*; import java.io.*; public class E436 { public static void main(String[] args) { MyScanner sc = new MyScanner(); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); int n = sc.nextInt(); Item [] a = new Item[n]; for (int i = 0; i < n; i++) { a[i] = new Item(sc.nextInt(), sc.nextInt(), sc.nextInt(), i + 1); } Arrays.sort(a); int [][] dp = new int[n+1][2020]; long ans = 0; int endTime = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= 2000; j++) { Item item = a[i - 1]; int destroy = item.d; int time = item.t; int val = item.p; if (destroy <= j || j - time < 0) { dp[i][j] = dp[i-1][j]; } else { dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - time] + val); } if (i == n) { if (dp[i][j] > ans) { ans = dp[i][j]; endTime = j; } } } } int t = endTime; int idx = n; LinkedList<Integer> l = new LinkedList<>(); int sz = 0; while (idx > 0) { Item item = a[idx - 1]; int time = item.t; int val = item.p; if (t - time >= 0 && dp[idx - 1][t - time] == (dp[idx][t] - val)) { l.addFirst(item.i); t -= time; sz++; } idx--; } out.println(ans); out.println(sz); for (int i = 0; i < sz; i++) out.print(l.pollFirst() + " "); out.close(); } static class Item implements Comparable<Item> { int t; int d; int p; int i; Item(int t, int d, int p, int i) { this.t = t; this.d = d; this.p = p; this.i = i; } @Override public int compareTo(Item o) { return d - o.d; } } //-----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["3\n3 7 4\n2 6 5\n3 7 6", "2\n5 6 1\n3 3 5"]
2 seconds
["11\n2\n2 3", "1\n1\n1"]
NoteIn the first example Polycarp will have time to save any two items, but in order to maximize the total value of the saved items, he must save the second and the third item. For example, he can firstly save the third item in 3 seconds, and then save the second item in another 2 seconds. Thus, the total value of the saved items will be 6 + 5 = 11.In the second example Polycarp can save only the first item, since even if he immediately starts saving the second item, he can save it in 3 seconds, but this item will already be completely burned by this time.
Java 11
standard input
[ "dp", "sortings" ]
f7a784dd4add8a0e892921c130068933
The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of items in Polycarp's house. Each of the following n lines contains three integers ti, di, pi (1 ≀ ti ≀ 20, 1 ≀ di ≀ 2 000, 1 ≀ pi ≀ 20) β€” the time needed to save the item i, the time after which the item i will burn completely and the value of item i.
2,000
In the first line print the maximum possible total value of the set of saved items. In the second line print one integer m β€” the number of items in the desired set. In the third line print m distinct integers β€” numbers of the saved items in the order Polycarp saves them. Items are 1-indexed in the same order in which they appear in the input. If there are several answers, print any of them.
standard output
PASSED
9ebe74d37273f3f17883781d6de8da96
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.Map; import java.util.Scanner; import java.util.TreeMap; public class Fruits { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int nFruits = scan.nextInt(); int mItems = scan.nextInt(); Integer[] prices = new Integer[nFruits]; String[] fruit_names = new String[mItems]; Integer count; int lucky = 0; int unlucky = 0; HashMap<String, Integer> itemsMap = new HashMap<String, Integer>(); TreeMap<String, Integer> sortedItemsMap = new TreeMap<>(new ValueComparator(itemsMap)); for(int i = 0; i < nFruits; i++) { prices[i] = scan.nextInt(); } for(int i = 0; i < mItems; i++) { fruit_names[i] = scan.next(); count = itemsMap.get(fruit_names[i]); itemsMap.put(fruit_names[i], ((count == null)? 1 : count + 1)); } Arrays.sort(prices); sortedItemsMap.putAll(itemsMap); int i = 0; for(Map.Entry<String,Integer> entry : sortedItemsMap.entrySet()) { lucky += entry.getValue() * prices[i++]; } Arrays.sort(prices, new Comparator<Integer>() { @Override public int compare(Integer i1, Integer i2) { if(i1 > i2) return -1; if(i1 == i2) return 0; return 1; } }); i = 0; for(Map.Entry<String,Integer> entry : sortedItemsMap.entrySet()) { unlucky += entry.getValue() * prices[i++]; } System.out.println(lucky + " " + unlucky); scan.close(); } } class ValueComparator implements Comparator<String> { Map<String, Integer> base; public ValueComparator(Map<String, Integer> base) { this.base = base; } // Note: this comparator imposes orderings that are inconsistent with equals. public int compare(String a, String b) { if (base.get(a) >= base.get(b)) { return -1; } else { return 1; } // returning 0 would merge keys } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
ef01d7bf8c8f584f58c0d32f623ca9b8
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.StringTokenizer; public class C_12 { FastScanner in; PrintWriter out; public void run() { try { in = new FastScanner(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); out.close(); } catch (IOException e) { e.printStackTrace(); } } public void solve() throws IOException { int n = in.nextInt(); int m = in.nextInt(); HashMap<String, Wrapper> fruits = new HashMap<String, Wrapper>(); int [] a = new int[n]; ArrayList<Integer> b = new ArrayList<Integer>(); int minSum = 0; int maxSum = 0; for (int i=0; i<n; i++) { a[i] = in.nextInt(); } String f = null; for (int i=0; i<m; i++) { f = in.next(); if (fruits.containsKey(f) == false) { fruits.put(f, new Wrapper(0)); } fruits.get(f).val++; } for (Wrapper w : fruits.values()) { b.add(w.val); } Collections.sort(b); Arrays.sort(a); int j = 0; for (int i=b.size()-1; i>=0; i--) { minSum += b.get(i) * a[j]; j++; } j = n-1; for (int i=b.size()-1; i>=0; i--) { maxSum += b.get(i) * a[j]; j--; } out.println(minSum + " " + maxSum); } class Wrapper { int val = 0; Wrapper(int a) { val = a; } } class FastScanner { BufferedReader br; StringTokenizer st; FastScanner(InputStreamReader in) { br = new BufferedReader(in); } String nextLine() { String str = null; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } } public static void main(String[] arg) { C_12 o = new C_12(); o.run(); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
497fc65a0ff74cd4a204da48534be7cf
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.StringTokenizer; /** * 10:48 ~ * */ public class Main { public static void main(String[] argv) { FastScanner scan = new FastScanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = scan.nextInt(); int m = scan.nextInt(); int tags[] = new int[n]; for(int i = 0; i < n; ++i) tags[i] = scan.nextInt(); Arrays.sort(tags); String[] ins = new String[m]; for(int i = 0; i < m; ++i){ ins[i] = scan.next(); } boolean used[] = new boolean[m]; List<Integer> strs = new ArrayList<Integer>(); for(int i = 0; i < m; ++i){ if(used[i]) continue; used[i] = true; int cnt = 1; for(int j = i + 1; j < m; ++j){ if(used[j]) continue; if(ins[i].equals(ins[j])) { ++cnt; used[j] = true; } } strs.add(cnt); } Collections.sort(strs, new Comparator<Integer>(){ @Override public int compare(Integer arg0, Integer arg1) { if(arg0 < arg1) return 1; else if(arg0 == arg1) return 0; else return -1; } }); int min = 0, max = 0; for(int i = 0; i < strs.size(); ++i){ min += (tags[i] * strs.get(i)); max += (tags[n-i-1] * strs.get(i)); } out.println(min + " " + max); out.close(); } static class FastScanner { BufferedReader br; StringTokenizer st; FastScanner(InputStream is) { try { br = new BufferedReader(new InputStreamReader(is)); } catch (Exception e) { e.printStackTrace(); } } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { return null; } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.valueOf(next()); } } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
8213671a5f16ea2234fe0680a9ec922f
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Scanner; public class C12 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int m = in.nextInt(); int prices[] = new int[n]; for (int i = 0; i < n; ++i) { prices[i] = in.nextInt(); } String[] fruits = new String[m]; in.nextLine(); for (int i = 0; i < m; ++i) { fruits[i] = in.nextLine(); } Arrays.sort(fruits); Arrays.sort(prices); long max = 0; long min = 0; int left = 0; int right = n - 1; String currentName = ""; List<Integer> listIntegers = new ArrayList<Integer>(); int count = 0; for (int i = 0; i < m; ++i) { if (currentName.equals(fruits[i])) { count++; } else { if (!currentName.equals("")) { listIntegers.add(count); } currentName = (fruits[i]); count = 1; } } listIntegers.add(count); Collections.sort(listIntegers); for (int i = listIntegers.size() - 1; i >= 0; --i) { min += listIntegers.get(i) * prices[left++]; max += listIntegers.get(i) * prices[right--]; } System.out.println(min + " " + max); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
32ca9400e5666d3bfeef1da4729c5ec1
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.io.*; import java.util.*; public class c12 { public static void main(String args[])throws IOException { InputStreamReader read=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(read); int n,m,minp=0,maxp=0,i,j,k=1,l=0,t; int price[]=new int[1000]; int nof[]=new int[1000]; String s,fruit,s1; String str[]=new String[1000]; // System.out.println("Enter"); s=in.readLine(); StringTokenizer st=new StringTokenizer(s); n=Integer.parseInt(st.nextToken()); m=Integer.parseInt(st.nextToken()); s1=in.readLine(); StringTokenizer st1=new StringTokenizer(s1); for(i=0;i<n;i++) price[i]=Integer.parseInt(st1.nextToken()); str[0]=in.readLine(); nof[0]++; for(i=1;i<m;i++) { l=0; fruit=in.readLine(); for(j=0;j<k;j++) { if(str[j].compareTo(fruit)==0) { l++; nof[j]++; break; } } if(l==0) { str[k]=fruit; nof[k]++; k++; } } for(i=0;i<n-1;i++) { for(j=i+1;j<n;j++) { if(price[i]>=price[j]) { t=price[i]; price[i]=price[j]; price[j]=t; } } } for(i=0;i<k-1;i++) { for(j=i+1;j<k;j++) { if(nof[i]<=nof[j]) { t=nof[i]; nof[i]=nof[j]; nof[j]=t; } } } l=n-1; for(i=0;i<k;i++) minp=minp+(nof[i]*price[i]); for(i=0;i<k;i++) { maxp=maxp+(nof[i]*price[l]); l--; } System.out.println(minp+" "+maxp); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
59fdd0f09b454138615083318b0a4d72
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.io.*; import java.util.*; /** * Codeforces 12C - Fruits * Created by Darren on 14-10-23. */ public class C { Reader in = new Reader(System.in); PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) throws IOException { new C().run(); } void run() throws IOException { int n = in.nextInt(), m = in.nextInt(); int[] prices = new int[n]; for (int i = 0; i < n; i++) prices[i] = in.nextInt(); // Sort the prices in non-decreasing order Arrays.sort(prices); // Each element is a fruit with its name and its total purchase amount List<Fruit> shopping = new ArrayList<Fruit>(); // A map between fruit name and its index at the shopping list Map<String, Integer> fruitIndex = new HashMap<String, Integer>(); int kind = 0; // Kinds of fruits for (int i = 0; i < m; i++) { String fruit = in.readLine(); if (fruitIndex.containsKey(fruit)) { // One more fruit encountered before shopping.get(fruitIndex.get(fruit)).increment(); } else { // A new fruit shopping.add(new Fruit(fruit, 1)); fruitIndex.put(fruit, kind++); } } // Sort the shopping list by purchase amount in non-decreasing order Collections.sort(shopping); // The minimum payment is achieved if he distributes the lowest price to the // fruit with the greatest amount int min = 0; for (int i = 0; i < kind; i++) min += prices[i] * shopping.get(kind-i-1).getAmount(); // The maximum payment is achieved if he distributes the highest price to the // fruit with the greatest amount int max = 0; for (int i = kind-1; i >= 0; i--) max += prices[n+i-kind] * shopping.get(i).getAmount(); out.printf("%d %d\n", min, max); out.flush(); } class Fruit implements Comparable<Fruit>{ String name; int amount; public Fruit(String name, int amount) { this.name = name; this.amount = amount; } @Override public int compareTo(Fruit o) { return this.amount - o.amount; } public void increment() { amount++; } public int getAmount() { return amount; } } static class Reader { BufferedReader reader; StringTokenizer tokenizer; public Reader(InputStream input) { reader = new BufferedReader(new InputStreamReader(input)); tokenizer = new StringTokenizer(""); } /** get next word */ String nextToken() throws IOException { while ( ! tokenizer.hasMoreTokens() ) { //TODO add check for eof if necessary tokenizer = new StringTokenizer( reader.readLine() ); } return tokenizer.nextToken(); } String readLine() throws IOException { return reader.readLine(); } int nextInt() throws IOException { return Integer.parseInt( nextToken() ); } long nextLong() throws IOException { return Long.parseLong( nextToken() ); } double nextDouble() throws IOException { return Double.parseDouble( nextToken() ); } } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
e6b7a72fdee8970ebbfa65c804c0be55
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.util.Scanner; public class prombel12Cfruits { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int m = scan.nextInt(); boolean fl = true, fl2 = true; int[] costs = new int[n]; for (int i = 0; i < n; i++) costs[i] = scan.nextInt(); String current_fruit = new String(""); String[] fruits = new String[m]; int[] c= new int[m]; int K = 0; for (int i = 0; i<m; i++) { c[i] = 0; } fruits[0] = scan.next(); c[0] = 1; K = 1; for (int i = 1; i < m; i++) { current_fruit = scan.next(); fl = true; for (int j = 0; j<K+1; j++) { if (current_fruit.equals(fruits[j])) { c[j]++; fl = false; break; } } if (fl == true) { K++; fruits[K-1] = current_fruit; c[K-1]++; } } scan.close(); int temp = 0; while(true) { fl2 = true; for (int i = 0; i < costs.length-1; i++) if(costs[i]>costs[i+1]) { temp = costs[i+1]; costs[i+1] = costs[i]; costs[i] = temp; fl2 = false; } if (fl2) break; } while(true) { fl2 = true; for (int i = 0; i < K-1; i++) if(c[i]<c[i+1]) { temp = c[i+1]; c[i+1] = c[i]; c[i] = temp; fl2 = false; } if (fl2) break; } int a1 = 0, a2 = 0; for (int i = 0; i<K; i++) a1 += (c[i]*costs[i]); for (int i = 0; i<K; i++) a2 += (c[i]*costs[costs.length-1-i]); System.out.println(a1+" "+a2); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
89731748aa2f6351541ef361aad881b9
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.io.*; import java.util.*; import java.math.*; public class P12C { @SuppressWarnings("unchecked") public void run() throws Exception { int n = nextInt(); int m = nextInt(); int [] p = readInt(n); Arrays.sort(p); HashMap<String, Integer> hm = new HashMap<String, Integer>(); for (int i = 0; i < m; i++) { String s = nextLine(); Integer c = hm.get(s); hm.put(s, (c == null) ? 1 : (c + 1)); } int [] q = new int [hm.size()]; int idx = 0; for (Integer i : hm.values()) { q[idx++] = i; } Arrays.sort(q); int min = 0; int max = 0; for (int i = q.length - 1; i >= 0; i--) { min += q[i] * p[q.length - i - 1]; max += q[i] * p[p.length - (q.length - i)]; } println(min + " " + max); } public static void main(String... args) throws Exception { br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new BufferedOutputStream(System.out)); new P12C().run(); br.close(); pw.close(); } static BufferedReader br; static PrintWriter pw; StringTokenizer stok; String nextToken() throws IOException { while (stok == null || !stok.hasMoreTokens()) { String s = br.readLine(); if (s == null) { return null; } stok = new StringTokenizer(s); } return stok.nextToken(); } void print(byte b) { print("" + b); } void print(int i) { print("" + i); } void print(long l) { print("" + l); } void print(double d) { print("" + d); } void print(char c) { print("" + c); } void print(Object o) { if (o instanceof int[]) { print(Arrays.toString((int [])o)); } else if (o instanceof long[]) { print(Arrays.toString((long [])o)); } else if (o instanceof char[]) { print(Arrays.toString((char [])o)); } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o)); } else if (o instanceof short[]) { print(Arrays.toString((short [])o)); } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o)); } else if (o instanceof float[]) { print(Arrays.toString((float [])o)); } else if (o instanceof double[]) { print(Arrays.toString((double [])o)); } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o)); } else { println("" + o); } } void print(String s) { pw.print(s); } void println() { println(""); } void println(byte b) { println("" + b); } void println(int i) { println("" + i); } void println(long l) { println("" + l); } void println(double d) { println("" + d); } void println(char c) { println("" + c); } void println(Object o) { print("" + o); } void println(String s) { pw.println(s); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } char nextChar() throws IOException { return (char) (br.read()); } String next() throws IOException { return nextToken(); } String nextLine() throws IOException { return br.readLine(); } int [] readInt(int size) throws IOException { int [] array = new int [size]; for (int i = 0; i < size; i++) { array[i] = nextInt(); } return array; } long [] readLong(int size) throws IOException { long [] array = new long [size]; for (int i = 0; i < size; i++) { array[i] = nextLong(); } return array; } double [] readDouble(int size) throws IOException { double [] array = new double [size]; for (int i = 0; i < size; i++) { array[i] = nextDouble(); } return array; } String [] readLines(int size) throws IOException { String [] array = new String [size]; for (int i = 0; i < size; i++) { array[i] = nextLine(); } return array; } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
2bfee4b8bf81cb3ff7ce3dc5a76ba558
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.io.File; import java.io.FileNotFoundException; import java.math.BigInteger; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.Hashtable; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.Iterator; public class Main { public static void main(String[] args) throws FileNotFoundException { //Scanner sc = new Scanner(new File("in.in")); Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int tmp,max=0,min=0; String name; int size; sc.nextLine(); Map<String , Integer> map = new HashMap<String, Integer>(); int tab[] = new int[n]; for(int i=0;i<n;i++){ tab[i] = sc.nextInt(); } sc.nextLine(); Arrays.sort(tab); for(int i=0;i<m;i++){ name = sc.nextLine(); if(map.get(name)==null){ map.put(name, 1); } else{ tmp = map.get(name); map.put(name, ++tmp); } } map = sortByComparator(map); int i=0; for (Entry<String, Integer> entry : map.entrySet()) { min+=entry.getValue() * tab[i]; i++; } System.out.print(min + " "); i=tab.length-1; for (Entry<String, Integer> entry : map.entrySet()) { max+=entry.getValue() * tab[i]; i--; } System.out.print(max); } private static Map<String, Integer> sortByComparator(Map<String, Integer> unsortMap) { // Convert Map to List List<Map.Entry<String, Integer>> list = new LinkedList<Map.Entry<String, Integer>>(unsortMap.entrySet()); // Sort list with comparator, to compare the Map values Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() { public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) { if(o1.getValue()>o2.getValue()) return -1; else if(o1.getValue()<o2.getValue()) return 1; else return 0; } }); // Convert sorted map back to a Map Map<String, Integer> sortedMap = new LinkedHashMap<String, Integer>(); for (Iterator<Map.Entry<String, Integer>> it = list.iterator(); it.hasNext();) { Map.Entry<String, Integer> entry = it.next(); sortedMap.put(entry.getKey(), entry.getValue()); } return sortedMap; } public static void printMap(Map<String, Integer> map) { for (Entry<String, Integer> entry : map.entrySet()) { System.out.println("Key : " + entry.getKey() + " Value : " + entry.getValue()); } } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
4ec92acb9887d482afea42414a09b288
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.io.*; import java.util.*; public class fruits { static BufferedReader br; static StringTokenizer st; static PrintWriter out; public static int exists(String[] a, String b) { for (int i = 0; i < a.length; i++) if (a[i].equals(b)) return i; return -1; } public static void main(String[] args) throws IOException { InputStream input = System.in; //InputStream input = new FileInputStream("fileIn.in"); OutputStream output = System.out; //OutputStream output = new FileOutputStream("fileOut.out"); br = new BufferedReader(new InputStreamReader(input)); out = new PrintWriter(output); StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); int m = Integer.parseInt(st.nextToken()); st = new StringTokenizer(br.readLine()); int[] tags = new int[n]; for (int i = 0; i < n; i++) tags[i] = Integer.parseInt(st.nextToken()); for (int i = 1; i < n; i++) for (int j = 0; j < i; j++) if (tags[i] < tags[j]) { int c = tags[i]; tags[i] = tags[j]; tags[j] = c; } String[] fruits = new String[m]; for (int i = 0; i < m; i++) fruits[i] = ""; int[] number = new int[m]; int ind = 0; for (int i = 0; i < m; i++) { String fruit = br.readLine(); if (exists(fruits,fruit) != -1) number[exists(fruits,fruit)] += 1; else { fruits[ind] = fruit; number[ind] = 1; ind++; } } for (int i = 1; i < ind; i++) for (int j = 0; j < i; j++) if (number[i] > number[j]) { int c = number[i]; number[i] = number[j]; number[j] = c; } int min = 0; int max = 0; for (int i = 0; i < ind; i++) { min += tags[i] * number[i]; max += tags[n-1-i] * number[i]; } out.println(min + " " + max); out.close(); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
7129b54626838ee80b4af25d0a4207b9
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.util.*; import java.io.*; public class C12 { class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public InputReader() throws FileNotFoundException{ reader = new BufferedReader(new FileReader("d:/test1.txt")); 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 void run(){ InputReader reader = new InputReader(System.in); int n = reader.nextInt(); int m = reader.nextInt(); int re[] = new int[n]; for(int i = 0 ; i < n ; i ++){ re[i] = reader.nextInt(); } Arrays.sort(re); TreeMap<String,Integer> map = new TreeMap<String,Integer>(); for(int i = 0 ; i < m ; i ++){ String str = reader.next(); int cnt = 1; if(map.containsKey(str)) cnt += map.get(str); map.put(str, cnt); } ArrayList<Integer> list = new ArrayList<Integer>(); Set<String> set = map.keySet(); for(String i : set){ list.add(map.get(i)*(-1)); } int rr[] = new int[list.size()]; for(int i = 0 ; i < list.size() ; i ++){ rr[i] = list.get(i); } Arrays.sort(rr); long min = 0;long max = 0; for(int i = 0 ; i < rr.length ; i ++){ min += (-1)*rr[i]*re[i]; } int j = 0; for(int i = re.length-1 ; i >= 0 ; i --){ max += (-1)*rr[j++]*re[i]; if(j >= rr.length) break; } System.out.println(min+" "+max); } public static void main(String[] args) { new C12().run(); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
2ac6e1c84037c5ad54f7dfff1c1fe2df
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.io.*; import java.util.*; public class CF { void realSolve() { int n = in.nextInt(); int m = in.nextInt(); int[] cost = new int[n]; for (int i = 0; i < n; i++) cost[i] = in.nextInt(); Arrays.sort(cost); HashMap<String, Integer> hm = new HashMap<>(); int it = 0; int[] sz = new int[m]; for (int i = 0; i < m; i++) { String s = in.next(); Integer id = hm.get(s); if (id == null) { hm.put(s, it); id = it++; } sz[id]++; } Arrays.sort(sz); int max = 0; for (int i = 0; i < m; i++) { if (n - i - 1 >= 0) max += sz[m - i - 1] * cost[n - i - 1]; } int min = 0; for (int i = 0; i < m; i++) { if (i < n) min += sz[m - i - 1] * cost[i]; } out.println(min + " " + max); } private class InputReader { StringTokenizer st; BufferedReader br; public InputReader(File f) { try { br = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException e) { e.printStackTrace(); } } public InputReader(InputStream f) { br = new BufferedReader(new InputStreamReader(f)); } String next() { while (st == null || !st.hasMoreElements()) { String s; try { s = br.readLine(); } catch (IOException e) { return null; } if (s == null) return null; st = new StringTokenizer(s); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextDouble() { return Double.parseDouble(next()); } boolean hasMoreElements() { while (st == null || !st.hasMoreElements()) { String s; try { s = br.readLine(); } catch (IOException e) { return false; } st = new StringTokenizer(s); } return st.hasMoreElements(); } long nextLong() { return Long.parseLong(next()); } } InputReader in; PrintWriter out; void solve() { in = new InputReader(new File("object.in")); try { out = new PrintWriter(new File("object.out")); } catch (FileNotFoundException e) { e.printStackTrace(); } realSolve(); out.close(); } void solveIO() { in = new InputReader(System.in); out = new PrintWriter(System.out); realSolve(); out.close(); } public static void main(String[] args) { new CF().solveIO(); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
6cfb9ca698c1adf981ae275a002bde8a
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Scanner; public class Solution { public static void main(String args[]) { Scanner scanner = new Scanner(System.in); int fruits = scanner.nextInt(); int wishes = scanner.nextInt(); int[] stall = new int[fruits]; for(int i = 0; i < fruits; i++) { stall[i] = scanner.nextInt(); } scanner.nextLine(); HashMap<String, Integer> hm = new HashMap<String, Integer>(); for(int i = 0; i < wishes; i++) { String fruit = scanner.nextLine(); Integer count = hm.get(fruit); if(count == null) { hm.put(fruit, 1); } else { hm.put(fruit, count + 1); } } Object[] list = hm.values().toArray(); scanner.close(); Arrays.sort(stall); Arrays.sort(list, Collections.reverseOrder()); int min = 0; int max = 0; for(int i = 0; i < list.length; i++) { int item = (Integer) list[i]; min += item * stall[i]; max += item * stall[stall.length - 1 - i]; } System.out.println(min + " " + max); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
92f6a652a783ac8571a48547d6ecd5fb
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.util.ArrayList; import java.util.Scanner; public class P12C { P12C (){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); ArrayList<Integer>prices = new ArrayList<>(); for (int i = 0; i < n; i++){ prices.add(sc.nextInt()); } ArrayList <String> fruits = new ArrayList<>(); ArrayList<Integer> quant = new ArrayList<>(); for (int i = 0; i < m; i++){ String fruit = sc.next(); if (fruits.contains(fruit)){ int ind = fruits.indexOf(fruit); quant.set(ind, quant.get(ind) + 1); } else { fruits.add(fruit); quant.add(1); } } m = fruits.size(); sc.close(); quicksort(prices, null, 0, n-1); quicksort(quant, fruits, 0, m-1); int min = 0; int max = 0; for (int i = m-1, j = 0; i >= 0 && j < n; i--, j++){ min += prices.get(j) * quant.get(i); } for (int i = m-1, j = n-1; i >= 0 && j >= 0; i--, j--){ max += prices.get(j) * quant.get(i); } System.out.println(min + " " + max); } void quicksort (ArrayList<Integer> array, ArrayList<String> aux, int left, int right){ int pivot = array.get(left + (right - left) / 2); int i = left; int j = right; while (i <= j){ while (array.get(i) < pivot){ i ++; } while (array.get(j) > pivot){ j --; } if (i <= j){ int tmp = array.get(i); array.set(i, array.get(j)); array.set(j, tmp); if (aux != null){ String tmpS = aux.get(i); aux.set(i, aux.get(j)); aux.set(j, tmpS); } i++; j--; } } if (left < j){ quicksort(array, aux, left, j); } if (i < right){ quicksort(array, aux, i, right); } } public static void main (String []args){ new P12C(); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
56241e8861758977ac30cfea6398d119
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.util.Arrays; import java.util.ArrayList; import java.io.InputStream; import java.io.InputStreamReader; import java.util.HashMap; import java.util.List; import java.io.BufferedReader; import java.util.Collection; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Collections; import java.io.IOException; import java.util.StringTokenizer; /** * 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); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } } class TaskC { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int m = in.nextInt(); Long[] prices = new Long[n]; for (int i = 0; i < n; i++) { prices[i] = in.nextLong(); } HashMap<String, Integer> map = new HashMap<String, Integer>(); for (int i = 0; i < m; i++) { String fruit = in.next(); if (map.containsKey(fruit)) { int cur = map.get(fruit); map.put(fruit, cur + 1); } else { map.put(fruit, 1); } } List<Integer> quantity = new ArrayList<Integer>(map.values()); Arrays.sort(prices); Collections.sort(quantity); long min = 0; long max = 0; for (int i = quantity.size() - 1, j = 0; i >= 0; i--, j++) { min += quantity.get(i) * prices[j]; max += quantity.get(i) * prices[n - j - 1]; } out.printf("%d %d", min, max); } } class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.parseInt(next()); } public long nextLong(){ return Long.parseLong(next()); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
e27eb15fee187a2ea08e34f32353de89
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.math.BigInteger; import java.util.Arrays; import java.util.HashMap; import java.util.LinkedList; import java.util.PriorityQueue; import java.util.Scanner; public class Main { static void sout(Object a){ System.out.print(a); } static boolean espal(String a){ int i=0,j=a.length()-1; while(i<j){ if(a.charAt(i)!=a.charAt(j))return false; i++;j--; } return true; } static class p implements Comparable<p>{ public String n; public int v; public p(String n, int v) { super(); this.n = n; this.v = v; } @Override public int compareTo(p o) { return v>=o.v?1:-1; } } static HashMap<String, Integer> map; static PriorityQueue<p> q; public static void main(String[] args) { Scanner n=new Scanner(System.in); int cas,frut; map=new HashMap<>(); q=new PriorityQueue<>(); cas=n.nextInt(); frut=n.nextInt(); int prec[]=new int[cas]; for (int i = 0; i < cas; i++) { prec[i]=n.nextInt(); } int c=0; int fr[]=new int[frut]; for(int i=0;i<frut;i++){ String f=n.next(); if(map.containsKey(f)){ fr[map.get(f)]++; }else { map.put(f,c); fr[map.get(f)]++; c++; } } Arrays.sort(prec); Arrays.sort(fr); int sum=0,sum1=0; for (int i = 0; i < c&&i<prec.length; i++) { //sout(fr[c-i]+" "+prec[i]+"\n"); sum+=fr[frut-i-1]*prec[i]; sum1+=fr[frut-i-1]*prec[prec.length-i-1]; } sout(sum+" "+sum1+"\n"); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
813a69bb3c205a180305567b570adbf0
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.io.InputStreamReader; import java.io.IOException; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.InputStream; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.Map; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); try (PrintWriter out = new PrintWriter(outputStream)) { TaskB solver = new TaskB(); solver.solve(1, in, out); } } } class TaskB { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int m = in.nextInt(); int prices[] = new int[n]; Map<String, Integer> foods = new HashMap<>(); for(int i = 0; i < n; ++i) prices[i] = in.nextInt(); Arrays.sort(prices); for(int i = 0; i < m; ++i){ String name = in.next(); if(foods.containsKey(name)) foods.put(name, foods.get(name) + 1); else foods.put(name, 1); } int counts[] = new int[foods.size()]; int ind = 0; for(Integer num : foods.values()){ counts[ind] = num; ind++; } Arrays.sort(counts); int min = 0, max = 0; int index = ind; for(int i = 0; i < ind; ++i) min += prices[i]*counts[index - i - 1]; for(int i = n - 1; i >= n - ind; --i){ index--; max += prices[i]*counts[index]; } out.println(min + " " + max); } } class InputReader { private final BufferedReader reader; private StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public String nextLine() { try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(nextLine()); } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public BigInteger nextBigInteger() { return new BigInteger(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
8b0aa0a10f1e2d7bd9ad151d9a4c0b31
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.io.*; import java.util.*; public class j { public static void main(String a[])throws IOException { BufferedReader b=new BufferedReader(new InputStreamReader(System.in)); int i=0,j=0,n=0,m=0,k=0; long v=0,u=0; String s; s=b.readLine(); StringTokenizer c=new StringTokenizer(s); n=Integer.parseInt(c.nextToken()); k=Integer.parseInt(c.nextToken()); int d[]=new int[n]; int e[]=new int[k]; e[0]=0; String f[]=new String[k]; s=b.readLine(); StringTokenizer z=new StringTokenizer(s); for(i=0;i<n;i++) d[i]=Integer.parseInt(z.nextToken()); for(i=0;i<k;i++) f[i]=b.readLine(); Arrays.sort(d); for(i=0;i<k;i++) { if(f[i].compareTo("#")==0) continue; else { e[m]++; for(j=i+1;j<k;j++) if(f[j].compareTo(f[i])==0) { e[m]++; f[j]="#"; } f[i]="#"; } m++; } int g[]=new int[m]; for(i=0;i<m;i++) g[i]=e[i]; Arrays.sort(g); for(i=0;i<m;i++) u+=g[m-1-i]*d[i]; for(i=0;i<m;i++) v+=g[m-1-i]*d[n-1-i]; System.out.print(u+" "+v); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
5ddcbe9d56f43fde57485e2b450aa1c8
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.util.Arrays; import java.util.HashMap; import java.util.StringTokenizer; public class Temp { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int n, m; n = Integer.parseInt(st.nextToken()); m = Integer.parseInt(st.nextToken()); int prices[]= new int[n]; st = new StringTokenizer(br.readLine()); for(int i=0; i<n;i++){ prices[i]= Integer.parseInt(st.nextToken()); } int items[]= new int[m]; int index=0; HashMap<String, Integer> mp = new HashMap<String, Integer>(); for(int i=0; i<m;i++){ String fruit = br.readLine().trim(); if(mp.containsKey(fruit)){ items[mp.get(fruit)]++; } else{ mp.put(fruit, index); items[index++] = 1; } } Arrays.sort(prices); items = Arrays.copyOfRange(items, 0, index); Arrays.sort(items); //System.out.println(Arrays.toString(prices)); //System.out.println(Arrays.toString(items)); int max=0, min=0; for(int i=0; i<index; i++){ max+= items[index-i-1]*prices[n-i-1]; min+= items[index-i-1]*prices[i]; } System.out.println(min+" "+max); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
3bf69eb359be055f63cedd0f2d70da6d
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.util.*; import java.io.*; public class Main implements Runnable { public void solve() throws IOException { int N = nextInt(); int m = nextInt(); int[] prices = new int[N]; for(int i= 0; i < N; i++) prices[i] = nextInt(); Arrays.sort(prices); Map<String, Integer> buys = new HashMap<>(); for(int i = 0; i < m; i++){ String fruit = nextToken(); if(buys.containsKey(fruit)){ buys.put(fruit, buys.get(fruit) + 1); } else{ buys.put(fruit, 1); } } int size = buys.size(); int[] qty = new int[size]; int index = 0; for(Map.Entry<String, Integer> me : buys.entrySet()){ qty[index++] = me.getValue(); } Arrays.sort(qty); int minimum = 0; for(int i = 0; i < size; i++) minimum += prices[i] * qty[size - i - 1]; int maximum = 0; index = 0; for(int i = prices.length - size; i < prices.length; i++) maximum += prices[i] * qty[index++]; System.out.println(minimum + " " + maximum); } //----------------------------------------------------------- public static void main(String[] args) { new Main().run(); } public void print1Int(int[] a){ for(int i = 0; i < a.length; i++) System.out.print(a[i] + " "); System.out.println(); } public void print2Int(int[][] a){ for(int i = 0; i < a.length; i++){ for(int j = 0; j < a[0].length; j++){ System.out.print(a[i][j] + " "); } System.out.println(); } } public void run() { try { in = new BufferedReader(new InputStreamReader(System.in)); tok = null; solve(); in.close(); } catch (IOException e) { System.exit(0); } } public String nextToken() throws IOException { while (tok == null || !tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); } return tok.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(nextToken()); } public long nextLong() throws IOException { return Long.parseLong(nextToken()); } public double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } BufferedReader in; StringTokenizer tok; }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
75f29bb825d9c394d6882416a9c69ab0
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.util.*; import java.math.*; import java.io.*; public class Main { public static void main(String[] argv) { Scanner in = new Scanner(new InputStreamReader(System.in)); int n = in.nextInt(); int m = in.nextInt(); int a[] = new int[n]; for(int i = 0 ; i < n ; i++) a[i] = in.nextInt(); Arrays.sort(a); HashMap<String, Integer> map = new HashMap<String,Integer>(); for(int i = 0 ; i < m ; i++) { String s = in.next(); if(map.containsKey(s)) { map.put(s, map.get(s)+1); } else { map.put(s, 1); } } int b[] = new int[map.size()]; int minc = 0 , maxc = 0; int cnt=0; Iterator it = map.keySet().iterator(); while(it.hasNext()) b[cnt++] = map.get(it.next()); Arrays.sort(b); for(int i = cnt-1 , j = 0 ,k=n-1; i >= 0 ; i--) { minc += b[i] * a[j++]; maxc += b[i] * a[k--]; } System.out.println(minc + " " + maxc); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
6ab27b5fc9d3d41aa8c8278fdb864540
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.util.*; public class Main{ public static void main(String[] args){ Scanner ss=new Scanner(System.in); int kinds=ss.nextInt(); int buy=ss.nextInt(); int[] price=new int[kinds]; String[] fruit=new String[buy]; for(int i=0;i<kinds;i++){ price[i]=ss.nextInt(); } for(int i=1;i<kinds;i++){ int flg=0; for(int j=0;j<(kinds-i);j++){ if(price[j]>price[j+1]){ int t=price[j]; price[j]=price[j+1]; price[j+1]=t; flg=1; } } if(flg==0){ break; } } ss.nextLine(); fruit[0]=ss.nextLine(); int[] ff=new int[buy]; ff[0]=1; int flg=0,count=1; for(int i=1;i<buy;i++){ fruit[i]=ss.nextLine(); flg=0; for(int j=0;j<i;j++){ if(fruit[i].equals(fruit[j])){ ff[j]++; flg++; break; } } if(flg==0){ ff[i]++; count++; } } int k=0; for(int i=0;i<buy;i++){ if(ff[i]>0)ff[k++]=ff[i]; } for(int i=1;i<count;i++){ int flag=0; for(int j=0;j<(count-i);j++){ if(ff[j]<ff[j+1]){ int t=ff[j]; ff[j]=ff[j+1]; ff[j+1]=t; flag=1; } } if(flag==0){ break; } } int min=0,max=0; for(int i=0;i<count;i++){ min+=(ff[i]*price[i]); max+=(ff[i]*price[kinds-i-1]); } System.out.println(min+" "+max); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
566994741540a1cbf72be1c2ca7fdfc9
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; import java.util.HashMap; public class Fruits { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); HashMap<String, Integer> map = new HashMap<String, Integer>(); String line[]; int n, m, prices[], fruits[]; String names[]; line = br.readLine().split(" "); n = Integer.parseInt(line[0]); m = Integer.parseInt(line[1]); line = br.readLine().split(" "); prices = new int[n]; names = new String[m]; for (int i = 0; i < n; i++) { prices[i] = Integer.parseInt(line[i]); } Arrays.sort(prices); int mapper = 0; String f; for (int i = 0; i < m; i++) { f = br.readLine(); names[i] = f; if (!map.containsKey(f)) { map.put(f, mapper); mapper++; } } fruits = new int[map.size()]; for (int i = 0; i < m; i++) { fruits[map.get(names[i])]++; } Arrays.sort(fruits); int min = 0, max = 0; int index_price_max = prices.length - 1; int index_price_min = 0; //int index_fruit = fruits.length-1; for (int i = fruits.length-1; i >= 0; i--) { max += fruits[i] * prices[index_price_max]; index_price_max--; min += fruits[i] * prices[index_price_min]; index_price_min++; } System.out.println(min+" "+max); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
b9d70fc0bc43342a538a32c9624758fa
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.util.*; import java.io.*; public class C0012 { public static void main(String args[]) throws Exception { new C0012(); } C0012() throws Exception { PandaScanner sc = null; PrintWriter out = null; try { sc = new PandaScanner(System.in); out = new PrintWriter(System.out); } catch (Exception ignored) { } int p = sc.nextInt(); int s = sc.nextInt(); int price[] = new int[p]; for (int i = 0; i < p; i++) { price[i] = sc.nextInt(); } Arrays.sort(price); String str[] = new String[s]; for (int i = 0; i < s; i++) { str[i] = sc.next(); } Arrays.sort(str); ArrayList<Integer> freq = new ArrayList<Integer>(); int currFreq = 1; for (int i = 1; i < s; i++) { if (str[i].compareTo(str[i - 1]) == 0) { currFreq++; } else { freq.add(currFreq); currFreq = 1; } } freq.add(currFreq); Collections.sort(freq); Collections.reverse(freq); int min = 0; int max = 0; for (int i = 0; i < freq.size(); i++) { min += freq.get(i) * price[i]; max += freq.get(i) * price[p - i - 1]; } out.println(min + " " + max); out.close(); System.exit(0); } //The PandaScanner class, for Panda fast scanning! public class PandaScanner { BufferedReader br; StringTokenizer st; InputStream in; PandaScanner(InputStream in) throws Exception { br = new BufferedReader(new InputStreamReader(this.in = in)); } public String next() throws Exception { if (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(br.readLine().trim()); return next(); } return st.nextToken(); } public boolean hasNext() throws Exception { return (st != null && st.hasMoreTokens()) || in.available() > 0; } public long nextLong() throws Exception { return Long.parseLong(next()); } public int nextInt() throws Exception { return Integer.parseInt(next()); } } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
dc07de49d1c99a27f94a487b53a67fac
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.util.Arrays; import java.util.Scanner; import java.util.HashMap; public class Codeforces { public static void main(String[] args) { Scanner entrada=new Scanner(System.in); HashMap hash=new HashMap(); int n,m; n=entrada.nextInt(); m=entrada.nextInt(); int[] arr=new int[n]; String[] f=new String[m]; for(int i=0;i<n;i++){ arr[i]=entrada.nextInt(); } Arrays.sort(arr); entrada.nextLine(); for(int i=0;i<m;i++){ String pal=entrada.nextLine(); int cont=0; if(hash.get(pal)!=null) cont=Integer.parseInt(hash.get(pal).toString()); cont++; hash.put(pal, cont); } int[] arr2=new int[hash.size()]; int ii=0; for ( Object value : hash.values()) { arr2[ii]=Integer.parseInt(value.toString()); ii++; } Arrays.sort(arr2); int min=0,max=0; for(int i=arr2.length-1;i>=0;i--){ min+=arr2[i]*arr[arr2.length-i-1]; } int j=arr.length-1; for(int i=arr2.length-1;i>=0;i--,j--){ max+=arr2[i]*arr[j]; } System.out.println(min+" "+max); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
30c93b3544e29eba5c546a84c44c61a1
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.StringTokenizer; public class Fruits { public static int t = 0; public static BufferedReader in; public static StringTokenizer st; public static String nextToken() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(in.readLine()); return st.nextToken(); } public static int nextInt() throws IOException { return Integer.parseInt(nextToken()); } public static Map<String,Integer> getSortedMapByValue(Map<String,Integer> map) { Map<String,Integer> sortedMap = null; List list = new LinkedList(map.entrySet()); Collections.sort(list, new Comparator() { public int compare (Object o1 , Object o2) { return ((Comparable) ((Map.Entry) (o1)).getValue()) .compareTo(((Map.Entry) (o2)).getValue()); } }); sortedMap = new LinkedHashMap(); for (Iterator it = list.iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); sortedMap.put((String)entry.getKey(), (int)entry.getValue()); } return sortedMap; } public static void main(String[] args) throws Exception { in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); int n = nextInt(); int m = nextInt(); int [] a = new int [n]; for(int i=0;i<a.length;i++) a[i]=nextInt(); Arrays.sort(a); Map<String, Integer> map = new HashMap<String, Integer>(); for(int i=0;i<m;i++) { String fruit =nextToken(); if(!map.containsKey(fruit)) map.put(fruit,1); else map.put(fruit,map.get(fruit)+1); } Map<String, Integer> sortedMap = getSortedMapByValue(map); int total = m; int [] b = new int[sortedMap.size()]; int k = 0; int min =0; int max = 0; for (String s : sortedMap.keySet()) { b[k]=sortedMap.get(s); k++; } for(int i=b.length-1,j=0;i>=0;i--,j++) { min+= b[i]*a[j]; } for(int i=b.length-1,j=a.length-1;i>=0;i--,j--) { max+=b[i]*a[j]; } out.println(min+" "+max); out.flush(); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
6a42ae1220f5844f794dfb0354f39880
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.HashMap; import java.util.Scanner; import java.util.StringTokenizer; public class magic2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int N = sc.nextInt(); int M = sc.nextInt(); int[] array = new int[N]; for(int a=0;a<N;a++)array[a]=sc.nextInt(); HashMap<String,Integer> HS = new HashMap<String,Integer>(); for(int a=0;a<M;a++){ String cur = sc.next(); int many = 0; if(HS.containsKey(cur)){ many = HS.get(cur); } HS.put(cur,many+1); } int[] MM = new int[HS.size()]; int thing = 0; for(String x : HS.keySet()){ MM[thing++]=-HS.get(x); } Arrays.sort(MM); Arrays.sort(array); //System.out.println(Arrays.toString(MM)); // System.out.println(Arrays.toString(array)); int low = 0; int high = 0; for(int a=0;a<HS.size();a++) low+=-MM[a]*array[a]; thing = 0; for(int a=N-1;a>=N-HS.size();a--) high+=-MM[thing++]*array[a]; out.println(low+" "+high); out.close(); } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(InputStream in) throws Exception { br = new BufferedReader(new InputStreamReader(in)); st = new StringTokenizer(br.readLine().trim()); } public int numTokens() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine().trim()); return numTokens(); } return st.countTokens(); } public boolean hasNext() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine().trim()); return hasNext(); } return true; } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine().trim()); return next(); } return st.nextToken(); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public float nextFloat() throws Exception { return Float.parseFloat(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public int nextInt() throws Exception { return Integer.parseInt(next()); } public String nextLine() throws Exception { return br.readLine(); } } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
2a856e70fbac14f585314be3eca93c85
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.util.*; import java.io.*; public class Main { static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); static StringBuilder out = new StringBuilder(); public static void main(String[] args){ int[] tmp = nextIntArray(); int n = tmp[0]; int m = tmp[1]; int[] tags = nextIntArray(); Arrays.sort(tags); int count[]=new int[m]; HashMap<String,Integer> list = new HashMap<String,Integer>(); for(int i=0;i<m;i++){ String fruit = nextLine(); if(list.containsKey(fruit)==true){ int v = list.get(fruit); list.put(fruit,v+1); } else{ list.put(fruit,1); } } Iterator<String> it = list.keySet().iterator(); int[] kind = new int[list.size()]; int k=0; while(it.hasNext()){ String fruit = it.next(); kind[k]=list.get(fruit); k++; } Arrays.sort(kind); int min=0; int j=0; for(int i=kind.length-1;0<=i;i--){ min+=kind[i]*tags[j]; j++; } int max=0; j=tags.length-1; for(int i=kind.length-1;0<=i;i--){ max+=kind[i]*tags[j]; j--; } System.out.println(min+" "+max); return; } // the followings are methods to take care of inputs. static int nextInt(){ return Integer.parseInt(nextLine()); } static long nextLong(){ return Long.parseLong(nextLine()); } static int[] nextIntArray(){ String[] inp = nextLine().split("\\s+"); int[] ary = new int[inp.length]; for (int i = 0; i < ary.length; i++){ ary[i] = Integer.parseInt(inp[i]); } return ary; } static int[] nextIntArrayFrom1(){ String[] inp = nextLine().split("\\s+"); int[] ary = new int[inp.length + 1]; for (int i = 0; i < inp.length; i++){ ary[i+1] = Integer.parseInt(inp[i]); } return ary; } static long[] nextLongArray(){ String[] inp = nextLine().split("\\s+"); long[] ary = new long[inp.length]; for (int i = 0; i < inp.length; i++){ ary[i] = Long.parseLong(inp[i]); } return ary; } static long[] nextLongArrayFrom1(){ String[] inp = nextLine().split("\\s+"); long[] ary = new long[inp.length + 1]; for (int i = 0; i < inp.length; i++){ ary[i+1] = Long.parseLong(inp[i]); } return ary; } static String nextLine(){ try { return reader.readLine().trim(); } catch (Exception e){} return null; } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
c54e2cb73321c31bfe9be5f6d7ebf603
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class Main { static Scanner si; public static void main(String[] args) { si = new Scanner(System.in); int n=si.nextInt(); int m=si.nextInt(); int max=0; int min=0; int[] n1=new int[n]; String [] m1=new String[m]; String temp; int count = 0; int c[]=new int[m]; for(int i=0;i<n;i++) {n1[i]=si.nextInt(); } for(int i=0;i<m;i++) {m1[i]=si.next(); } Arrays.sort(m1); temp=m1[0]; for(int i=0;i<m;i++) { if(m1[i].equals(temp)) {c[count]++; } if(i<m-1) {if(!m1[i+1].equals(temp)) { temp=m1[i+1]; count++; } } } Arrays.sort(c); Arrays.sort(n1); for(int i=0;i<=count;i++) { max= max+c[m-i-1]*n1[n1.length-i-1]; } for(int i=0;i<=count;i++) { min= min +c[m-i-1]*n1[i]; } System.out.println(min+" "+max); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
bb5ee172b90a5da6993916f1e13cf017
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.util.*; public class JavaApplication17 { /** * @param args the command line arguments */ static class valueComparator implements Comparator<String>{ Map<String,Integer> base; public valueComparator(Map<String,Integer> base) { this.base = base; } @Override public int compare(String a,String b){ if(base.get(a)>base.get(b)) return 1; else return -1; } } public static void main(String[] args) { // TODO code application logic here Scanner input=new Scanner(System.in); int min=0,max=0,j=0; int n=input.nextInt(); int m=input.nextInt(); int[] price=new int[n]; for(int i=0;i<n;i++) price[i]=input.nextInt(); Arrays.sort(price); Map<String,Integer> fruit=new HashMap<>(); valueComparator bvc = new valueComparator(fruit); TreeMap<String,Integer> sorted_map = new TreeMap<>(bvc); for(int i=1;i<=m;i++){ String s=input.next(); if(fruit.get(s)==null) fruit.put(s,1); else{ int val=fruit.get(s); val++; fruit.put(s,val); } } sorted_map.putAll(fruit); int x=fruit.size()-1; int y=fruit.size(); y=n-y; Set<Map.Entry<String,Integer>> entrySet=sorted_map.entrySet(); for(Map.Entry<String,Integer> entry:entrySet){ min+=entry.getValue()*price[x];x--; max+=entry.getValue()*price[y]; y++; } System.out.println(min); System.out.println(max); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
da9c48ca0f66e6ed29a49076e41843eb
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.io.*; import java.util.*; public class problem12C { public static void main (String[]args)throws IOException{ BufferedReader x = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(x.readLine()); int numtags=Integer.parseInt(st.nextToken()); int numfruits=Integer.parseInt(st.nextToken()); int[]prices=new int[numtags]; st=new StringTokenizer(x.readLine()); for (int i=0; i<numtags; i++){ prices[i]=Integer.parseInt(st.nextToken()); } Arrays.sort(prices); HashSet<String>distinctfruits=new HashSet<String>(); String[]fruits=new String[numfruits]; for (int i=0; i<numfruits; i++){ fruits[i]=x.readLine(); distinctfruits.add(fruits[i]); } Arrays.sort(fruits); int[]fruitcount=new int[distinctfruits.size()]; fruitcount[0]=1; int tempcounter=0; for (int i=1; i<numfruits; i++){ if (fruits[i].equals(fruits[i-1])){fruitcount[tempcounter]++;} else {tempcounter++;fruitcount[tempcounter]++;} } Arrays.sort(fruitcount); //fruitcount and prices are both in ascending order now //min is descending fruitcount, ascending prices //max is descending fruitcount, descending prices int min=0; for (int i=0; i<fruitcount.length; i++){ min=min+fruitcount[fruitcount.length-i-1]*prices[i]; } int max=0; for (int i=0; i<fruitcount.length; i++){ max=max+fruitcount[fruitcount.length-i-1]*prices[numtags-i-1]; } System.out.println(min+" "+max); System.exit(0); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
c76a4231b7f61321cbed04bfd1a4dc5e
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
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.math.BigInteger; import java.util.*; public class Codeforces implements Runnable { BufferedReader in; PrintWriter out; StringTokenizer tok = new StringTokenizer(""); void init() throws FileNotFoundException { try { in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); } catch (Throwable e) { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); } } String readString() throws IOException { while (!tok.hasMoreTokens()) { try { tok = new StringTokenizer(in.readLine()); } catch (Exception e) { return null; } } return tok.nextToken(); } int readInt() throws IOException { return Integer.parseInt(readString()); } int[] readIntArray(int size) throws IOException { int[] res = new int[size]; for (int i = 0; i < size; i++) { res[i] = readInt(); } return res; } long readLong() throws IOException { return Long.parseLong(readString()); } double readDouble() throws IOException { return Double.parseDouble(readString()); } public static void main(String[] args) { new Codeforces().run(); } long timeBegin, timeEnd; void time() { timeEnd = System.currentTimeMillis(); System.err.println("Time = " + (timeEnd - timeBegin)); } long memoryTotal, memoryFree; void memory() { memoryFree = Runtime.getRuntime().freeMemory(); System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10) + " KB"); } public void run() { try { timeBegin = System.currentTimeMillis(); memoryTotal = Runtime.getRuntime().freeMemory(); init(); solve(); out.close(); if (System.getProperty("ONLINE_JUDGE") == null) { time(); memory(); } } catch (Exception e) { e.printStackTrace(); System.exit(-1); } } int[] getPrimes(int max) { boolean[] prime = new boolean[max]; Arrays.fill(prime, true); prime[0] = prime[1] = false; int count = 0; for (int i = 2; i < max; i++) { if (prime[i]) { count++; for (int j = i * i; j < max; j += i) { prime[j] = false; } } } int[] result = new int[count]; int index = 0; for (int i = 2; i < max; i++) if (prime[i]) result[index++] = i; return result; } void solve() throws IOException { int n = readInt(); int m = readInt(); int[] a = readIntArray(n); Arrays.sort(a); HashMap<String, Integer> map = new HashMap<>(); for (int i=0;i<m;i++) { String key = readString(); Integer count = map.get(key); map.put(key, count == null ? 1 : count + 1); } int[] b = new int[map.size()]; int index = 0; for (Map.Entry<String, Integer> e : map.entrySet()) { b[index++] = e.getValue(); } Arrays.sort(b); for (int i=0;i<b.length/2;i++) { int t = b[i]; b[i] = b[b.length - 1 - i]; b[b.length - 1 - i] = t; } int min = 0; int max = 0; for (int i=0;i<b.length;i++) { min += a[i] * b[i]; } for (int i=0;i<b.length;i++) { max += a[n - 1 - i] * b[i]; } out.println(min + " " + max); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
6cbc63c6151c9853500377e7864c0217
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.lang.reflect.Constructor; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; import java.util.StringTokenizer; public class CodeE { static class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public String nextLine() { try { return br.readLine(); } catch(Exception e) { throw(new RuntimeException()); } } public String next() { while(!st.hasMoreTokens()) { String l = nextLine(); if(l == null) return null; st = new StringTokenizer(l); } return st.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public int[] nextIntArray(int n) { int[] res = new int[n]; for(int i = 0; i < res.length; i++) res[i] = nextInt(); return res; } public long[] nextLongArray(int n) { long[] res = new long[n]; for(int i = 0; i < res.length; i++) res[i] = nextLong(); return res; } public double[] nextDoubleArray(int n) { double[] res = new double[n]; for(int i = 0; i < res.length; i++) res[i] = nextDouble(); return res; } public void sortIntArray(int[] array) { Integer[] vals = new Integer[array.length]; for(int i = 0; i < array.length; i++) vals[i] = array[i]; Arrays.sort(vals); for(int i = 0; i < array.length; i++) array[i] = vals[i]; } public void sortLongArray(long[] array) { Long[] vals = new Long[array.length]; for(int i = 0; i < array.length; i++) vals[i] = array[i]; Arrays.sort(vals); for(int i = 0; i < array.length; i++) array[i] = vals[i]; } public void sortDoubleArray(double[] array) { Double[] vals = new Double[array.length]; for(int i = 0; i < array.length; i++) vals[i] = array[i]; Arrays.sort(vals); for(int i = 0; i < array.length; i++) array[i] = vals[i]; } public String[] nextStringArray(int n) { String[] vals = new String[n]; for(int i = 0; i < n; i++) vals[i] = next(); return vals; } public Integer nextInteger() { String s = next(); if(s == null) return null; return Integer.parseInt(s); } public int[][] nextIntMatrix(int n, int m) { int[][] ans = new int[n][]; for(int i = 0; i < n; i++) ans[i] = nextIntArray(m); return ans; } public char[][] nextGrid(int r) { char[][] grid = new char[r][]; for(int i = 0; i < r; i++) grid[i] = next().toCharArray(); return grid; } public static <T> T fill(T arreglo, int val) { if(arreglo instanceof Object[]) { Object[] a = (Object[]) arreglo; for(Object x : a) fill(x, val); } else if(arreglo instanceof int[]) Arrays.fill((int[]) arreglo, val); else if(arreglo instanceof double[]) Arrays.fill((double[]) arreglo, val); else if(arreglo instanceof long[]) Arrays.fill((long[]) arreglo, val); return arreglo; } <T> T[] nextObjectArray(Class <T> clazz, int size) { @SuppressWarnings("unchecked") T[] result = (T[]) java.lang.reflect.Array.newInstance(clazz, size); for(int c = 0; c < 3; c++) { Constructor <T> constructor; try { if(c == 0) constructor = clazz.getDeclaredConstructor(Scanner.class, Integer.TYPE); else if(c == 1) constructor = clazz.getDeclaredConstructor(Scanner.class); else constructor = clazz.getDeclaredConstructor(); } catch(Exception e) { continue; } try { for(int i = 0; i < result.length; i++) { if(c == 0) result[i] = constructor.newInstance(this, i); else if(c == 1) result[i] = constructor.newInstance(this); else result[i] = constructor.newInstance(); } } catch(Exception e) { throw new RuntimeException(e); } return result; } throw new RuntimeException("Constructor not found"); } public void printLine(int... vals) { if(vals.length == 0) System.out.println(); else { System.out.print(vals[0]); for(int i = 1; i < vals.length; i++) System.out.print(" ".concat(String.valueOf(vals[i]))); System.out.println(); } } public void printLine(long... vals) { if(vals.length == 0) System.out.println(); else { System.out.print(vals[0]); for(int i = 1; i < vals.length; i++) System.out.print(" ".concat(String.valueOf(vals[i]))); System.out.println(); } } public void printLine(double... vals) { if(vals.length == 0) System.out.println(); else { System.out.print(vals[0]); for(int i = 1; i < vals.length; i++) System.out.print(" ".concat(String.valueOf(vals[i]))); System.out.println(); } } public void printLine(int prec, double... vals) { if(vals.length == 0) System.out.println(); else { System.out.printf("%." + prec + "f", vals[0]); for(int i = 1; i < vals.length; i++) System.out.printf(" %." + prec + "f", vals[i]); System.out.println(); } } public Collection <Integer> wrap(int[] as) { ArrayList <Integer> ans = new ArrayList <Integer> (); for(int i : as) ans.add(i); return ans; } } static class Fruta implements Comparable <Fruta> { String nombre; int cuenta; Fruta(String n) { nombre = n; } @Override public int compareTo(Fruta o) { return (o.cuenta - cuenta); } } public static void main(String[] args) { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); LinkedList <Integer> preciosA = new LinkedList <Integer> (sc.wrap(sc.nextIntArray(n))); LinkedList <Integer> preciosB = new LinkedList <Integer> (preciosA); Collections.sort(preciosA); Collections.sort(preciosB, Collections.reverseOrder()); String[] frutas = sc.nextStringArray(m); HashMap <String, Fruta> map = new HashMap <String, Fruta> (); for(String s : frutas) { if(!map.containsKey(s)) map.put(s, new Fruta(s)); map.get(s).cuenta++; } ArrayList <Fruta> todasFrutas = new ArrayList <Fruta> (map.values()); Collections.sort(todasFrutas); int totalMin = 0; for(Fruta f : todasFrutas) totalMin += f.cuenta * preciosA.poll(); int totalMax = 0; for(Fruta f : todasFrutas) totalMax += f.cuenta * preciosB.poll(); sc.printLine(totalMin, totalMax); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
a3cc66a085e5f023d95ba523213daf37
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.util.*; import java.io.*; import java.math.BigDecimal; import java.math.BigInteger; public class Main { static void solve(InputReader in, OutputWriter out) throws IOException { // Scanner in = new Scanner(new BufferedReader(new // FileReader("input.txt"))); // PrintWriter out = new PrintWriter(new FileWriter("output.txt")); String s = in.readLine(); String [] split = s.split(" "); int n = Integer.parseInt(split[0]); int m = Integer.parseInt(split[1]); String k = in.readLine(); String [] splitter = k.split(" "); int [] r = new int[splitter.length]; for (int i =0; i < splitter.length; ++i) { r[i] = Integer.parseInt(splitter[i]); } Arrays.sort(r); String [] c = new String[m]; ArrayList<Integer> v = new ArrayList<Integer>(); for (int i = 0; i < m; ++i) { //String str = in.readLine(); c[i] = in.readLine(); //out.println(c[i]); } Arrays.sort(c); StringBuilder com = new StringBuilder(); com.append(c[0]); int count = 0; for (int i = 0; i < m; ++i) { StringBuilder x = new StringBuilder(); x.append(c[i]); //out.println(x + " " + com + " " + com.toString().equals(x.toString())); if(com.toString().equals(x.toString())) { count++; } else { v.add(count); count = 0; com = new StringBuilder(); com.append(x); if(com.toString().equals(x.toString())) { count++; } com = new StringBuilder(); com.append(c[i]); } } v.add(count); int [] res = new int[v.size()]; for (int i = 0; i < v.size(); ++i) { res[i] = v.get(i); } Arrays.sort(res); int min = 0; for (int i = 0, j = v.size() - 1; i < v.size(); ++i, --j) { min += (res[j] * r[i]); } int max = 0; for (int i = v.size() - 1, j = r.length - 1; i >= 0; --i, --j) { max += (res[i] * r[j]); } out.println(min + " " + max); } /*static boolean check(String[] a) { boolean c = true; for (int i = 0; ) }*/ public static void main(String[] args) throws Exception { InputReader in = new InputReader(System.in); OutputWriter out = new OutputWriter(System.out); try { solve(in, out); } catch (Exception e) { e.printStackTrace(System.out); } finally { out.close(); } } } class InputReader extends BufferedReader { public InputReader(InputStream in) { super(new InputStreamReader(in)); } } class OutputWriter extends PrintWriter { public OutputWriter(PrintStream out) { super(new BufferedWriter(new OutputStreamWriter(out))); } } /* * 6 ICPC.@bmail.com p+con+test@BMAIL.COM P@bmail.com a@bmail.com.ru * I.cpc@Bmail.Com a+b@bmail.com.ru * * 4 2 ICPC.@bmail.com I.cpc@Bmail.Com 2 p+con+test@BMAIL.COM P@bmail.com 1 * a@bmail.com.ru 1 a+b@bmail.com.ru */
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
5a521248383674bc762cde27fa14cbd8
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.io.*; import java.util.*; public class j { public static void main(String a[])throws IOException { BufferedReader b=new BufferedReader(new InputStreamReader(System.in)); int i=0,j=0,n=0,m=0,k=0; long v=0,u=0; String s; s=b.readLine(); StringTokenizer c=new StringTokenizer(s); n=Integer.parseInt(c.nextToken()); k=Integer.parseInt(c.nextToken()); int d[]=new int[n]; int e[]=new int[k]; e[0]=0; String f[]=new String[k]; s=b.readLine(); StringTokenizer z=new StringTokenizer(s); for(i=0;i<n;i++) d[i]=Integer.parseInt(z.nextToken()); for(i=0;i<k;i++) f[i]=b.readLine(); Arrays.sort(d); for(i=0;i<k;i++) { if(f[i].compareTo("#")==0) continue; else { e[m]++; for(j=i+1;j<k;j++) if(f[j].compareTo(f[i])==0) { e[m]++; f[j]="#"; } f[i]="#"; } m++; } int g[]=new int[m]; for(i=0;i<m;i++) g[i]=e[i]; Arrays.sort(g); for(i=0;i<m;i++) u+=g[m-1-i]*d[i]; for(i=0;i<m;i++) v+=g[m-1-i]*d[n-1-i]; System.out.print(u+" "+v); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
bf2657d3f446531456288e2d184a7557
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws java.lang.Exception { BufferedReader kek = new BufferedReader(new InputStreamReader(System.in)); //Scanner skek = new Scanner(System.in); PrintWriter outkek = new PrintWriter(System.out); int minRes = 0, maxRes = 0; String[] input = kek.readLine().split(" "); int N = Integer.parseInt(input[0]), M = Integer.parseInt(input[1]); input = kek.readLine().split(" "); int[] prices = new int[N]; Map<String, Integer> fruits = new HashMap<>(); for(int i = 0; i < N; i++){ prices[i] = Integer.parseInt(input[i]); } Arrays.sort(prices); for(int i = 0; i < M; i++){ String fruit = kek.readLine(); if(fruits.get(fruit) == null){ fruits.put(fruit, 1); } else { int val = fruits.get(fruit); val++; fruits.put(fruit, val); } } Integer[] uniqFruitsCnt = new Integer[fruits.size()]; fruits.values().toArray(uniqFruitsCnt); Arrays.sort(uniqFruitsCnt); for(int i = 0; i < fruits.size(); i++){ minRes += uniqFruitsCnt[fruits.size() - (i + 1)] * prices[i]; } for(int i = fruits.size() - 1; i >= 0; i--){ maxRes += uniqFruitsCnt[i] * prices[N - (fruits.size() - i)]; } outkek.println(minRes + " " + maxRes); kek.close(); outkek.close(); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
600bc75e705db1a03a6c61ee63c94097
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.util.Arrays; import java.util.HashMap; import java.util.Scanner; public class C12 { public static void main (String args[]){ Scanner in = new Scanner(System.in); int n = in.nextInt(); int m = in.nextInt(); int a[] = new int [n]; for (int i = 0 ; i < n ;i++){ a[i]=in.nextInt(); } Arrays.sort(a); HashMap<String, Integer> map = new HashMap<String,Integer>(); for(int i = 0 ; i < m ; i++){ String st = in.next(); if(map.containsKey(st)){ map.put(st, map.get(st)+1); } else { map.put(st, 1); } } int min= 0 ; int max = 0 ; int b[] = new int[map.size()]; int ind = 0 ; for(String s: map.keySet()){ b[ind++] = map.get(s); } Arrays.sort(b); ind = 0; int ind2 = a.length-1; for(int i = b.length-1 ; i >=0 ; i--){ min += b[i]*a[ind++]; max += b[i]*a[ind2--]; } System.out.println(min+" "+max); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
08f6697b0be3d6e28c42596de6b4a735
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.util.HashMap; import java.util.Arrays; public class FRUITS { public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String brr[]=br.readLine().trim().split(" "); HashMap map=new HashMap<String,Integer>(); int j=0; int n=Integer.parseInt(brr[0]); int m=Integer.parseInt(brr[1]); brr=br.readLine().trim().split(" "); int arr[]=new int[n]; int crr[]=new int[m]; int i,k; for(i=0;i<m;i++) crr[i]=1; for(i=0;i<n;i++) { arr[i]=Integer.parseInt(brr[i]); } for(i=0;i<m;i++) { brr=br.readLine().trim().split(" "); if(!map.containsKey(brr[0])) { map.put(brr[0], j); j++; } else { k=(int) map.get(brr[0]); crr[k]++; } } for(i=j;i<m;i++) crr[i]=1005; Arrays.sort(arr); Arrays.sort(crr); //for(i=0;i<n;i++) // System.out.println(arr[i]); //for(i=0;i<j;i++) // System.out.println(crr[i]); int z=0,min=0,max=0; //System.out.println(j); for(i=j-1;i>=0;i--) { min+=crr[i]*arr[z]; max+=crr[i]*arr[n-z-1]; // System.out.println(min+" "+max); z++; } System.out.println(min+" "+max); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
f0c95914e16041e88b87ad31eb6b84b6
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.StringTokenizer; public class Fruits { public static void main(String[] args) throws IOException { BufferedReader f = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(f.readLine()); int n = Integer.parseInt(st.nextToken()); int m = Integer.parseInt(st.nextToken()); int[] a = new int[n]; st = new StringTokenizer(f.readLine()); for (int i = 0; i < n; i++) a[i] = Integer.parseInt(st.nextToken()); Arrays.sort(a); HashMap<String,Integer> hm = new HashMap<String,Integer>(); for (int i = 0; i < m; i++) { String str = f.readLine(); if (hm.containsKey(str)) hm.put(str, hm.get(str)+1); else hm.put(str,1); } int[] b = new int[n]; int index = 0; Iterator it = hm.entrySet().iterator(); while (it.hasNext()) { Map.Entry pairs = (Map.Entry)it.next(); b[index++] = (int) pairs.getValue(); it.remove(); } Arrays.sort(b); int min = 0; for (int i = 0; i < n; i++) min += a[i]*b[n-1-i]; int max = 0; for (int i = 0; i < n; i++) max += a[i]*b[i]; System.out.println(min+" "+max); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
b78706a7a35a92b57c3e0b046244a722
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class Main { static Scanner si; public static void main(String[] args) { si = new Scanner(System.in); int n=si.nextInt(); int m=si.nextInt(); int max=0; int min=0; int[] n1=new int[n]; String [] m1=new String[m]; String temp; int count = 0; int c[]=new int[m]; for(int i=0;i<n;i++) {n1[i]=si.nextInt(); } for(int i=0;i<m;i++) {m1[i]=si.next(); } Arrays.sort(m1); temp=m1[0]; for(int i=0;i<m;i++) { if(m1[i].equals(temp)) {c[count]++; } if(i<m-1) {if(!m1[i+1].equals(temp)) { temp=m1[i+1]; count++; } } } Arrays.sort(c); Arrays.sort(n1); for(int i=0;i<=count;i++) { max= max+c[m-i-1]*n1[n1.length-i-1]; } for(int i=0;i<=count;i++) { min= min +c[m-i-1]*n1[i]; } System.out.println(min+" "+max); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
51352039c64af5190082d2c6df4c264b
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; public class Main12C { private FastScanner in; private PrintWriter out; public void solve() throws IOException { int N = in.nextInt(); int M = in.nextInt(); int[] prices = new int[N]; for(int i = 0; i < N; i++){ prices[i] = in.nextInt(); } Map<String, Integer> fruits = new HashMap<String, Integer>(); for(int i = 0; i < M; i++){ String fruit = in.next(); Integer count = fruits.get(fruit); if(count == null){ fruits.put(fruit, 1); } else{ fruits.put(fruit, count + 1); } } int[] counts = new int[fruits.keySet().size()]; int i = 0; for(Integer count : fruits.values()){ counts[i] = count; i++; } Arrays.sort(prices); Arrays.sort(counts); int min = 0; int max = 0; for(i = 0; i < counts.length; i++){ min += counts[counts.length - i - 1] * prices[i]; max += counts[counts.length - i - 1] * prices[N - i - 1]; } out.print(min + " " + max); } public void run() { try { in = new FastScanner(System.in); out = new PrintWriter(System.out); solve(); out.close(); } catch (IOException e) { e.printStackTrace(); } } class FastScanner { BufferedReader br; StringTokenizer st; FastScanner(InputStream is) { br = new BufferedReader(new InputStreamReader(is)); } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } public static void main(String[] arg) { new Main12C().run(); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
eb492d2200b6c27d1cfe41f73f8a0fed
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
//package threadpractice; import java.text.DecimalFormat; import java.util.*; import java.io.*; public class Main { public static void main(String args[]) { try { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s[] = br.readLine().split(" "); String nS[] = br.readLine().split(" "); int n[] = new int[nS.length]; for(int i = 0;i<n.length;i++){ n[i] = Integer.parseInt(nS[i]); } Arrays.sort(n); HashMap <String,Integer> hm = new HashMap(); Integer m = Integer.parseInt(s[1]); while(m>0){ String temp = br.readLine(); if(hm.containsKey(temp)){ int i = hm.get(temp); hm.put(temp, i+1); } else{ hm.put(temp, 1); } m--; } int count[] = new int[hm.size()]; int i = 0; for(Iterator I = hm.keySet().iterator();I.hasNext();){ String temp = (String)I.next(); count[i++] = hm.get(temp); } Arrays.sort(count); int sum = 0; i = count.length-1; int k = 0; while(i>=0){ sum += count[i--]*n[k++]; } int sum1 = 0; i = count.length-1; k = n.length-1; while(i>=0){ sum1 += count[i--]*n[k--]; } System.out.println(sum+" "+sum1); } catch (Exception e) { e.printStackTrace(); } } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
1b3ad3afb0137cbe2c64b2d46a29b623
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int m = in.nextInt(); int V[] = new int[n]; int N[] = new int[n]; for (int i = 0; i < n; i++) { V[i] = in.nextInt(); } Arrays.sort(V); String R[] = new String[m]; for (int i = 0; i < m; i++) { R[i] = in.next(); } int c, d = 0; boolean vis[] = new boolean[m]; for (int i = 0; i < m; i++) { c = 1; if (!vis[i]) { for (int j = i + 1; j < m; j++) { if (R[i].equals(R[j])) { vis[j] = true; c++; } } N[d] = c; d++; } } for (int i = d; i < n; i++) { N[i] = -1; } Arrays.sort(N); N = Rev(N); int min = 0; for (int i = 0; i < N.length; i++) { if (N[i] != -1) { int rpta = N[i] * V[i]; min += rpta; } } Arrays.sort(N); int max = 0; for (int i = 0; i < N.length; i++) { if (N[i] != -1) { int rpta = N[i] * V[i]; max += rpta; } } System.out.println(min + " " + max); } public static int[] Rev(int A[]) { int B[] = new int[A.length]; int c = 0; for (int i = A.length - 1; i >= 0; i--) { B[c] = A[i]; c++; } return B; } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
6f3120d2fa3d1dd2e526f3665a664f68
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.Scanner; public class problem12C { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int[] arr = new int[n]; for(int i=0;i<n;i++) arr[i] = sc.nextInt(); /* String[] name = new String[m]; for(int i=0;i<m;i++) name[i] = sc.next(); */ HashMap<String, Integer> hash = new HashMap<>(); for(int i=0;i<m;i++){ String str = sc.next(); if(hash.containsKey(str)){ hash.put(str, hash.get(str)+1); } else hash.put(str, 1); } Arrays.sort(arr); int[] val = new int[hash.size()]; Iterator<String> it = hash.keySet().iterator(); int ii=0; while(it.hasNext()){ String key = it.next(); val[ii] = hash.get(key); ii++; } Arrays.sort(arr); Arrays.sort(val); int min = 0, max = 0; for(int i=0;i<hash.size();i++){ min = min + (arr[i]*val[hash.size()-i-1]); } int cnt = 0; for(int i=n-1;i>=n-hash.size();i--){ max = max + (arr[i]*val[hash.size()-1-cnt]); cnt++; } System.out.println(min+" "+max); /* int min = 0, max = 0; for(int i=0;i<m;i++) min+= arr[i]; for(int i=n-1;i>=n-m;i--) max += arr[i]; System.out.println(min+" "+max); */ } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
d49c45e1749e800f8a86ee52bc692aa5
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.util.Arrays; import java.util.ArrayList; import java.io.InputStream; import java.io.InputStreamReader; import java.util.HashMap; import java.util.List; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Collections; import java.io.IOException; import java.util.Set; import java.util.StringTokenizer; /** * Built using CHelper plug-in * Actual solution is at the top * @author nasko */ 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); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } } class TaskC { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int m = in.nextInt(); HashMap<String,Integer> hm = new HashMap<String,Integer>(); int[] price = new int[n]; for(int i = 0; i < n; ++i) price[i] = in.nextInt(); Arrays.sort(price); ArrayList<Integer> count = new ArrayList<Integer>(); for(int i = 0; i < m; ++i) { String name = in.nextLine(); if(!hm.containsKey(name)) hm.put(name,1); else hm.put(name,hm.get(name)+1); } for(String s : hm.keySet()) { int get = hm.get(s); count.add(get); } Collections.sort(count); int min = 0; int max = 0; int id = 0; int id2 = price.length - 1; for(int i = count.size() - 1; i >= 0; --i) { min += count.get(i)*price[id++]; max += count.get(i)*price[id2--]; } out.println(min + " " + max); } } class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public String nextLine() { String s = null; try { s = reader.readLine(); } catch (IOException e) { e.printStackTrace(); } return s; } public int nextInt() { return Integer.parseInt(next()); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
2b6b91026233e5889cd3b0153099a19c
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.io.InputStreamReader; import java.io.IOException; import java.util.Arrays; import java.util.Set; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.util.HashSet; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author nasko */ 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); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } } class TaskC { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int m = in.nextInt(); int[] prices = new int[n]; for(int i = 0; i < n; ++i) { prices[i] = in.nextInt(); } Arrays.sort(prices); String[] products = new String[m]; Set<String> hs = new HashSet<String>(); for(int i = 0; i < m; ++i) { products[i] = in.nextLine(); hs.add(products[i]); } int[] cnt = new int[hs.size()]; Arrays.fill(cnt,0); int cur = 0; for(String s : hs) { int temp = 0; for(int i = 0; i < products.length; ++i) { if(s.equals(products[i])) { ++temp; } } cnt[cur++] = temp; } Arrays.sort(cnt); int min = 0; int max = 0; int start = 0; for(int i = cnt.length-1;i>=0;--i) { min += cnt[i] * prices[start++]; } start = prices.length-1; for(int i = cnt.length-1;i>=0;--i) { max += cnt[i] * prices[start--]; } out.println(min + " " + max); } } class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public String nextLine() { String s = null; try { s = reader.readLine(); } catch (IOException e) { e.printStackTrace(); } return s; } public int nextInt() { return Integer.parseInt(next()); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
b0a45998f9ca1a7c7a96cae95c04ab6a
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Scanner; public class Fruits { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int m = in.nextInt(); List<Integer> prices = new LinkedList<Integer>(); Map<String, Integer> fruits = new HashMap<String, Integer>(m); for (int i = 0; i < n; i++) prices.add(in.nextInt()); in.nextLine(); for (int i = 0; i < m; i++) { String fruit = in.nextLine(); int count = fruits.containsKey(fruit) ? fruits.get(fruit) : 0; fruits.put(fruit, count + 1); } in.close(); Collections.sort(prices); fruits = MapUtil.reverseSortByValue(fruits); int minPrice = 0, maxPrice = 0, i = 0; for (Integer nf : fruits.values()) { minPrice += prices.get(i) * nf; maxPrice += prices.get(prices.size() - i - 1) * nf; i++; } System.out.println(minPrice + " " + maxPrice); } } class MapUtil { public static <K, V extends Comparable<? super V>> Map<K, V> reverseSortByValue( Map<K, V> map ) { List<Map.Entry<K, V>> list = new LinkedList<Map.Entry<K, V>>( map.entrySet() ); Collections.sort( list, new Comparator<Map.Entry<K, V>>() { public int compare( Map.Entry<K, V> o1, Map.Entry<K, V> o2 ) { return (o2.getValue()).compareTo( o1.getValue() ); } } ); Map<K, V> result = new LinkedHashMap<K, V>(); for (Map.Entry<K, V> entry : list) { result.put( entry.getKey(), entry.getValue() ); } return result; } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
ab5a533f8f0fbbcbcba368ade8cc701d
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.util.Scanner; /** * * @author IR_HAM */ public class Fruits { public static void main(String [] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int m = in.nextInt(); int [] price = new int[n]; for(int i = 0; i < n; i++) price[i] = in.nextInt(); String [] fruit = new String[m]; for(int i = 0; i < m; i++) fruit[i] = in.next(); for(int i = 0; i < n; i++) { int k = i; for(int j = i; j < n; j++) if(price[k] > price[j]) k = j; int c = price[i]; price[i] = price[k]; price[k] = c; } int [] amount = new int[m]; boolean [] flag = new boolean[m]; int l = 0; for(int i = 0; i < m; i++) { if(!flag[i]) { for(int j = i; j < m; j++) if(fruit[j].equals(fruit[i])) { amount[l]++; flag[j] = true; } l++; } } for(int i = 0; i < l; i++) { int k = i; for(int j = i; j < l; j++) if(amount[k] < amount[j]) k = j; int c = amount[i]; amount[i] = amount[k]; amount[k] = c; } int min = 0; for(int i = 0; i < l && i < n; i++) min += price[i] * amount[i]; int max = 0; for(int i = 0; i < l && i < n; i++) max += price[n - i - 1] * amount[i]; System.out.println(min + " " + max); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
7dbccf55e7db268275d863107b90d3f2
train_003.jsonl
1272538800
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags).
256 megabytes
//package codeforces.ru.task_12C; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Scanner; /** * Created by myduomilia on 14.10.14. */ public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int m = scanner.nextInt(); Map<String, Integer> map = new HashMap<>(); int a[] = new int[n]; for(int i = 0; i < n; i++) a[i] = scanner.nextInt(); for(int i = 0; i < m; i++){ String key = scanner.next(); if(!map.containsKey(key)) map.put(key, 1); else map.put(key, map.get(key) + 1); } Arrays.sort(a); int min = 0, max = 0; int ind = 0; int arr[] = new int[map.size()]; for(Map.Entry<String, Integer> entry : map.entrySet()){ arr[ind] = entry.getValue(); ind++; } Arrays.sort(arr); for(int i = arr.length - 1; i >= 0; i--) min += arr[i] * a[arr.length - i - 1]; for(int i = arr.length - 1; i >= 0; i--) max += arr[i] * a[a.length - (arr.length - i - 1) - 1]; System.out.println(min + " " + max); scanner.close(); } }
Java
["5 3\n4 2 1 10 5\napple\norange\nmango", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange"]
1 second
["7 19", "11 30"]
null
Java 7
standard input
[ "implementation", "sortings", "greedy" ]
31c43b62784a514cfdb9ebb835e94cad
The first line of the input contains two integer number n and m (1 ≀ n, m ≀ 100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
1,100
Print two numbers a and b (a ≀ b) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
standard output
PASSED
751baf54f19e972463a121a0ebfb9e47
train_003.jsonl
1461515700
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
256 megabytes
/** * Created by yume on 2016/5/27. */ import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; public class Main { public static void main(final String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(in, out); out.close(); } static class TaskA { public void solve(InputReader in, PrintWriter out) { int h = in.nextInt(); int w = in.nextInt(); int q = in.nextInt(); int[] t = new int[q]; int[] r = new int[q]; int[] c = new int[q]; int[] x = new int[q]; for (int i = 0; i < q; i++) { t[i] = in.nextInt(); switch (t[i]) { case 1: r[i] = in.nextInt() - 1; break; case 2: c[i] = in.nextInt() - 1; break; case 3: r[i] = in.nextInt() - 1; c[i] = in.nextInt() - 1; x[i] = in.nextInt(); break; } } // make answer matrix int[][] matrix = new int[h][w]; for (int i = 0; i < q; i++) { if (t[i] == 3) { int curR = r[i]; int curC = c[i]; for (int j = i; j >= 0; j--) { if (t[j] == 1 && r[j] == curR) { curC = (curC + 1) % w; } else if (t[j] == 2 && c[j] == curC) { curR = (curR + 1) % h; } } matrix[curR][curC] = x[i]; } } // print answer for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (j != 0) out.print(" "); out.print(matrix[i][j]); } out.println(); } } } static class InputReader { private final BufferedReader buffer; private StringTokenizer tok; InputReader(InputStream stream) { buffer = new BufferedReader(new InputStreamReader(stream), 32768); } private boolean haveNext() { while (tok == null || !tok.hasMoreElements()) { try { tok = new StringTokenizer(buffer.readLine()); } catch (final Exception e) { throw new RuntimeException(e); } } return true; } protected String next() { if (haveNext()) { return tok.nextToken(); } return null; } protected String nextLine() { if (haveNext()) { return tok.nextToken("\n"); } return null; } protected int nextInt() { return Integer.parseInt(next()); } protected long nextLong() { return Long.parseLong(next()); } protected double nextDouble() { return Double.parseDouble(next()); } } }
Java
["2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8", "3 3 2\n1 2\n3 2 2 5"]
2 seconds
["8 2 \n1 8", "0 0 0 \n0 0 5 \n0 0 0"]
null
Java 8
standard input
[ "implementation" ]
f710958b96d788a19a1dda436728b9eb
The first line of the input contains three integers n, m and q (1 ≀ n, m ≀ 100, 1 ≀ q ≀ 10 000)Β β€” dimensions of the matrix and the number of turns in the experiment, respectively. Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≀ ti ≀ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≀ ri ≀ n) or ci (1 ≀ ci ≀ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≀ ri ≀ n, 1 ≀ ci ≀ m,  - 109 ≀ xi ≀ 109) are given. Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
1,400
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value. If there are multiple valid solutions, output any of them.
standard output
PASSED
941ef1a7d4347344b127e0fe90b37b4f
train_003.jsonl
1461515700
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Scanner; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Rene */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } static class TaskA { public void solve(int testNumber, Scanner in, PrintWriter out) { int rows = in.nextInt(); int cols = in.nextInt(); int turns = in.nextInt(); int[][] mat = new int[rows][cols]; for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { mat[r][c] = r * cols + c; } } int[][] result = new int[rows][cols]; for (int i = 0; i < turns; i++) { int type = in.nextInt(); if (type == 1) { int r = in.nextInt() - 1; int first = mat[r][0]; for (int j = 1; j < cols; j++) mat[r][j - 1] = mat[r][j]; mat[r][cols - 1] = first; } else if (type == 2) { int c = in.nextInt() - 1; int first = mat[0][c]; for (int j = 1; j < rows; j++) mat[j - 1][c] = mat[j][c]; mat[rows - 1][c] = first; } else { int r = in.nextInt() - 1; int c = in.nextInt() - 1; int x = in.nextInt(); int v = mat[r][c]; result[v / cols][v % cols] = x; } } for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { out.print(result[r][c]); if (c + 1 < cols) out.print(" "); } out.println(); } } } }
Java
["2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8", "3 3 2\n1 2\n3 2 2 5"]
2 seconds
["8 2 \n1 8", "0 0 0 \n0 0 5 \n0 0 0"]
null
Java 8
standard input
[ "implementation" ]
f710958b96d788a19a1dda436728b9eb
The first line of the input contains three integers n, m and q (1 ≀ n, m ≀ 100, 1 ≀ q ≀ 10 000)Β β€” dimensions of the matrix and the number of turns in the experiment, respectively. Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≀ ti ≀ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≀ ri ≀ n) or ci (1 ≀ ci ≀ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≀ ri ≀ n, 1 ≀ ci ≀ m,  - 109 ≀ xi ≀ 109) are given. Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
1,400
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value. If there are multiple valid solutions, output any of them.
standard output
PASSED
1b28233ac0ef57610ca9416e838c8b79
train_003.jsonl
1461515700
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
256 megabytes
// practice with rainboy import java.io.*; import java.util.*; public class CF668A extends PrintWriter { CF668A() { super(System.out, true); } Scanner sc = new Scanner(System.in); public static void main(String[] $) { CF668A o = new CF668A(); o.main(); o.flush(); } void main() { int n = sc.nextInt(); int m = sc.nextInt(); int q = sc.nextInt(); int[] tt = new int[q]; int[] rr = new int[q]; int[] cc = new int[q]; int[] xx = new int[q]; for (int h = 0; h < q; h++) { tt[h] = sc.nextInt(); if (tt[h] == 1) rr[h] = sc.nextInt() - 1; else if (tt[h] == 2) cc[h] = sc.nextInt() - 1; else { rr[h] = sc.nextInt() - 1; cc[h] = sc.nextInt() - 1; xx[h] = sc.nextInt(); } } int[][] aa = new int[n][m]; for (int h = q - 1; h >= 0; h--) if (tt[h] == 1) { int i = rr[h]; int a = aa[i][m - 1]; for (int j = m - 1; j > 0; j--) aa[i][j] = aa[i][j - 1]; aa[i][0] = a; } else if (tt[h] == 2) { int j = cc[h]; int a = aa[n - 1][j]; for (int i = n - 1; i > 0; i--) aa[i][j] = aa[i - 1][j]; aa[0][j] = a; } else { int i = rr[h]; int j = cc[h]; aa[i][j] = xx[h]; } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) print(aa[i][j] + " "); println(); } } }
Java
["2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8", "3 3 2\n1 2\n3 2 2 5"]
2 seconds
["8 2 \n1 8", "0 0 0 \n0 0 5 \n0 0 0"]
null
Java 8
standard input
[ "implementation" ]
f710958b96d788a19a1dda436728b9eb
The first line of the input contains three integers n, m and q (1 ≀ n, m ≀ 100, 1 ≀ q ≀ 10 000)Β β€” dimensions of the matrix and the number of turns in the experiment, respectively. Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≀ ti ≀ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≀ ri ≀ n) or ci (1 ≀ ci ≀ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≀ ri ≀ n, 1 ≀ ci ≀ m,  - 109 ≀ xi ≀ 109) are given. Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
1,400
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value. If there are multiple valid solutions, output any of them.
standard output
PASSED
9d1117cf69fefe8dc1e132fe46e55700
train_003.jsonl
1461515700
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
256 megabytes
import java.util.ArrayList; import java.util.Scanner; public class ProblemA { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); int n = input.nextInt(); int m = input.nextInt(); int q = input.nextInt(); int[][] arr = new int[n][m]; for (int a = 0; a < n; a++) { for (int b = 0; b < m; b++) { arr[a][b] = Integer.MAX_VALUE; } } ArrayList<Integer>[] arr2 = new ArrayList[q]; for (int a = 0; a < q; a++) { arr2[a] = new ArrayList<Integer>(); int type = input.nextInt(); arr2[a].add(type); if (type == 3) { arr2[a].add(input.nextInt()); arr2[a].add(input.nextInt()); arr2[a].add(input.nextInt()); } else { arr2[a].add(input.nextInt()); } } for (int a = q - 1; a >= 0; a--) { int type = arr2[a].get(0); if (type == 1) { int rowRotate = arr2[a].get(1) - 1; int temp = arr[rowRotate][m - 1]; for (int column = m - 1; column > 0; column--) { arr[rowRotate][column] = arr[rowRotate][column - 1]; } arr[rowRotate][0] = temp; } if (type == 2) { int columnRotate = arr2[a].get(1) - 1; int temp = arr[n - 1][columnRotate]; for (int row = n - 1; row > 0; row--) { arr[row][columnRotate] = arr[row - 1][columnRotate]; } arr[0][columnRotate] = temp; } if (type == 3) { int x = arr2[a].get(1) - 1; int y = arr2[a].get(2) - 1; int val = arr2[a].get(3); arr[x][y] = val; } } for (int a = 0; a < n; a++) { for (int b = 0; b < m; b++) { if (arr[a][b] > 2000000000) { System.out.print(0 + " "); } else { System.out.print(arr[a][b] + " "); } } System.out.println(); } } }
Java
["2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8", "3 3 2\n1 2\n3 2 2 5"]
2 seconds
["8 2 \n1 8", "0 0 0 \n0 0 5 \n0 0 0"]
null
Java 8
standard input
[ "implementation" ]
f710958b96d788a19a1dda436728b9eb
The first line of the input contains three integers n, m and q (1 ≀ n, m ≀ 100, 1 ≀ q ≀ 10 000)Β β€” dimensions of the matrix and the number of turns in the experiment, respectively. Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≀ ti ≀ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≀ ri ≀ n) or ci (1 ≀ ci ≀ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≀ ri ≀ n, 1 ≀ ci ≀ m,  - 109 ≀ xi ≀ 109) are given. Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
1,400
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value. If there are multiple valid solutions, output any of them.
standard output
PASSED
eb5fb79374bdbfb92f7a82d4f1f0231d
train_003.jsonl
1461515700
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
256 megabytes
import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.util.StringTokenizer; import java.io.InputStream; import java.io.InputStreamReader; /** * 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); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } } class TaskA { public static class Element { public int x, y; public int val; public Element(int x, int y, int val) { this.x = x; this.y = y; this.val = val; } } public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); int m = in.nextInt(); int q = in.nextInt(); Element[][] a = new Element[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { a[i][j] = new Element(i, j, 0); } } for (int i = 0; i < q; i++) { int type = in.nextInt(); if (type == 1) { int r = in.nextInt() - 1; shift(a, r, 0, 0, -1, n, m); } else if (type == 2) { int c = in.nextInt() - 1; shift(a, 0, c, -1, 0, n, m); } else { int r = in.nextInt() - 1; int c = in.nextInt() - 1; int x = in.nextInt(); a[r][c].val = x; } } int[][] sol = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { sol[a[i][j].x][a[i][j].y] = a[i][j].val; } } for (int i=0; i<n; i++){ for (int j=0; j<m; j++){ out.print(sol[i][j] + " "); } out.println(); } } private void shift(Element[][] a, int r, int c, int dx, int dy, int n, int m) { int oR = r; int oC = c; Element e = a[r][c]; do { int newR = (r - dx + n) % n; int newC = (c - dy + m) % m; a[r][c] = a[newR][newC]; r = newR; c = newC; } while (r != oR || c != oC); int newR = (r + dx + n) % n; int newC = (c + dy + m) % m; a[newR][newC] = e; } } class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream){ reader = new BufferedReader(new InputStreamReader(stream)); } public String next(){ while (tokenizer == null || !tokenizer.hasMoreTokens()){ try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException("FATAL ERROR", e); } } return tokenizer.nextToken(); } public int nextInt(){ return Integer.valueOf(next()); } }
Java
["2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8", "3 3 2\n1 2\n3 2 2 5"]
2 seconds
["8 2 \n1 8", "0 0 0 \n0 0 5 \n0 0 0"]
null
Java 8
standard input
[ "implementation" ]
f710958b96d788a19a1dda436728b9eb
The first line of the input contains three integers n, m and q (1 ≀ n, m ≀ 100, 1 ≀ q ≀ 10 000)Β β€” dimensions of the matrix and the number of turns in the experiment, respectively. Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≀ ti ≀ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≀ ri ≀ n) or ci (1 ≀ ci ≀ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≀ ri ≀ n, 1 ≀ ci ≀ m,  - 109 ≀ xi ≀ 109) are given. Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
1,400
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value. If there are multiple valid solutions, output any of them.
standard output
PASSED
ae35a6099a0a885382595d5e16b165f0
train_003.jsonl
1461515700
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
256 megabytes
import java.util.*; import java.io.*; public class A { public static void main(String[] args) throws Exception { FastScanner in = new FastScanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(); int m = in.nextInt(); int qs = in.nextInt(); Query[] queries = new Query[qs]; for(int x = 0; x < qs; x++) { int type = in.nextInt(); if(type == 1) { queries[x] = new Query(type, in.nextInt() - 1, -1, -1); } else if(type == 2) { queries[x] = new Query(type, -1, in.nextInt() - 1, -1); } else { queries[x] = new Query(type, in.nextInt() - 1, in.nextInt() - 1, in.nextInt()); } } int[][] matrix = new int[n][m]; for(int y = queries.length - 1; y >= 0; y--) { Query q = queries[y]; if(q.type == 1) { int temp = matrix[q.row][matrix[0].length - 1]; for(int z = matrix[0].length - 2; z >= 0; z--) { matrix[q.row][z + 1] = matrix[q.row][z]; } matrix[q.row][0] = temp; } else if(q.type == 2) { int temp = matrix[matrix.length - 1][q.col]; for(int a = matrix.length - 2; a >= 0; a--) { matrix[a + 1][q.col] = matrix[a][q.col]; } matrix[0][q.col] = temp; } else { matrix[q.row][q.col] = q.val; } } for(int z = 0; z < matrix.length; z++) { for(int a = 0; a < matrix[0].length; a++) { if(a > 0) { out.print(" "); } out.print(matrix[z][a]); } out.println(); } out.close(); } static class Query { int type; int row; int col; int val; public Query(int t, int r, int c, int v) { type = t; row = r; col = c; val = v; } } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(InputStream input) { br = new BufferedReader(new InputStreamReader(input)); st = new StringTokenizer(""); } public String next() throws IOException { if(st.hasMoreTokens()) { return st.nextToken(); } else { st = new StringTokenizer(br.readLine()); return next(); } } public int nextInt() throws IOException { return Integer.parseInt(next()); } } }
Java
["2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8", "3 3 2\n1 2\n3 2 2 5"]
2 seconds
["8 2 \n1 8", "0 0 0 \n0 0 5 \n0 0 0"]
null
Java 8
standard input
[ "implementation" ]
f710958b96d788a19a1dda436728b9eb
The first line of the input contains three integers n, m and q (1 ≀ n, m ≀ 100, 1 ≀ q ≀ 10 000)Β β€” dimensions of the matrix and the number of turns in the experiment, respectively. Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≀ ti ≀ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≀ ri ≀ n) or ci (1 ≀ ci ≀ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≀ ri ≀ n, 1 ≀ ci ≀ m,  - 109 ≀ xi ≀ 109) are given. Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
1,400
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value. If there are multiple valid solutions, output any of them.
standard output
PASSED
bd94389058c008029e475941164b4075
train_003.jsonl
1461515700
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.io.IOException; import java.util.InputMismatchException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Niyaz Nigmatullin */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastScanner in = new FastScanner(inputStream); FastPrinter out = new FastPrinter(outputStream); TaskA solver = new TaskA(); solver.solve(1, in, out); out.close(); } static class TaskA { public void solve(int testNumber, FastScanner in, FastPrinter out) { int n = in.nextInt(); int m = in.nextInt(); int q = in.nextInt(); int[][] ans = new int[n][m]; int[][] id = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { id[i][j] = i * m + j; } } for (int i = 0; i < q; i++) { int t = in.nextInt(); if (t == 1) { int row = in.nextInt() - 1; int tmp = id[row][0]; for (int j = 0; j + 1 < m; j++) { id[row][j] = id[row][j + 1]; } id[row][m - 1] = tmp; } else if (t == 2) { int col = in.nextInt() - 1; int tmp = id[0][col]; for (int j = 0; j + 1 < n; j++) { id[j][col] = id[j + 1][col]; } id[n - 1][col] = tmp; } else { int x = in.nextInt() - 1; int y = in.nextInt() - 1; int z = in.nextInt(); ans[id[x][y] / m][id[x][y] % m] = z; } } for (int[] e : ans) { out.printArray(e); } } } static class FastScanner extends BufferedReader { public FastScanner(InputStream is) { super(new InputStreamReader(is)); } public int read() { try { int ret = super.read(); // if (isEOF && ret < 0) { // throw new InputMismatchException(); // } // isEOF = ret == -1; return ret; } catch (IOException e) { throw new InputMismatchException(); } } static boolean isWhiteSpace(int c) { return c >= 0 && c <= 32; } public int nextInt() { int c = read(); while (isWhiteSpace(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int ret = 0; while (c >= 0 && !isWhiteSpace(c)) { if (c < '0' || c > '9') { throw new NumberFormatException("digit expected " + (char) c + " found"); } ret = ret * 10 + c - '0'; c = read(); } return ret * sgn; } public String readLine() { try { return super.readLine(); } catch (IOException e) { return null; } } } static class FastPrinter extends PrintWriter { public FastPrinter(OutputStream out) { super(out); } public FastPrinter(Writer out) { super(out); } public void printArray(int[] a) { for (int i = 0; i < a.length; i++) { if (i > 0) { print(' '); } print(a[i]); } println(); } } }
Java
["2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8", "3 3 2\n1 2\n3 2 2 5"]
2 seconds
["8 2 \n1 8", "0 0 0 \n0 0 5 \n0 0 0"]
null
Java 8
standard input
[ "implementation" ]
f710958b96d788a19a1dda436728b9eb
The first line of the input contains three integers n, m and q (1 ≀ n, m ≀ 100, 1 ≀ q ≀ 10 000)Β β€” dimensions of the matrix and the number of turns in the experiment, respectively. Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≀ ti ≀ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≀ ri ≀ n) or ci (1 ≀ ci ≀ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≀ ri ≀ n, 1 ≀ ci ≀ m,  - 109 ≀ xi ≀ 109) are given. Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
1,400
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value. If there are multiple valid solutions, output any of them.
standard output
PASSED
bcf90a67abaf05be217d3de248563ec1
train_003.jsonl
1461515700
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
256 megabytes
import java.io.*; import java.util.*; public class A { InputStream is; int __t__ = 1; int __f__ = 0; int __FILE_DEBUG_FLAG__ = __f__; String __DEBUG_FILE_NAME__ = "src/A2"; FastScanner in; PrintWriter out; class Query { int t; int r; int c; int x; Query(int t, int rc) { this.t = t; this.r = rc; this.c = rc; } Query(int t, int r, int c, int x) { this.t = t; this.r = r; this.c = c; this.x = x; } public String toString() { return t + " : " + r + " " + c + " " + x; } } public void solve() { int n = in.nextInt(), m = in.nextInt(); int q = in.nextInt(); Query[] qs = new Query[q]; for (int i = 0; i < q; i++) { int t = in.nextInt(); if (t == 1 || t == 2) { int rc = in.nextInt() - 1; qs[i] = new Query(t, rc); } else { int r = in.nextInt() - 1, c = in.nextInt() - 1, x = in.nextInt(); qs[i] = new Query(t, r, c, x); } } int[][] res = new int[n][m]; for (int qcnt = q - 1; qcnt >= 0; qcnt--) { Query nq = qs[qcnt]; if (nq.t == 1) { int tmp = res[nq.r][m-1]; for (int j = m - 1; j >= 1; j--) res[nq.r][j] = res[nq.r][j-1]; res[nq.r][0] = tmp; } else if (nq.t == 2) { int tmp = res[n-1][nq.c]; for (int i = n - 1; i >= 1; i--) res[i][nq.c] = res[i-1][nq.c]; res[0][nq.c] = tmp; } else { res[nq.r][nq.c] = nq.x; } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { out.print(res[i][j] + " "); } out.println(); } out.close(); } public void run() { if (__FILE_DEBUG_FLAG__ == __t__) { try { is = new FileInputStream(__DEBUG_FILE_NAME__); } catch (FileNotFoundException e) { // TODO θ‡ͺε‹•η”Ÿζˆγ•γ‚ŒγŸ catch ブロック e.printStackTrace(); } System.out.println("FILE_INPUT!"); } else { is = System.in; } in = new FastScanner(is); out = new PrintWriter(System.out); solve(); } public static void main(String[] args) { new A().run(); } public void mapDebug(int[][] a) { System.out.println("--------map display---------"); for (int i = 0; i < a.length; i++) { for (int j = 0; j < a[i].length; j++) { System.out.printf("%3d ", a[i][j]); } System.out.println(); } System.out.println("----------------------------"); System.out.println(); } public void debug(Object... obj) { System.out.println(Arrays.deepToString(obj)); } class FastScanner { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public FastScanner(InputStream stream) { this.stream = stream; //stream = new FileInputStream(new File("dec.in")); } 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++]; } boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } boolean isEndline(int c) { return c == '\n' || c == '\r' || c == -1; } int nextInt() { return Integer.parseInt(next()); } int[] nextIntArray(int n) { int[] array = new int[n]; for (int i = 0; i < n; i++) array[i] = nextInt(); return array; } int[][] nextIntMap(int n, int m) { int[][] map = new int[n][m]; for (int i = 0; i < n; i++) { map[i] = in.nextIntArray(m); } return map; } long nextLong() { return Long.parseLong(next()); } long[] nextLongArray(int n) { long[] array = new long[n]; for (int i = 0; i < n; i++) array[i] = nextLong(); return array; } long[][] nextLongMap(int n, int m) { long[][] map = new long[n][m]; for (int i = 0; i < n; i++) { map[i] = in.nextLongArray(m); } return map; } double nextDouble() { return Double.parseDouble(next()); } double[] nextDoubleArray(int n) { double[] array = new double[n]; for (int i = 0; i < n; i++) array[i] = nextDouble(); return array; } double[][] nextDoubleMap(int n, int m) { double[][] map = new double[n][m]; for (int i = 0; i < n; i++) { map[i] = in.nextDoubleArray(m); } return map; } String next() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } String[] nextStringArray(int n) { String[] array = new String[n]; for (int i = 0; i < n; i++) array[i] = next(); return array; } String nextLine() { int c = read(); while (isEndline(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndline(c)); return res.toString(); } } }
Java
["2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8", "3 3 2\n1 2\n3 2 2 5"]
2 seconds
["8 2 \n1 8", "0 0 0 \n0 0 5 \n0 0 0"]
null
Java 8
standard input
[ "implementation" ]
f710958b96d788a19a1dda436728b9eb
The first line of the input contains three integers n, m and q (1 ≀ n, m ≀ 100, 1 ≀ q ≀ 10 000)Β β€” dimensions of the matrix and the number of turns in the experiment, respectively. Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≀ ti ≀ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≀ ri ≀ n) or ci (1 ≀ ci ≀ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≀ ri ≀ n, 1 ≀ ci ≀ m,  - 109 ≀ xi ≀ 109) are given. Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
1,400
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value. If there are multiple valid solutions, output any of them.
standard output
PASSED
3605e9540e708a7474d3e93e39fd4d08
train_003.jsonl
1461515700
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
256 megabytes
// package codeforces.cf3xx.cf348.div1; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class A { public static void main(String[] args) { InputReader in = new InputReader(System.in); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(); int m = in.nextInt(); int q = in.nextInt(); int[][] queries = new int[q][]; for (int i = 0; i < q ; i++) { int type = in.nextInt(); if (type == 3) { queries[i] = new int[]{type, in.nextInt()-1, in.nextInt()-1, in.nextInt()}; } else { queries[i] = new int[]{type, in.nextInt()-1}; } } int[][] mat = new int[n][m]; while (--q >= 0) { if (queries[q][0] == 1) { int row = queries[q][1]; int tmp = mat[row][m-1]; for (int i = m-1 ; i >= 1 ; i--) { mat[row][i] = mat[row][i-1]; } mat[row][0] = tmp; } else if (queries[q][0] == 2) { int col = queries[q][1]; int tmp = mat[n-1][col]; for (int i = n-1 ; i >= 1 ; i--) { mat[i][col] = mat[i-1][col]; } mat[0][col] = tmp; } else { mat[queries[q][1]][queries[q][2]] = queries[q][3]; } } for (int i = 0; i < n ; i++) { for (int j = 0; j < m ; j++) { if (j >= 1) { out.print(' '); } out.print(mat[i][j]); } out.println(); } out.flush(); } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public InputReader(InputStream stream) { this.stream = stream; } private int[] nextInts(int n) { int[] ret = new int[n]; for (int i = 0; i < n; i++) { ret[i] = nextInt(); } return ret; } private int[][] nextIntTable(int n, int m) { int[][] ret = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { ret[i][j] = nextInt(); } } return ret; } private long[] nextLongs(int n) { long[] ret = new long[n]; for (int i = 0; i < n; i++) { ret[i] = nextLong(); } return ret; } private long[][] nextLongTable(int n, int m) { long[][] ret = new long[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { ret[i][j] = nextLong(); } } return ret; } private double[] nextDoubles(int n) { double[] ret = new double[n]; for (int i = 0; i < n; i++) { ret[i] = nextDouble(); } return ret; } private int next() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public char nextChar() { int c = next(); while (isSpaceChar(c)) c = next(); if ('a' <= c && c <= 'z') { return (char) c; } if ('A' <= c && c <= 'Z') { return (char) c; } throw new InputMismatchException(); } public String nextToken() { int c = next(); while (isSpaceChar(c)) c = next(); StringBuilder res = new StringBuilder(); do { res.append((char) c); c = next(); } while (!isSpaceChar(c)); return res.toString(); } public int nextInt() { int c = next(); while (isSpaceChar(c)) c = next(); int sgn = 1; if (c == '-') { sgn = -1; c = next(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c-'0'; c = next(); } while (!isSpaceChar(c)); return res*sgn; } public long nextLong() { int c = next(); while (isSpaceChar(c)) c = next(); long sgn = 1; if (c == '-') { sgn = -1; c = next(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c-'0'; c = next(); } while (!isSpaceChar(c)); return res*sgn; } public double nextDouble() { return Double.valueOf(nextToken()); } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } static void debug(Object... o) { System.err.println(Arrays.deepToString(o)); } }
Java
["2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8", "3 3 2\n1 2\n3 2 2 5"]
2 seconds
["8 2 \n1 8", "0 0 0 \n0 0 5 \n0 0 0"]
null
Java 8
standard input
[ "implementation" ]
f710958b96d788a19a1dda436728b9eb
The first line of the input contains three integers n, m and q (1 ≀ n, m ≀ 100, 1 ≀ q ≀ 10 000)Β β€” dimensions of the matrix and the number of turns in the experiment, respectively. Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≀ ti ≀ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≀ ri ≀ n) or ci (1 ≀ ci ≀ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≀ ri ≀ n, 1 ≀ ci ≀ m,  - 109 ≀ xi ≀ 109) are given. Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
1,400
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value. If there are multiple valid solutions, output any of them.
standard output
PASSED
d5c51ed247fdcd69e4fb324a11faa003
train_003.jsonl
1461515700
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
256 megabytes
import java.io.*; import java.util.*; public class Solution { private BufferedReader in; private StringTokenizer line; private PrintWriter out; private static final int mm = 1000000007; public void solve() throws IOException { int n = nextInt(); int m = nextInt(); int q = nextInt(); int[][] a = new int[n][m]; int[][] queries = new int[q][]; for (int i = 0; i < q; i++) { int t = nextInt(); if (t == 3) { int x = nextInt() - 1; int y = nextInt() - 1; a[x][y] = nextInt(); } else if (t == 1) { int x = nextInt() - 1; queries[i] = new int[]{t, x}; int tmp = a[x][0]; for (int j = 1; j < m; j++) { a[x][j - 1] = a[x][j]; } a[x][m - 1] = tmp; } else { int y = nextInt() - 1; queries[i] = new int[]{t, y}; int tmp = a[0][y]; for (int j = 1; j < n; j++) { a[j - 1][y] = a[j][y]; } a[n - 1][y] = tmp; } } for (int i = q - 1; i >= 0; i--) { if (queries[i] != null) { int t = queries[i][0]; if (t == 1) { int x = queries[i][1]; int tmp = a[x][m - 1]; for (int j = m - 1; j > 0; j--) { a[x][j] = a[x][j - 1]; } a[x][0] = tmp; } else { int y = queries[i][1]; int tmp = a[n - 1][y]; for (int j = n - 1; j > 0; j--) { a[j][y] = a[j - 1][y]; } a[0][y] = tmp; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { out.print(a[i][j] + " "); } out.println(); } } public static void main(String[] args) throws IOException { new Solution().run(args); } public void run(String[] args) throws IOException { if (args.length > 0 && "DEBUG_MODE".equals(args[0])) { in = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt"))); } else { in = new BufferedReader(new InputStreamReader(System.in)); } out = new PrintWriter(System.out); // out = new PrintWriter("output.txt"); // int t = nextInt(); int t = 1; for (int i = 0; i < t; i++) { // out.print("Case #" + (i + 1) + ": "); solve(); } in.close(); out.flush(); out.close(); } private int[] nextIntArray(int n) throws IOException { int[] res = new int[n]; for (int i = 0; i < n; i++) { res[i] = nextInt(); } return res; } private long[] nextLongArray(int n) throws IOException { long[] res = new long[n]; for (int i = 0; i < n; i++) { res[i] = nextInt(); } return res; } 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()); } private String nextToken() throws IOException { while (line == null || !line.hasMoreTokens()) { line = new StringTokenizer(in.readLine()); } return line.nextToken(); } private static class Pii { private int key; private int value; public Pii(int key, int value) { this.key = key; this.value = value; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pii pii = (Pii) o; if (key != pii.key) return false; return value == pii.value; } @Override public int hashCode() { int result = key; result = 31 * result + value; return result; } } private static class Pair<K, V> { private K key; private V value; public Pair(K key, V value) { this.key = key; this.value = value; } public K getKey() { return key; } public V getValue() { return value; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pair<?, ?> pair = (Pair<?, ?>) o; if (key != null ? !key.equals(pair.key) : pair.key != null) return false; return !(value != null ? !value.equals(pair.value) : pair.value != null); } @Override public int hashCode() { int result = key != null ? key.hashCode() : 0; result = 31 * result + (value != null ? value.hashCode() : 0); return result; } } }
Java
["2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8", "3 3 2\n1 2\n3 2 2 5"]
2 seconds
["8 2 \n1 8", "0 0 0 \n0 0 5 \n0 0 0"]
null
Java 8
standard input
[ "implementation" ]
f710958b96d788a19a1dda436728b9eb
The first line of the input contains three integers n, m and q (1 ≀ n, m ≀ 100, 1 ≀ q ≀ 10 000)Β β€” dimensions of the matrix and the number of turns in the experiment, respectively. Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≀ ti ≀ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≀ ri ≀ n) or ci (1 ≀ ci ≀ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≀ ri ≀ n, 1 ≀ ci ≀ m,  - 109 ≀ xi ≀ 109) are given. Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
1,400
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value. If there are multiple valid solutions, output any of them.
standard output