codeforces AIM Tech Round3

A. Juicer
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.

The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section?

Input

The first line of the input contains three integers nb and d (1 ≤ n ≤ 100 0001 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer.

Output

Print one integer — the number of times Kolya will have to empty the waste section.

Examples
input
2 7 10
5 6
output
1
input
1 5 10
7
output
0
input
3 10 10
5 7 7
output
1
input
1 1 1
1
output
0
Note

In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.

In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all.

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int n,b,d,tot=0,i,j,k,ans=0;
	cin>>n>>b>>d;
	for(i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		if(x>b)continue;
		tot+=x;
		if(tot>d){
			ans++;
			tot=0;
		}
	} 
	cout<<ans;
}




B. Checkpoints
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x1, x2, ..., xn. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary order.

Vasya wants to pick such checkpoints and the order of visiting them that the total distance travelled is minimized. He asks you to calculate this minimum possible value.

Input

The first line of the input contains two integers n and a (1 ≤ n ≤ 100 000 - 1 000 000 ≤ a ≤ 1 000 000) — the number of checkpoints and Vasya's starting position respectively.

The second line contains n integers x1, x2, ..., xn ( - 1 000 000 ≤ xi ≤ 1 000 000) — coordinates of the checkpoints.

Output

Print one integer — the minimum distance Vasya has to travel in order to visit at least n - 1 checkpoint.

Examples
input
3 10
1 7 12
output
7
input
2 0
11 -10
output
10
input
5 0
0 0 1000 0 0
output
0
Note

In the first sample Vasya has to visit at least two checkpoints. The optimal way to achieve this is the walk to the third checkpoints (distance is 12 - 10 = 2) and then proceed to the second one (distance is 12 - 7 = 5). The total distance is equal to 2 + 5 = 7.

In the second sample it's enough to visit only one checkpoint so Vasya should just walk to the point  - 10.

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=100005;
int pos[maxn];
int main(){
	int n,a,i,j,k,ans,p;
	cin>>n>>a;
	ans=1e9;
	for(i=1;i<=n;i++){
		scanf("%d",&pos[i]);
	}
	n++;
	pos[n]=a;
	sort(pos+1,pos+1+n);
	for(i=1;i<=n;i++){
		if(pos[i]==a){
			p=i;
			break;
		}
	}
	for(i=max(0,p-2);i<=min(p-1,n-2);i++){
		int t1=p-i,t2=p+n-i-2;
		if(t2<p)t2=p;
		if(t1>p)t1=p;
		ans=min(ans,2*(a-pos[p-i])+pos[p+n-i-2]-a);
		ans=min(ans,a-pos[p-i]+2*(pos[p+n-i-2]-a));
	}
	cout<<ans;
}



C. Letters Cyclic Shift
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly one non-empty substring of s and shift all its letters 'z 'y 'x 'b 'a 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'.

What is the lexicographically minimum string that can be obtained from s by performing this shift exactly once?

Input

The only line of the input contains the string s (1 ≤ |s| ≤ 100 000) consisting of lowercase English letters.

Output

Print the lexicographically minimum string that can be obtained from s by shifting letters of exactly one non-empty substring.

Examples
input
codeforces
output
bncdenqbdr
input
abacaba
output
aaacaba
Note

String s is lexicographically smaller than some other string t of the same length if there exists some 1 ≤ i ≤ |s|, such thats1 = t1, s2 = t2, ..., si - 1 = ti - 1, and si < ti.

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
char change(char ch){
	if(ch=='a')return 'z';
	else return char(int(ch)-1);
}
int main(){
	string s;
	cin>>s;
	int i,j,k,len,start,end=1e9;
	bool flag=false;
	len=s.length();
	for(i=0;i<len;i++){
		if(s[i]!='a'&&(flag==false)){
			start=i;
			flag=true;
		}
		if(flag){
			if(s[i]=='a'){
				end=i-1;
				break;
			}
		}
	}
	if(flag==false){
		for(i=1;i<len;i++)printf("a");
		cout<<"z";
		return 0;
	}
	if(end==1e9)end=len-1;
	for(i=0;i<start;i++)printf("%c",s[i]);
	for(i=start;i<=end;i++)printf("%c",change(s[i]));
	for(i=end+1;i<len;i++)printf("%c",s[i]);
}





D. Recover the String
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

For each string s consisting of characters '0' and '1' one can define four integers a00a01a10 and a11, where axy is the number ofsubsequences of length 2 of the string s equal to the sequence {x, y}.

In these problem you are given four integers a00a01a10a11 and have to find any non-empty string s that matches them, or determine that there is no such string. One can prove that if at least one answer exists, there exists an answer of length no more than1 000 000.

Input

The only line of the input contains four non-negative integers a00a01a10 and a11. Each of them doesn't exceed 109.

