Skip to main content

Posts

codeforces div3 round 547-Superhero Battle

#include < bits / stdc ++. h > using namespace std ; int main () { long long H ; int n , i ; cin >> H >> n ; long long d [ n ], sum = 0 , h = H , gap = 0 ; for ( i = 0 ; i < n ; i ++) { cin >> d [ i ]; sum -= d [ i ]; h = h + d [ i ]; if ( h <= 0 ) { cout << i + 1 << endl ; return 0 ; } gap = max ( gap , sum ); } if ( sum <= 0 ) { cout << "-1" << endl ; return 0 ; } long long whole =( H - gap )/ sum ; H = H - whole * sum ; long long result = whole * n ; for ( i = 0 ;; i ++) { H = H + d [ i % n ]; result ++; if ( H <= 0 ) { cout << result << endl ; break ; } } return 0 ; }
Recent posts

codeforces-beautiful year

#include < bits / stdc ++. h > using namespace std ; bool check ( int n ) { int count [ 10 ]={ 0 }; while ( n != 0 ) { int t = n % 10 ; count [ t ]++; n = n / 10 ; } int flag = 1 ; for ( int i = 0 ; i < 10 ; i ++) { if ( count [ i ]> 1 ) { return false ; flag = 0 ; break ; } } if ( flag == 1 ) return true ; } int main () { int y ; cin >> y ; int i ; if ( check ( y )) y ++; for ( i = y ;; i ++) { if ( check ( i )) { cout << i ; break ; } } return 0 ; }

codeforces-expression

#include < bits / stdc ++. h > using namespace std ; void check ( int a , int b , int c ) { int p , q , r , s , t , u ; p = a * b + c ; q = a + b * c ; r =( a + b )* c ; s = a * b * c ; t = a *( b + c ); u = a + b + c ; cout << max ( p , max ( q , max ( r , max ( s , max ( t , u ))))); } int main () { int a , b , c ; cin >> a >> b >> c ; check ( a , b , c ); return 0 ; }

codeforces-presents

#include < bits / stdc ++. h > using namespace std ; int main () { int n , i ; cin >> n ; vector < pair < int , int >> vect ; for ( i = 0 ; i < n ; i ++) { int x ; cin >> x ; vect . push_back ( make_pair ( x , i + 1 )); } sort ( vect . begin (), vect . end ()); for ( i = 0 ; i < n ; i ++) { cout << vect [ i ]. second << " " ; } return 0 ; }

codeforces-puzzles solution

#include <iostream> #include <vector> #include <algorithm> #include <map> using namespace std ; int main () { int n , m ; cin >> n >> m ; vector <int> vect ; map < int , int > mp ; for ( int i = 0 ; i < m ; i ++) { int x ; cin >> x ; mp [ x ]++; vect . push_back ( x ); } sort ( vect . begin (), vect . end ()); int small = vect [ n - 1 ]- vect [ 0 ]; for ( int i = 0 ; i < vect . size ()- n + 1 ; i ++) { int d = vect [ i + n - 1 ]- vect [ i ]; if ( small > d ) small = d ; } int flag = 1 ; for ( auto k : mp ) { if ( k . second >= n ) { cout << "0" ; flag = 0 ; break ; } } if ( flag == 1 ) { cout << small ; } return 0 ; }

codeforces-Word

#include <iostream> using namespace std ; void process1 ( char str []) { int i = 0 ; while ( str [ i ]!= '\0' ) { if ( str [ i ]>= 65 and str [ i ]<= 90 ) { str [ i ]= str [ i ]+ 32 ; } i ++; } } void process2 ( char str []) { int i = 0 ; while ( str [ i ]!= '\0' ) { if ( str [ i ]>= 97 and str [ i ]<= 122 ) { str [ i ]= str [ i ]- 32 ; } i ++; } } void check ( char str []) { int i = 0 , count = 0 , count1 = 0 ; while ( str [ i ]!= '\0' ) { if ( str [ i ]>= 65 and str [ i ]<= 90 ) { count ++; } else if ( str [ i ]>= 97 and str [ i ]<= 122 ) { count1 ++; } i ++; } if ( count1 == count ) process1 ( str ); else if ( count1 < count ) process2 ( str ); else if ( count1 > count ) process1 ( str ); } int main () { char str [ 101 ]; cin >> str ; check ( str ); cout << str ;

codeforces-infinite sequence

#include <iostream> using namespace std ; int main () { long long a , b , c ; cin >> a >> b >> c ; if ( c == 0 ) { if ( a == b ) cout << "YES" ; else cout << "NO" ; } else { if (( b - a )% c == 0 and ( b - a )/ c >= 0 ) { cout << "YES" ; } else { cout << "NO" ; } } return 0 ; }