This repository has been archived by the owner on Dec 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 366
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 #301 from shubhrai2811/main
added codeforces solutions to CPP
- Loading branch information
Showing
20 changed files
with
584 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,27 @@ | ||
#include<iostream> | ||
#include<bits/stdc++.h> | ||
|
||
using namespace std; | ||
void solve(int n){ | ||
for(int i=1;i<n;i++){ | ||
int a=i; | ||
int b=n-i; | ||
int ans1=__gcd(a,b); | ||
int ans2=lcm(a,b); | ||
if(ans1+ans2==n){ | ||
cout<<a<<" "<<b<<endl; | ||
break; | ||
} | ||
|
||
} | ||
} | ||
int main(){ | ||
int t; | ||
cin>>t; | ||
for(int i=0;i<t;i++){; | ||
int x; | ||
cin>>x; | ||
solve(x); | ||
} | ||
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,24 @@ | ||
#include<iostream> | ||
#include<bits/stdc++.h> | ||
|
||
using namespace std; | ||
int main(){ | ||
int n; | ||
cin>>n; | ||
int count=0; | ||
int arr[n]; | ||
for (int i = 0; i < n; i++) | ||
{ | ||
cin>>arr[i]; | ||
|
||
} | ||
sort(arr,arr+(n)); | ||
int y = arr[n-1]; | ||
int x= arr[0]; | ||
|
||
int ans = y-x-n+1; | ||
|
||
std::cout<<ans<<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,47 @@ | ||
#include<iostream> | ||
#include<bits/stdc++.h> | ||
#define ll long long | ||
using namespace std; | ||
|
||
int main(){ | ||
ll n; | ||
cin>>n; | ||
ll arr[n+2]; | ||
ll srej=0,dim=0; | ||
int left=1,right=n,chance=1; | ||
for (int i = 1; i < n+1; i++) | ||
{ | ||
cin>>arr[i]; | ||
} | ||
while(right>=left){ | ||
if(chance%2==1){ | ||
|
||
if(arr[left]>=arr[right]){ | ||
srej+=arr[left++]; | ||
|
||
} | ||
else{ | ||
srej+=arr[right--]; | ||
|
||
} | ||
chance++; | ||
} | ||
else if(chance%2==0){ | ||
|
||
if(arr[left]>=arr[right]){ | ||
dim+=arr[left++]; | ||
|
||
} | ||
else{ | ||
dim+=arr[right--]; | ||
|
||
} | ||
chance++; | ||
} | ||
|
||
|
||
} | ||
cout<<srej<<" "<<dim<<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<iostream> | ||
#include<bits/stdc++.h> | ||
|
||
using namespace std; | ||
int main(){ | ||
int k,r,h=1,i=0,j=1; | ||
bool b=true; | ||
cin>>k>>r; | ||
|
||
while(b){ | ||
i++; | ||
h=k*i; | ||
if(h%10==0 or h%10==r){ | ||
b=false; | ||
} | ||
} | ||
cout<<i; | ||
|
||
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,47 @@ | ||
#include<iostream> | ||
#include<bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
void solve(int n){ | ||
int rem1= n-16; | ||
if(n<=30){ | ||
cout<<"NO"<<endl; | ||
} | ||
else{ | ||
int d1=2*7; | ||
int d2=3*5; | ||
int d3=3*7; | ||
int d4=2*11; | ||
int rem2=rem1-d1; | ||
int rem3=rem1-d2; | ||
int rem4=rem1-d3; | ||
int rem5=rem1-d4; | ||
if(rem2>0 and rem2!=d1 and rem2!= 6 and rem2!=10){ | ||
cout<<"YES"<<endl; | ||
cout<<6<<" "<<10<<" "<<d1<<" "<<rem2<<endl; | ||
} | ||
else if(rem3>0 and rem3!=d2 and rem3!= 6 and rem3!=10){ | ||
cout<<"YES"<<endl; | ||
cout<<6<<" "<<10<<" "<<d2<<" "<<rem3<<endl; | ||
} | ||
else if(rem4>0 and rem4!=d3 and rem4!= 6 and rem4!=10){ | ||
cout<<"YES"<<endl; | ||
cout<<6<<" "<<10<<" "<<d3<<" "<<rem4<<endl; | ||
} | ||
else if(rem5>0 and rem5!=d4 and rem5!= 6 and rem5!=10){ | ||
cout<<"YES"<<endl; | ||
cout<<6<<" "<<10<<" "<<d4<<" "<<rem5<<endl; | ||
} | ||
} | ||
} | ||
int main(){ | ||
int t; | ||
cin>>t; | ||
for(int i=0;i<t;i++){; | ||
int n; | ||
cin>>n; | ||
solve(n); | ||
} | ||
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<iostream> | ||
#include<bits/stdc++.h> | ||
|
||
using namespace std; | ||
int main(){ | ||
string s1="best"; | ||
string s2="cost"; | ||
int sum1=0; | ||
int sum2=0; | ||
for (int i = 0; i < s1.size(); i++) | ||
{ | ||
sum1+= s1[i]; | ||
} | ||
for (int i = 0; i < s2.size(); i++) | ||
{ | ||
sum2+= s2[i]; | ||
} | ||
|
||
cout<<sum1-sum2<<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,28 @@ | ||
#include<iostream> | ||
#include<bits/stdc++.h> | ||
|
||
using namespace std; | ||
int main(){ | ||
int n,k,count=0; | ||
cin>>n>>k; | ||
int arr[n]; | ||
|
||
for (int i = 0; i <n; i++) | ||
{ | ||
cin>>arr[i]; | ||
if((5-arr[i])>=k){ | ||
count++; | ||
} | ||
} | ||
|
||
int ans=count/3; | ||
if(ans>=1){ | ||
cout<<ans<<endl; | ||
} | ||
else{ | ||
cout<<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,29 @@ | ||
#include<iostream> | ||
#include<bits/stdc++.h> | ||
|
||
using namespace std; | ||
int main(){ | ||
int t; | ||
cin>>t; | ||
for(int i=0;i<t;i++){; | ||
int n,l,r,k,count=0; | ||
cin>>n>>l>>r>>k; | ||
int left=k; | ||
int arr[n]; | ||
for (int i = 0; i < n; i++) | ||
{ | ||
cin>>arr[i]; | ||
} | ||
sort(arr,arr+(n-1)); | ||
for (int i = 0; i < n; i++) | ||
{ | ||
if(arr[i]>=l && arr[i]<=r and arr[i]<=left){ | ||
left-=arr[i]; | ||
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,29 @@ | ||
#include <iostream> | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
int main() | ||
{ | ||
int t,x=0,y=0; | ||
cin >> t; | ||
for (int i = 0; i < t; i++) | ||
{ | ||
int l, r; | ||
cin >> l >> r; | ||
int x=l,y=2*l; | ||
|
||
if(y<=r){ | ||
|
||
|
||
cout<<x<<" "<<y<<endl; | ||
|
||
} | ||
else{ | ||
cout<<-1<<" "<<-1<<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,48 @@ | ||
#include<iostream> | ||
#include<bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
int sdif(string s1,string s2){ | ||
int sum1=0; | ||
// int sum2=0; | ||
int diff; | ||
for (int i = 0; i < s1.size(); i++) | ||
{ | ||
sum1+= abs(s1[i]-s2[i]); | ||
} | ||
// for (int i = 0; i < s2.size(); i++) | ||
// { | ||
// sum2+= s2[i]; | ||
// } | ||
|
||
return sum1; | ||
} | ||
|
||
int main(){ | ||
int t; | ||
cin>>t; | ||
for(int i=0;i<t;i++){; | ||
int m,n; | ||
cin>>n>>m; | ||
vector <string> arr(n); | ||
int mini=INT_MAX; | ||
int d; | ||
for (int i = 0; i < n; i++) | ||
{ | ||
cin>>arr[i]; | ||
} | ||
for (int i = 0; i < n; i++) | ||
{ | ||
for (int j = i+1;j < n; j++) | ||
{ | ||
d=sdif(arr[i],arr[j]); | ||
mini=min(mini,d); | ||
} | ||
} | ||
|
||
|
||
cout<<mini<<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,23 @@ | ||
#include<iostream> | ||
#include<bits/stdc++.h> | ||
|
||
using namespace std; | ||
int solve(int n){ | ||
int s = 0; | ||
for (int p = 1; p <= n; s++){ | ||
p = p / (p % 10) * (p % 10 + 1); | ||
if (p % 10 == 0) | ||
p++; | ||
} | ||
return s; | ||
} | ||
int main(){ | ||
int t,count=0; | ||
cin>>t; | ||
for(int i=0;i<t;i++){; | ||
int n; | ||
cin>>n; | ||
cout<<solve(n)<<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,26 @@ | ||
#include<iostream> | ||
#include<bits/stdc++.h> | ||
|
||
using namespace std; | ||
int main(){ | ||
int t; | ||
cin>>t; | ||
for(int i=0;i<t;i++){; | ||
int n,c1,c2; | ||
cin>>n; | ||
int res = n%3; | ||
if(res==0){ | ||
c1=c2=n/3; | ||
} | ||
else if(res==1){ | ||
c1=n/3+1; | ||
c2=n/3; | ||
} | ||
else if(res==2){ | ||
c1=n/3; | ||
c2=n/3+1; | ||
} | ||
cout<<c1<<" "<<c2<<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,3 @@ | ||
here i'm posting Codeforces Solutions | ||
|
||
updating it for git ssh |
Oops, something went wrong.