codeforces AIM Tech Round 3 (Div. 2)

codeforces AIM Tech Round 3 (Div. 2)




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.


By Gerry99, contest: AIM Tech Round 3 (Div. 2), problem: (A) Juicer, Accepted#



#include <bits/stdc++.h>
const int INF = ~0U>>1;

using namespace std;
int ans;
int main(){
  int n, b, d;
  long long now = 0;
  scanf("%d%d%d", &n, &b, &d);
  for(int i = 1; i <= n; i++){
    int x;
    scanf("%d", &x);
    if(x <= b) now += x;
    if(now > d) ans++, now = 0;
  }
  if(now > d) ans++;
  printf("%d\n", 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.            



By Gerry99, contest: AIM Tech Round 3 (Div. 2), problem: (B) Checkpoints, Accepted#



#include <bits/stdc++.h>
const int INF = ~0U>>1;

using namespace std;
int n, a, pos[100005];
long long ans;
int main(){
  scanf("%d%d", &n, &a);
  for(int i = 1; i <= n; i++) {
      scanf("%d", &pos[i]);
  }
  pos[0] = a;
  int now;
  sort(pos, pos + n + 1);
  for(int i = 0; i <= n; i++) {
    if(a == pos[i]){
      now = i;
      break;
    }
  }
  ans = min(min(abs(pos[now] - pos[0]) * 2 + abs(pos[n - 1] - pos[now]), abs(pos[n - 1] - pos[now]) * 2 + abs(pos[now] - pos[0])), min(abs(pos[now] - pos[1]) * 2 + abs(pos[n] - pos[now]), abs(pos[n] - pos[now]) * 2 + abs(pos[now] - pos[1])));
  cout << ans << endl;
}


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.


By Gerry99, contest: AIM Tech Round 3 (Div. 2), problem: (C) Letters Cyclic Shift, Accepted#



#include <bits/stdc++.h>
const int INF = ~0U>>1;

using namespace std;
char s[100002];
int main(){
  scanf("%s", s);
  int left = -1, right = strlen(s) - 1;
  for(int i = 0; i < strlen(s); i++){
    if(left == -1 && s[i] != 'a') left = i;
    if(left != -1 && s[i] == 'a'){
      right = i - 1;
      break;
    }
  }
  if(left != -1) for(int i = left; i <= right; i++) s[i] = s[i] - 1;
  else s[right] = 'z';
  printf("%s\n", s);
}


B. 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.


By Gerry99, contest: AIM Tech Round 3 (Div. 1), problem: (B) Recover the String, Accepted#


#include <bits/stdc++.h>
const int INF = ~0U>>1;

using namespace std;
char ch[1000002];
long long a1, a2, a3, a4;
int find(double x){
    double res = (1 + sqrt(1+8*x))/2;
    long long t = res;
    if(t*(t-1)/2 != x) return -1;
    else return t;
}
int main(){
  scanf("%lld%lld%lld%lld", &a1, &a2, &a3, &a4);
  int num1, num0;
  num0 = find(a1);
  num1 = find(a4);
  if(num0 == -1 || num1 == -1) {
    cout << "Impossible\n";
    return 0;
  }
  if(a1 == 0 || a4 == 0){
    if(a1 == 0 && a4 == 0){
      if(a2 == 1 || a3 == 1) num0 = 1, num1 = 1;
      else if(a2 == 0 && a3 == 0){
        cout << "0\n";
        return 0;
      }
      else{
        cout << "Impossible\n";
        return 0;
      }
    }
    else if(a1 == 0){
      if(a2 != 0 || a3 != 0) num0 = 1;
      else{
        for(int i = 1; i <= num1; i++) cout << '1';
        cout << endl;
        return 0;
      }
    }
    else if(a4 == 0){
      if(a2 != 0 || a3 != 0) num1 = 1;
      else {
        for(int i = 1; i <= num0; i++) cout << '0';
        cout << endl;
        return 0;
      }
    }
  }
  if(num0 * num1 != a2 + a3) {
    printf("Impossible\n");
    return 0;
  }
  int tail0 = a3 / num1;
  int head0 = num0 - 1 - tail0;
  int pos0 = head0 + 1 + a3 - tail0 * num1;
  for(int i = 1; i <= head0; i++) ch[i] = '0';
  for(int i = num0 + num1; i >= num0 + num1 - tail0 + 1; i--) ch[i] = '0';
  ch[pos0] = '0';
  for(int i = 1; i <= num1 + num0; i++) if(ch[i] != '0') ch[i] = '1';
  for(int i = 1; i <= num0 + num1; i++) printf("%c", ch[i]);
  printf("\n");
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值