Posts

Showing posts from May, 2020

734B - Anton and Digits

#include <iostream> using namespace std ; int main () {   long long d2 , d3 , d5 , d6 ; cin >> d2 >> d3 >> d5 >> d6 ; long long mn = min ( min ( d2 , d5 ), d6 );   long long mn2 = min ( d2 - mn , d3 );   long long ans = mn * 256 + mn2 * 32 ; cout << ans ; }

835A - Key races

835A - Key races #include <iostream> using namespace std ; int main (){ int s , v1 , t1 , v2 , t2 ; cin >> s >> v1 >> v2 >> t1 >> t2 ; int f = s * v1 + 2 * t1 ; int sc = s * v2 + 2 * t2 ; if ( f > sc ) cout << "Second" ; else if ( f < sc ) cout << "First" ; else if ( f == sc ) cout << "Friendship" ;   }

1114A - Got Any Grapes?

1114A - Got Any Grapes? #include <iostream> using namespace std ; int main () { int x , y , z ; cin >> x >> y >> z ; int a , b , c ; cin >> a >> b >> c ;   int green = a - x ; int gandp = green + b ; int smith = gandp - y ; int drick = smith + c - z ; if ( green < 0 or smith < 0 or drick < 0 ) cout << "NO" ; else cout << "YES" ;   }

514A. Chewbaсca and Number

514A . Chewbaсca and Number #include <iostream> using namespace std ; int main () { string s ; cin >> s ; for ( int i = 0 ; i < s . length (); i ++){ if ( i == 0 and s [ i ]== '9' ) continue ;   if ( s [ i ]== '5' ) s [ i ]= '4' ; if ( s [ i ]== '6' ) s [ i ]= '3' ; if ( s [ i ]== '7' ) s [ i ]= '2' ; if ( s [ i ]== '8' ) s [ i ]= '1' ; if ( s [ i ]== '9' ) s [ i ]= '0' ; } cout << s ;   return 0 ; }

651A. Joysticks

#include <iostream> using namespace std ; int main () { int a , b , c = 0 ; int i ; cin >> a >> b ; int mn = min ( a , b ); int mx = max ( a , b );   while ( max ( mx , mn )> 1 && min ( mx , mn )> 0 ){   if ( mx > mn ){ mn = mn + 1 ; mx = mx - 2 ;   } else { mn = mn - 2 ; mx = mx + 1 ; }   //cout<<mn<<" "<<mx<<endl; c ++; } cout << c ; return 0 ; }

1257A - Two Rival Students

1257A - Two Rival Students #include <iostream> using namespace std ; int main () {   int n , x , a , b ; int t ; cin >> t ;   while ( t --) { cin >> n >> x >> a >> b ; { int c = 0 ; int m = max ( a , b ); int mn = min ( a , b ); for ( int i = 1 ; i <= x ; i ++) { if ( m >= n ) break ; c ++; m ++; } int xtramove = 0 ; xtramove = x - c ; for ( int i = 0 ; i < xtramove ; i ++) { if ( mn <= 1 ) break ; mn --; }     cout << m - mn << endl ; }   } return 0 ;}

1295A - Display The Number

1295A - Display The Number #include <iostream> using namespace std ; int main () { int t ; int n ; cin >> t ; while ( t --) { cin >> n ; if ( n % 2 == 0 ){ for ( int i = 0 ; i < n / 2 ; i ++) cout << 1 ; cout << endl ; } else { cout << 7 ; for ( int i = 1 ; i < n / 2 ; i ++) cout << 1 ; cout << endl ; } }         }

1206A. Choose Two Numbers

1206/A #include <iostream> #include <algorithm> using namespace std ; int main (){ int a ; int b ; cin >> a ; int arr [ a ];   for ( int i = 0 ; i < a ; i ++) cin >> arr [ i ]; sort ( arr , arr + a ); cin >> b ; int brr [ b ]; for ( int i = 0 ; i < b ; i ++) cin >> brr [ i ]; sort ( brr , brr + b );   cout << arr [ a - 1 ]<< " " << brr [ b - 1 ]<< endl ;   }

1350A - Orac and Factors

1350A - Orac and Factors #include <iostream> using namespace std ; int main (){ long n , k ; int t , i ; cin >> t ; while ( t --){ long c = 0 ; cin >> n >> k ; if ( n % 2 == 0 ){ n = n + 2 * k ; cout << n << endl ; }   else { for ( int j = 2 ; j <= n ; j ++){ if ( n % j == 0 )   { c = j ; break ;} } c = c + n ; c = c + 2 *( k - 1 ); cout << c << endl ; } } return 0 ;}

1230A Dawid and Bags of Candies

#include<iostream> #include<algorithm> using namespace std; int main() { int arr[4]; for(int i=0;i<4;i++){ cin>>arr[i]; } sort(arr,arr+4); if(arr[0]+arr[3]==arr[1]+arr[2]) cout<<"YES"<<endl; else if(arr[0]+arr[2]+arr[1]==arr[3]) cout<<"YES"<<endl; else cout<<"NO"<<endl; return 0; }

1326A - Bad Ugly Numbers

#include <math.h> #include <iostream> using namespace std ;   int main () { int n ; int t ; cin >> t ; while ( t --){ cin >> n ; if ( n == 1 ) cout <<- 1 << endl ; else { cout << "2" ; for ( int i = 1 ; i < n ; i ++)   cout << "3" ;     } cout << endl ; }     }  

149A - Business trip

#include <algorithm> #include <iostream> using namespace std ; int main (){ int n , sum = 0 , c = 0 ; cin >> n ; int arr [ 12 ]; for ( int i = 0 ; i < 12 ; i ++) cin >> arr [ i ]; sort ( arr , arr + 12 , greater <int> ()); if ( n == 0 ) cout << 0 ; else { for ( int i = 0 ; i < 12 ; i ++) { sum = sum + arr [ i ]; c ++; if ( sum >= n ){ cout << c ; break ;}     } if ( sum < n ){ cout <<- 1 << " " ; }   }     }

149A - Business trip

#include <algorithm> #include <iostream> using namespace std ; int main (){ int n , sum = 0 , c = 0 ; cin >> n ; int arr [ 12 ]; for ( int i = 0 ; i < 12 ; i ++) cin >> arr [ i ]; sort ( arr , arr + 12 , greater <int> ()); if ( n == 0 ) cout << 0 ; else { for ( int i = 0 ; i < 12 ; i ++) { sum = sum + arr [ i ]; c ++; if ( sum >= n ){ cout << c ; break ;}     } if ( sum < n ){ cout <<- 1 << " " ; }   }     }

149A - Business trip

#include <algorithm> #include <iostream> using namespace std ; int main (){ int n , sum = 0 , c = 0 ; cin >> n ; int arr [ 12 ]; for ( int i = 0 ; i < 12 ; i ++) cin >> arr [ i ]; sort ( arr , arr + 12 , greater <int> ()); if ( n == 0 ) cout << 0 ; else { for ( int i = 0 ; i < 12 ; i ++) { sum = sum + arr [ i ]; c ++; if ( sum >= n ){ cout << c ; break ;}     } if ( sum < n ){ cout <<- 1 << " " ; }   }     }