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 894 (Div. 3) 是一个Codeforces举办的比赛,是第894轮的Div. 3级别比赛。它包含了一系列题目,其中包括题目E. Kolya and Movie Theatre。 根据题目描述,E. Kolya and Movie Theatre问题要求我们给定两个字符串,通过三种操作来让字符串a等于字符串b。这三种操作分别为:交换a中相同位置的字符、交换a中对称位置的字符、交换b中对称位置的字符。我们需要先进行一次预处理,替换a中的字符,然后进行上述三种操作,最终得到a等于b的结果。我们需要计算预处理操作的次数。 根据引用的讨论,当且仅当b[i]==b[n-i-1]时,如果a[i]!=a[n-i-1],需要进行一次操作;否则不需要操作。所以我们可以遍历字符串b的前半部分,判断对应位置的字符是否与后半部分对称,并统计需要进行操作的次数。 以上就是Codeforces Round 894 (Div. 3)的简要说明和题目E. Kolya and Movie Theatre的要求。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Codeforces Round #498 (Div. 3) (A+B+C+D+E+F)](https://blog.csdn.net/qq_46030630/article/details/108804114)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [Codeforces Round 894 (Div. 3)A~E题解](https://blog.csdn.net/gyeolhada/article/details/132491891)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值