Skip to content

Instantly share code, notes, and snippets.

@sakshamchhimwal
Last active November 22, 2022 06:39
Show Gist options
  • Save sakshamchhimwal/d596dc2562f44ec594ffdbef39855254 to your computer and use it in GitHub Desktop.
Save sakshamchhimwal/d596dc2562f44ec594ffdbef39855254 to your computer and use it in GitHub Desktop.
This Gist Holds All The CodeForces 800 level question solutions
#include<bits/stdc++.h>
using namespace std;
int solve(){
int n,m;
cin>>n;
cin>>m;
int sum=0;
for(int i=0;i<m;i++){
int a,b;
cin>>a;
cin>>b;
sum+=a;
}
if(sum<((n*(n+1))/2)){
return 1;
}
return 0;
}
int main(){
int t;
cin>>t;
for(int i=0;i<t;i++){
if(solve()){
cout<<"YES\n";
}else{
cout<<"NO\n";
}
}
}
#include<bits/stdc++.h>
using namespace std;
long long int solve(){
string s;
long long int l;
cin>>l;
cin >> s;
long long int tx=0,x=0,y=0,ty=0;
long long int maxNum=-100;
for(long long int i=0;i<l;){
while(s[i]=='0'){
i++;
x++;
tx++;
}
while(s[i]=='1'){
i++;
y++;
ty++;
}
long long int sx = x*x;
long long int sy = y*y;
long long int sb = tx*ty;
if (maxNum < max({sx, sy, sb})){
maxNum = max({sx, sy, sb});
}
x=0;y=0;
}
return maxNum;
}
int main(int argc, char const *argv[])
{
long long int t=0;
cin>>t;
for(long long int i=0;i<t;i++){
long long int k=solve();
cout<<k<<'\n';
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int solve(){
string x;
cin>>x;
stack<int> s;
for(char c:x){
if(c=='Q'){
s.push(1);
}else{
if(!s.empty()){
s.pop();
}
}
}
if(!s.empty()){
return 0;
}else{
return 1;
}
}
int main(int argc, char const *argv[])
{
int n;
cin>>n;
for(int i=0;i<n;i++){
int c;
cin>>c;
if(solve()) cout<<"Yes\n";
else cout<<"No\n";
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int solver(){
string x;
cin >> x;
char prev='/';
for(char c : x){
if(c!='Y' && c!='e' && c!='s'){
return 0;
}
if(prev=='/'){
prev=c;
}else{
switch(prev){
case 'Y':
if(c!='e'){
return 0;
}
prev = c;
break;
case 'e':
if(c!='s'){
return 0;
}
prev = c;
break;
case 's':
if(c!='Y'){
return 0;
}
prev = c;
break;
default:
return 0;
}
}
}
return 1;
}
int main(int argc, char const *argv[])
{
int n;
cin>>n;
for(int i=0;i<n;i++){
if(solver()){
cout<<"\tYES\n";
}else{
cout<<"\tNO\n";
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment