-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #750 from thesuaveguy/main
pr #423 added codechef LTIME110D solutions
- Loading branch information
Showing
9 changed files
with
331 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"files.associations": { | ||
"iostream": "cpp" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include <bits/stdc++.h> | ||
#define ll long long | ||
using namespace std; | ||
int main() | ||
{ | ||
ll t; | ||
cin >> t; | ||
while (t--) | ||
{ | ||
ll n; | ||
cin >> n; | ||
string a, b; | ||
cin >> a; | ||
cin >> b; | ||
bool iszer = false; | ||
char c = a[0]; | ||
bool isB = false; | ||
for (int i = 0; i < b.size() - 1; i++) | ||
{ | ||
if (b[i] == b[i + 1]) | ||
isB = true; | ||
} | ||
if (c == '0') | ||
{ | ||
for (int i = 1; i < a.size(); i++) | ||
{ | ||
if (a[i] == '1') | ||
iszer = true; | ||
} | ||
if (iszer&isB) | ||
cout << "YES" << endl; | ||
else | ||
{ | ||
if (a == b) | ||
cout << "YES" << endl; | ||
else | ||
cout << "NO" << endl; | ||
} | ||
} | ||
else if (c == '1') | ||
{ | ||
for (int i = 1; i < a.size(); i++) | ||
{ | ||
if (a[i] == '0') | ||
iszer = true; | ||
} | ||
if (isB) | ||
{ | ||
cout << "YES" << endl; | ||
} | ||
else | ||
{ | ||
|
||
if (a == b) | ||
cout << "YES" << endl; | ||
else | ||
cout << "NO" << endl; | ||
} | ||
} | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#define ll long long | ||
|
||
int main() | ||
{ | ||
ll t; | ||
cin>>t; | ||
|
||
while(t--) | ||
{ | ||
ll n,count=0; | ||
cin>>n; | ||
string s; | ||
vector<int>v; | ||
cin>>s; | ||
for (ll i = 0; i < n; i++) | ||
{ | ||
if(s[i]=='a' || s[i]=='e' || s[i]=='i' || s[i]=='o' || s[i]=='u') | ||
{ | ||
v.push_back(count); | ||
count=0; | ||
} | ||
else | ||
count++; | ||
} | ||
v.push_back(count); | ||
sort(v.begin(),v.end()); | ||
if(v[v.size()-1]>=4) | ||
cout<<"NO"<<endl; | ||
else | ||
cout<<"YES"<<endl; | ||
|
||
|
||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <bits/stdc++.h> | ||
#define ll long long | ||
using namespace std; | ||
int main() | ||
{ | ||
ll t; | ||
cin >> t; | ||
while (t--) | ||
{ | ||
ll a,b,c,d; | ||
cin >> a>>b>>c>>d; | ||
ll e=a+b; | ||
ll f=c+d; | ||
if(e>f) | ||
cout<<f<<endl; | ||
else | ||
cout<<e<<endl; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#define ll long long | ||
|
||
int main() | ||
{ | ||
ll t; | ||
cin >> t; | ||
|
||
while (t--) | ||
{ | ||
ll n; | ||
cin >> n; | ||
ll arr[n]; | ||
for (ll i = 0; i < n; i++) | ||
{ | ||
cin >> arr[i]; | ||
} | ||
ll count = 0; | ||
ll sum = 0; | ||
sort(arr, arr + n); | ||
for (ll i = 0; i < n; i++) | ||
{ | ||
sum += arr[i]; | ||
if (n - 1 >= sum) | ||
{ | ||
|
||
count++; | ||
} | ||
} | ||
|
||
cout << count << endl; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#define ll long long | ||
|
||
int main() | ||
{ | ||
ll t; | ||
cin>>t; | ||
|
||
while(t--) | ||
{ | ||
ll n; | ||
cin>>n; | ||
ll arr[n]; | ||
ll brr[n]; | ||
for (ll i = 0; i < n; i++) | ||
{ | ||
cin>>arr[i]; | ||
} | ||
for (ll i = 0; i < n; i++) | ||
{ | ||
cin>>brr[i]; | ||
} | ||
sort(arr,arr+n); | ||
sort(brr,brr+n); | ||
vector<ll>v1; | ||
vector<ll>v2; | ||
for (ll i = (n-1)/2; i < n; i++) | ||
{ | ||
v1.push_back(arr[i]); | ||
} | ||
for (ll i = (n-1)/2; i < n; i++) | ||
{ | ||
v2.push_back(brr[i]); | ||
} | ||
sort(v1.begin(),v1.end()); | ||
sort(v2.begin(),v2.end(),greater<int>()); | ||
|
||
vector<ll>main; | ||
for (ll i = 0; i < v1.size(); i++) | ||
{ | ||
main.push_back(v1[i]+v2[i]); | ||
} | ||
sort(main.begin(),main.end()); | ||
cout<<main[0]<<endl; | ||
|
||
|
||
|
||
|
||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <bits/stdc++.h> | ||
#define ll long long | ||
using namespace std; | ||
int main() | ||
{ | ||
ll t; | ||
cin >> t; | ||
while (t--) | ||
{ | ||
ll x,y,z; | ||
cin >> x>>y>>z; | ||
ll d; | ||
if(x%3==0) | ||
d=x/3 -1; | ||
else | ||
d=x/3; | ||
cout<<((x*y)+(d*z))<<endl; | ||
|
||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <bits/stdc++.h> | ||
#define ll long long | ||
using namespace std; | ||
int main() | ||
{ | ||
ll t; | ||
cin >> t; | ||
while (t--) | ||
{ | ||
ll n,k; | ||
cin >> n>>k; | ||
cout<<n-k<<endl; | ||
|
||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#define ll long long int | ||
|
||
int main() | ||
{ | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
ll t; | ||
cin>>t; | ||
|
||
while(t--) | ||
{ | ||
ll n; | ||
cin>>n; | ||
string s; | ||
ll flag=0; | ||
cin>>s; | ||
vector<pair<char,int>>v; | ||
map<char,int>m; | ||
for (ll i = 0; i < n; i++) | ||
{ | ||
v.push_back({s[i],i+1}); | ||
m[s[i]]++; | ||
} | ||
sort(v.begin(),v.end()); | ||
for (auto it:m) | ||
{ | ||
if(it.second%2!=0) | ||
{ | ||
flag=1; | ||
break; | ||
} | ||
} | ||
|
||
ll odd=0; | ||
ll even=0; | ||
for (ll i = 0; i < n-1; i++) | ||
{ | ||
if(v[i].first==v[i+1].first) | ||
{ | ||
if(v[i].second%2==0) | ||
even++; | ||
else | ||
odd++; | ||
} | ||
else | ||
{ | ||
if(v[i].second%2==0) | ||
even++; | ||
else | ||
odd++; | ||
if(odd!=even) | ||
{ | ||
flag=1; | ||
break; | ||
} | ||
odd=0; | ||
even=0; | ||
} | ||
if(i==n-2) | ||
{ | ||
if(v[i+1].second%2==0) | ||
even++; | ||
else | ||
odd++; | ||
if(odd!=even) | ||
{ | ||
flag=1; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if(flag) | ||
cout<<"NO"<<endl; | ||
else | ||
cout<<"YES"<<endl; | ||
|
||
|
||
} | ||
return 0; | ||
} |