Posts

Showing posts from June, 2019

CODEFORCES 390A

CODEFORCES  390A - Inna and Alarm Clock Link to Ques -  Codeforces 390A 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 import java.util.Arrays ; import java.util.Scanner ; public class CF390A { public static void main ( String [] args ) { Scanner sc = new Scanner ( System . in ); int visx [] = new int [ 110 ]; int visy [] = new int [ 110 ]; Arrays . fill ( visx , 0 ); Arrays . fill ( visy , 0 ); int n = sc . nextInt (); for ( int i = 0 ; i < n ; i ++) { int x = sc . nextInt (); int y = sc . nextInt (); visx [ x ]= 1 ; visy [ y ]= 1 ; } int cx = 0 , cy = 0 ; for ( int i = 0 ; i < 110 ; i ++) { if ( visx [ i ]== 1 ) cx ++; if ( visy [ i ]== 1 ) cy...

CODEFORCES 399A

CODEFORCES 399A - Pages Link to Ques -  Codeforces 399A 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 import java.util.LinkedList ; import java.util.Scanner ; public class CF399A { public static void main ( String [] args ) { Scanner sc = new Scanner ( System . in ); LinkedList < String > str = new LinkedList <>(); int n = sc . nextInt (); int p = sc . nextInt (); int k = sc . nextInt (); if ( p - k > 1 ) { str . add ( "<< " ); } for ( int i = p - k ; i <= p + k ; i ++) { if ( i == p && i >= 1 ) { str . add ( "(" + i + ") " ); } else if ( i <= n && i >= 1 ) { str . add ( i + " " ); }...

CODEFORCES 393A

CODEFORCES 393A - NINETEEN Link to Ques -  Codeforces 393A 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 import java.util.Arrays ; import java.util.Scanner ; public class CF393A { public static void main ( String [] args ) { Scanner sc = new Scanner ( System . in ); int a []= new int [ 4 ]; String str = sc . nextLine (); for ( int i = 0 ; i < str . length (); i ++) { char ch = str . charAt ( i ); if ( ch == 'n' || ch == 'N' ) a [ 0 ]++; else if ( ch == 'i' || ch == 'I' ) a [ 1 ]++; else if ( ch == 'e' || ch == 'E' ) a [ 2 ]++; else if ( ch == 't' || ch == 'T' ) a [ 3 ]++; } a [ 0 ] = ( a [ 0 ]- 1 )/ 2 ; a [ 2 ]/= 3 ; Arrays . sort...

CODEFORCES 1145A

CODEFORCES  1145A - THANOS SOR T Link to Ques -  Codeforces 1145A 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 import java.util.Scanner ; public class CF1145A { static int [] arr ; public static void main ( String [] args ) { Scanner in = new Scanner ( System . in ); arr = new int [ in . nextInt ()]; for ( int i = 0 ; i < arr . length ; i ++) { arr [ i ] = in . nextInt (); } System . out . println ( dp ( 0 , arr . length )); } static int dp ( int l , int r ) { for ( int i = l + 1 ; i < r ; i ++) { if ( arr [ i ] < arr [ i - 1 ]) { int mid = ( l + r )/ 2 ; return Math . max ( dp ( l , mid ), dp ( mid , r )); } } return r - l ; } }

CODEFORCES 1181A

CODEFORCES 1181A - Chunga Changa Link to Ques -  CodeForces 1181A Approach It's easy to calculate how much coconuts we will buy:  k = ⌊ x + y z ⌋ k = ⌊ x + y z ⌋  (suppose that all money transferred to a single person, this way the number of bought coconuts would be clearly maximal) If  k = ⌊ x z ⌋ + ⌊ y z ⌋ k = ⌊ x z ⌋ + ⌊ y z ⌋ , then the answer is  ⟨ k , 0 ⟩ ⟨ k , 0 ⟩ . The remaining case is a bit harder. Let's notice, that there is no need to transfer  ≥ z ≥ z  chizhiks, since the one transferring money could have used  z z  chizhiks to buy one more coconut herself. Also it's optimal to transfer coins such that the remainder modulo  z z  of the receiving part will turn to be exactly zero (we could have simply transfer less for the same effect). So the answer is  ⟨ k , min ( z − ( x mod z ) , z − ( y mod z ) ) ⟩ ⟨ k , min ( z − ( x mod z ) , z − ( y mod z ) ) ⟩ . 1 2 3 4 5 6 7 8 9 10 1...