File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Codeforces/Codeforces Round #717 (Div. 2) Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ package codeforces ;
2
+
3
+ import java .io .BufferedReader ;
4
+ import java .io .IOException ;
5
+ import java .io .InputStreamReader ;
6
+
7
+ public class TitForTat {
8
+
9
+ public static void main (String [] args ) throws IOException {
10
+ // TODO Auto-generated method stub
11
+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
12
+ int t = Integer .parseInt (br .readLine ());
13
+ while (t -- != 0 ) {
14
+ String line = br .readLine ();
15
+ String [] temp = line .trim ().split ("\\ s+" );
16
+ int n = Integer .parseInt (temp [0 ]);
17
+ int k = Integer .parseInt (temp [1 ]);
18
+ line = br .readLine ();
19
+ temp = line .trim ().split ("\\ s+" );
20
+ int [] arr = new int [n ];
21
+ for (int i = 0 ; i < n ; i ++)
22
+ arr [i ] = Integer .parseInt (temp [i ]);
23
+ int i = 0 ;
24
+ while (true ) {
25
+ if (k <= 0 )
26
+ break ;
27
+ if (i >= n - 1 )
28
+ break ;
29
+ while (i < n - 1 && arr [i ] == 0 ) {
30
+ i += 1 ;
31
+ if (i >= n - 1 )
32
+ break ;
33
+ }
34
+ arr [i ] -= 1 ;
35
+ arr [n - 1 ] += 1 ;
36
+ k -= 1 ;
37
+ }
38
+ StringBuffer sb = new StringBuffer ();
39
+ for (i = 0 ; i < n ; i ++)
40
+ sb .append (arr [i ] + " " );
41
+ System .out .println (sb .toString ().trim ());
42
+ }
43
+ br .close ();
44
+ }
45
+
46
+ }
47
+
You can’t perform that action at this time.
0 commit comments