Output

If there exists a non-empty string that matches four integers from the input, print it in the only line of the output. Otherwise, print "Impossible". The length of your answer must not exceed 1 000 000.

Examples
input
1 2 3 4
output
Impossible
input
1 2 2 1
output
0110

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
char ans[1000005];
long long A01,A10,remain0,remain1,len;
int main(){
	long long a00,a01,a10,a11,i,j,k,num0,num1,dt1,dt2;
	double t;
	cin>>a00>>a01>>a10>>a11;
	t=sqrt(1+8*a00);
	if(a00==0)num0=0;
	else if(fabs(t-double(ceil(t)))<=0.0000001){
		num0=(1+ceil(t))/2;
	}
	else{
		cout<<"Impossible";
		return 0;
	}
	t=sqrt(1+8*a11);
	if(a11==0)num1=0;
	else if(fabs(t-double(ceil(t)))<=0.0000001){
		num1=(1+ceil(t))/2;
	}
	else{
		cout<<"Impossible";
		return 0;
	}
	if(a00==0&&a11==0){
		if(a10!=0||a01!=0){
			num0=1;
			num1=1;
			if(a10==1&&a01==0){
				cout<<"10";
				return 0;
			}
			else if(a01==1&&a10==0){
				cout<<"01";
				return 0;
			}
			cout<<"Impossible";
			return 0;
		}
		cout<<"0";return 0;
	} 
	if(a00==0){
		if(a10!=0||a01!=0)num0=1;
	}
	if(a11==0){
		if(a10!=0||a01!=0)num1=1;
	}
	if(num1+num0>1000000){
		cout<<"Impossible";
		return 0;
	}
	A10=a10,A01=a01;
	remain0=num0,remain1=num1;
	len=num0+num1;
	for(i=1;i<=num0+num1;i++){
		if(remain1<=A01){
			ans[i]='0';
			A01-=remain1;
			remain0--;
		}
		else if(remain0<=A10){
			ans[i]='1';
			A10-=remain0;
			remain1--;
		}
		else break;
	}
	if(i==num0+num1+1&&A10==0&&A01==0){
		for(i=1;i<=num0+num1;i++){
			printf("%c",ans[i]);
		}
		return 0;
	}
	A10=a10;A01=a01;
	remain0=num0;
	remain1=num1;
	for(i=1;i<=num0+num1;i++){
		if(remain0<=A10){
			ans[i]='1';
			A10-=remain0;
			remain1--;
		}
		else if(remain1<=A01){
			ans[i]='0';
			A01-=remain1;
			remain0--;
		}
		else break;
	}
	if(i<=num0+num1||A10||A01){
		cout<<"Impossible";
		return 0;
	}
	else {
		for(i=1;i<=num0+num1;i++){
			printf("%c",ans[i]);
		}
		return 0;
	}
}



### Codeforces Round 927 Div. 3 比赛详情 Codeforces是一个面向全球程序员的比赛平台,定期举办不同级别的编程竞赛。Div. 3系列比赛专为评级较低的选手设计,旨在提供更简单的问题让新手能够参与并提升技能[^1]。 #### 参赛规则概述 这类赛事通常允许单人参加,在规定时间内解决尽可能多的问题来获得分数。评分机制基于解决问题的速度以及提交答案的成功率。比赛中可能会有预测试案例用于即时反馈,而最终得分取决于系统测试的结果。此外,还存在反作弊措施以确保公平竞争环境。 ### 题目解析:Moving Platforms (G) 在这道题中,给定一系列移动平台的位置和速度向量,询问某时刻这些平台是否会形成一条连续路径使得可以从最左端到达最右端。此问题涉及到几何学中的线段交集判断和平面直角坐标系内的相对运动分析。 为了处理这个问题,可以采用如下方法: - **输入数据结构化**:读取所有平台的数据,并将其存储在一个合适的数据结构里以便后续操作。 - **时间轴离散化**:考虑到浮点数精度误差可能导致计算错误,应该把整个过程划分成若干个小的时间间隔来进行模拟仿真。 - **碰撞检测算法实现**:编写函数用来判定任意两个矩形之间是否存在重叠区域;当发现新的连接关系时更新可达性矩阵。 - **连通分量查找技术应用**:利用图论知识快速求解当前状态下哪些节点属于同一个集合内——即能否通过其他成员间接相连。 最后输出结果前记得考虑边界条件! ```cpp // 假设已经定义好了必要的类和辅助功能... bool canReachEnd(vector<Platform>& platforms, double endTime){ // 初始化工作... for(double currentTime = startTime; currentTime <= endTime ;currentTime += deltaT){ updatePositions(platforms, currentTime); buildAdjacencyMatrix(platforms); if(isConnected(startNode,endNode)){ return true; } } return false; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值