Codeforces AIM Tech Round3

Source: Internet
Author: User
Tags time limit
A. Juicer time limit per test 1 second memory limit per test 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 would put them in the juicer in the fixed order, starting with orange of s Ize A1, then orange of size A2 and so on. To being put in the juicer the orange must has a size not exceeding B, so if Kolya sees a orange that's strictly greater he Throws it away and continues with the next one.

The juicer has a special sections 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 is no more oranges) and continues to squeeze the juice. How many times would he have to empty the waste section? Input

The first line of the input contains three integers n, b and D (1≤n≤100 000, 1≤b≤d≤1)-the number of OR Anges, the maximum size of the orange that fits in the juicer and the value D, which determines the condition when the IS Te section should is emptied.

The second line contains n integers a1, a2, ..., A (1≤ai≤1)-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'll has to empty the waste section. Examples input

2 7
5 6
Output
1
Input
1 5
7
Output
0
Input
3
5 7 7
Output
1
Input
1 1 1
1
Output
0
Note

In the first sample, Kolya'll squeeze the juice from the oranges and empty of the waste section afterwards.

In the second sample, the Orange won ' t fit in the juicer so Kolya'll has 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 megabytes input standard input output standard OUTPU T

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

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

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

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

Print one integer-the minimum distance vasya have to travel on order to visit at least N-1 checkpoint. Examples input

3
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 have to visit at least and checkpoints. The optimal-achieve-the-walk to the third-checkpoints (distance is-12-10 = 2) and then proceed to the SEC Ond one (distance is 12-7 = 5). The total distance are 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 megabytes input standard input output stand ARD output

You are given a non-empty string s consisting of lowercase Chinese letters. You had 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 was replaced with the previous character of Chinese alphabet and ' a ' are replaced with ' Z '.

What's the lexicographically minimum string that can being obtained from s by performing this shift exactly once? Input

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.