https://www.codechef.com/CNHT2022

https://www.codechef.com/CNHT2022

IPL Question Link:

Solution:

Summary

C++:

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int x,y,z;
	cin>>x>>y>>z;
	int rem=y-x;
	if(rem*2>=z||rem>=z)
	cout<<"YES\n";
	else
	cout<<"NO\n";
	return 0;
}

Python:

x=int(input())
y=int(input())
z=int(input())

a=y-x
if a*2<z:
    print("NO")
    
else:
    print("YES")

TOOS Question Link:

Solution:

Summary

C++:

#include<iostream>

#include<cstring>

using namespace std;

int main()

{

    char a[20];

    cin>>a;

    int n=strlen(a);

    int t=0,o=0;

    for(int i=0;i<n;i++)

    {

        if(a[i]=='T'||a[i]=='t')

        {

            t++;

        }

        else

        {

            o++;

        }

    }

    if((2*t)==o)

    {

        cout<<"Yes";

    }

    else

    {

        cout<<"No";

    }

    return 0;

}

Pyhton:

v= input()
x=0
k=0
n=len(v)

for i in range (0,n):
    if v[i]=='t' or v[i]=='T':
        x=x+1
        k=i
    else:
        break
v1=v[k+1:]
y=len(v1)
if((2*x)==y):
    print("YES")
else:
    print("NO")

KAKASHI SENSEI AND THE NINJA ACADEMY Question Link :

Solution:

Summary

C++:

#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(long long i=a;i<b;i++)
#define rf(i,a,b) for(long long i=a;i>=b;i--)
#define ll long long
#define pb push_back
#define vll vector<long long>
#define vc vector
#define fi first
#define se second
#define pqmin priority_queue<ll,vector<ll>,greater<ll>>
#define all(x) x.begin(),x.end()
#define IOS ios_base::sync_with_stdio(0)
#define tie cin.tie(NULL),cout.tie(NULL) 
void solve(){

int n,i;
		cin>>n;
		int a[n],b[n];
		int ans=0;
		for(i=0;i<n;i++)
			cin>>a[i];
		for(i=0;i<n;i++)
			cin>>b[i];
		for(i=0;i<n;i++)
		{
			ans=max(ans,20*a[i]-10*(b[i]));
		}
		cout<<ans<<endl;
    }



int main() {
	// your code goes here
	int t;
	cin>>t;

	while(t--)
	{
		
	 solve();
	
	
}
return 0;
}

Python:

# cook your dish here
for _ in range(int(input())):
    n = int(input())
    lst1 =  list(map(int,input().split()))
    lst2 =  list(map(int,input().split()))
    lst3 = []
    for i in range(n):
        s = lst1[i] * 20 - lst2[i] * 10
        if (s < 0):
            s = 0
        lst3.append(s)
    print(max(lst3))

AUDIO SYSTEM Question Link:

Solution:

Summary

C++:

#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m;cin>>n>>m;
    int ans=0;int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<m;i++){
        if(a[i]<0){
            ans+=abs(a[i]);
        }
    }
    std::cout << ans << std::endl;
    return 0;
}

Python:

n,k = map(int,input().split())
l = list(map(int,input().split()))
sum = 0
l.sort()
for i in range(0,k):
    if l[i]<=0:
        sum += l[i]
print(0-sum)

CHATBOT Question Link:

Solution:

Summary

C++:

#include <bits/stdc++.h>

using namespace std;

string ltrim(const string &);
string rtrim(const string &);

string ChatBot(string str, string T) {
	string arr, brr;
       arr=str;brr=T;

        vector <pair<char,long long> > s, t;

        long long cnt = 1;
        for(long long i = 0; i < arr.size(); i++){
            if(arr[i] == arr[i + 1]) cnt++;
            else{
                s.push_back(make_pair(arr[i], cnt));
                cnt = 1;
            }
        }

        cnt = 1;
        for(long long i = 0; i < brr.size(); i++){
            if(brr[i] == brr[i + 1]) cnt++;
            else{
                t.push_back(make_pair(brr[i], cnt));
                cnt = 1;
            }
        }

        if(s.size() != t.size()){
            // cout << "NO" << endl;
            return "NO";
            // return "NO";
            // continue;
        }

        bool ck = true;
        for(long long i = 0; i < s.size(); i++){
            if(s[i].first == t[i].first && s[i].second <= t[i].second) continue;
            else {
                // cout << "NO" << endl;
                return "NO";
                ck = false;
                break;
            }
        }

        if(ck == true){ 
            // cout << "YES" << endl;
            return "YES";
            
        }
}

int main() {

	string str;
	getline(cin, str);

	string T;
	getline(cin, T);

	string result = ChatBot(str, T);

	cout << result;

	return 0;
}

string ltrim(const string &str) {
	string s(str);

	s.erase(
		s.begin(),
		find_if(s.begin(), s.end(), not1(ptr_fun<int, int>(isspace)))
	);

	return s;
}

string rtrim(const string &str) {
	string s(str);

	s.erase(
		find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(isspace))).base(),
		s.end()
	);

	return s;
}

Python:

GI = lambda: int(input()); GIS = lambda: map(int, input().split()); LGIS = lambda: list(GIS())

def main():
    a = input()
    b = input()
    ib = 0
    for ia, ca in enumerate(a):
        if ib:
            while ib < len(b) and b[ib] != ca:
                ib += 1
        else:
            if b[0] != ca:
                break
        if ib == len(b):
            break
        ib += 1
    else:
        return print('YES')
    print('NO')

main()