Educational Codeforces Round 158 (Rated for Div. 2)

Problem - A - Codeforces

#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
const int N=55;
int a[N];
int n,x;
void solve() {
	cin>>n>>x;
	for(int i=1;i<=n;i++) cin>>a[i];
	a[n+1]=1000;
	int ans=0;
	int pos=lower_bound(a+1,a+1+n+1,x)-a;
	pos--;
//	cout<<pos<<endl;
	for(int i=1;i<=pos;i++){
		ans=max(ans,a[i]-a[i-1]);
	}
	ans=max(ans,2*(x-a[pos]));
	cout<<ans<<endl;
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
    cin>>t;
	while(t--) {
		solve();
	}
	return 0;
}

Problem - B - Codeforces

#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
const int N=2e5+10;
int a[N];
int n;
void solve() {
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	int ans=0;
	ans+=a[1]-1;
	for(int i=2;i<=n;i++){
		if(a[i]>=a[i-1]) ans+=a[i]-a[i-1];
	}
	cout<<ans<<endl;
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
    cin>>t;
	while(t--) {
		solve();
	}
	return 0;
}

Problem - C - Codeforces

#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
const int N=2e5+10;
int a[N];
int n;
void solve() {
	cin>>n;
	int maxn=0;
	int minn=2e9;
	for(int i=1;i<=n;i++) cin>>a[i],maxn=max(maxn,a[i]),minn=min(minn,a[i]);
	if(maxn==minn){
		cout<<0<<endl;
		return;
	}
	int ans=0;
	vector<int>c;
	while(maxn!=minn+1){
		ans++;
		if(minn%2){
			maxn++;
			minn++;
			c.push_back(1);
		}
		else{
			c.push_back(0);
		}
		maxn/=2;
		minn/=2;
		if(maxn==0) break;
	}
	if(maxn==minn+1){
		cout<<ans+1<<endl;
		if(ans+1<=n){
			for(auto v:c) cout<<v<<' ';
			if(minn%2==0) cout<<2<<endl;
			else cout<<1<<endl;
		}
	}
	else{
		cout<<ans<<endl;
		if(ans<=n){
			for(auto v:c) cout<<v<<' ';
			cout<<endl;
		}
	}
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	cin>>t;
	while(t--) {
		solve();
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值