目录
A. Print a Pedestal (Codeforces logo?)
题目链接:A. Print a Pedestal (Codeforces logo?)
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n;
void solve()
{
cin>>n;
int a=n/3*3;
if(a<n)a+=3;
a/=3;
int b=a+1;
int c=n-a-b;
if(c==0)c++,a--;
cout<<a<<' '<<b<<' '<<c<<endl;
}
signed main()
{
io;
cin>>_;
while(_--)solve();
return 0;
}
B. Array Decrements
题目链接:B. Array Decrements
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n;
const int N=5e4+10;
int a[N],b[N];
void solve()
{
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)cin>>b[i];
int maxv=0;
for(int i=1;i<=n;i++)
{
maxv=max(maxv,a[i]-b[i]);
}
for(int i=1;i<=n;i++)
{
a[i]=max(0ll,a[i]-maxv);
}
bool f=false;
for(int i=1;i<=n;i++)
{
if(a[i]!=b[i])
{
f=true;
break;
}
}
if(f)cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
signed main()
{
io;
cin>>_;
while(_--)solve();
return 0;
}
C. Restoring the Duration of Tasks
题目链接:C. Restoring the Duration of Tasks
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n;
const int N=2e5+10;
int a[N],b[N];
void solve()
{
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)cin>>b[i];
int pre=a[1];
for(int i=1;i<=n;i++)
{
cout<<b[i]-a[i]<<' ';
if(b[i]>a[i+1])a[i+1]=b[i];
}
cout<<endl;
}
signed main()
{
io;
cin>>_;
while(_--)solve();
return 0;
}
D. Black and White Stripe
题目链接:D. Black and White Stripe
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n,k;
const int N=2e5+10;
int s[N];
void solve()
{
cin>>n>>k;
string str;
cin>>str;
for(int i=1;i<=n;i++)
{
int x=0;
if(str[i-1]=='B')x=1;
else x=-1;
s[i]=s[i-1]+x;
}
int minv=INF;
for(int i=1;i+k-1<=n;i++)
{
int r=i+k-1;
minv=min(minv,k-(s[r]-s[i-1]+k)/2);
//a-b=r,a+b=n a=(r+n)/2
}
cout<<minv<<endl;
}
signed main()
{
io;
cin>>_;
while(_--)solve();
return 0;
}
E. Price Maximization
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n,k;
const int N=2e5+10;
int a[N];
void solve()
{
cin>>n>>k;
int sum=0;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)
{
sum+=a[i]/k;
a[i]%=k;
}
sort(a+1,a+1+n);
int l=1,r=n;
while(l<r)
{
if(a[l]+a[r]>=k)
{
sum++;
r--;
}
l++;
}
cout<<sum<<endl;
}
signed main()
{
io;
cin>>_;
while(_--)solve();
return 0;
}