Codeforces Round #797 (Div. 3)A~E

115 篇文章 3 订阅
42 篇文章 2 订阅

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

题目链接: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;
}
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

leimingzeOuO

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值