initial commit

This commit is contained in:
ShazidMahsrafi 2023-06-23 01:53:18 +06:00
parent f6a23826d1
commit 413e322c28
2 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,36 @@
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
void solve()
{
int n,t1,t2,t;
cin>>n;
t=t1=t2=INT_MAX;
for(int i=0; i<n; ++i)
{
int x;
string s;
cin>>x>>s;
if(s[0]=='1') t1=min(x,t1);
if(s[1]=='1') t2=min(x,t2);
if(s[0]=='1' && s[1]=='1') t=min(x,t);
}
if(t1==INT_MAX || t2==INT_MAX) cout<<"-1"<<endl;
else
{
if(t<t1+t2) cout<<t<<endl;
else cout<<t1+t2<<endl;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int TC = 1;
cin >> TC;
cin.ignore();
while (TC--) solve();
}

30
1829D Gold Rush/1829D.cpp Normal file
View File

@ -0,0 +1,30 @@
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
bool check(int n,int m)
{
if(n==m) return true;
else if(n%3!=0 || n<m) return false;
else return (check (n/3,m) || check(2*n/3,m));
}
void solve()
{
int n,m;
cin>>n>>m;
bool p=check(n,m);
if(p) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int TC = 1;
cin >> TC;
cin.ignore();
while (TC--) solve();
}