A - Alehouse
答案
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eps 1e-6
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
const int M = 11;
using namespace std;
int n,k;
vector<PII> dp;
void solve(){
cin>>n>>k;
int u,v;
rep(i,0,n-1){
cin>>u>>v;
dp.pb({u,1});
dp.pb({v+1,-1});
}
sort(dp.begin(),dp.end());
int m=n*2;
int maxn=-1;
int res=0;
int j=0;
rep(i,0,m-1){
while(j<m&&dp[j].first<=dp[i].first+k-1){
if(dp[j].second==1) res++;
j++;
}
if(dp[i].second==-1){
maxn=max(maxn,res);
res--;
}
}
cout<<maxn<<endl;
}
int main() {
solve();
return 0;
}
C - Climbing Stairs
答案
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eps 1e-6
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
const int M = 11;
using namespace std;
void solve(){
int n,r,k;
cin>>n>>r>>k;
if(r>=k)
{
if(n<=r)
cout<<2*r<<endl;
else{
if((n%2!=r%2)||(n%2!=r%2)) cout<<n+r+1<<endl;
else cout<<n+r<<endl;
}
}
else
{
if(n<=2*k-r) cout<<2*k<<endl;
else{
if((n%2!=r%2)||(n%2!=r%2)) cout<<n+r+1<<endl;
else cout<<n+r<<endl;
}
}
}
int main() {
solve();
return 0;
}
H - Howl
答案
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eps 1e-6
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
const int M = 11;
using namespace std;
void solve(){
string s;
cin>>s;
int len=s.size();
string str="AWH";
int cnt=len-2;
cout<<str;
rep(i,0,cnt-1){
cout<<"O";
}
cout<<endl;
}
int main() {
solve();
return 0;
}