Posts

Showing posts from January, 2022

Solution to the problem 'A' from 'Hello 2022' Contest (Codeforces)

Here's my solution to problem  A from the contest 'Hello 2022' of Codeforces .   Question Link:  https://codeforces.com/contest/1621/problem/A #include <bits/stdc++.h> #define int long long #define pb push_back #define fi first #define se second #define pii pair < int,int > using namespace std ; int32_t main () {     ios_base :: sync_with_stdio ( false );     cin . tie ( NULL );     cout . tie ( NULL );     int t ;     cin >> t ;     while ( t --){         int n , k , m = 0 ;         cin >> n >> k ;         if ( n % 2 == 0 ){             if ( k <= n / 2 ){                 for ( int i = 1 ; i <= n ; i ++){                     for ( int j = 1 ; j <= n ; j ++){                         if ( k > 0 && i == 2 * m + 1 && j == 2 * m + 1 ){                             cout << 'R' ;                             k --;                             m ++;                         }                    

Solution to the problem 'Electronics Shop' (HackerRank)

Hi all! Here's my solution to the problem 'Electronics Shop' from HackerRank. Question link:  https://www.hackerrank.com/challenges/electronics-shop/problem #include <bits/stdc++.h> #define int long long #define pb push_back #define fi first #define se second #define pii pair < int,int > using namespace std ; int32_t main () {     ios_base :: sync_with_stdio ( false );     cin . tie ( NULL );     cout . tie ( NULL );     int b , n , m ;     cin >> b >> n >> m ;     vector < int > keyboard , usb ;     for ( int i = 0 ; i < n ; i ++){         int x ;         cin >> x ;         keyboard . pb ( x );     }     for ( int i = 0 ; i < m ; i ++){         int x ;         cin >> x ;         usb . pb ( x );     }     sort ( keyboard . begin (), keyboard . end ());     sort ( usb . begin (), usb . end ());     int ans = 0 , flg = 0 ;     if ( keyboard [ 0 ] + usb [ 0 ] > b ) cout << - 1 ;     else {