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 000, 1 ≤ 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.

题解:给你n个橙,要选小于等于b的橙做成果汁,如果放进果汁机的橙总和大于d,就要浪费一次。问你把这些橙全部做成果汁后,浪费了多少次。模拟一下就可以了。

代码:

#pragma comment(linker, "/STACK:102400000,102400000")
//#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<map>
#include<cmath>
#include<queue>
#include<set>
#include<stack>
#include <utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define mst(a) memset(a, 0, sizeof(a))
#define M_P(x,y) make_pair(x,y)
#define rep(i,j,k) for (int i = j; i <= k; i++)
#define per(i,j,k) for (int i = j; i >= k; i--)
#define lson x << 1, l, mid
#define rson x << 1 | 1, mid + 1, r
const int lowbit(int x) { return x&-x; }
const double eps = 1e-8;
const int INF = 1e9+7;
const ll inf =(1LL<<62) ;
const int MOD = 1e9 + 7;
const ll mod = (1LL<<32);
const int N = 110;
const int M=100010;
const int maxn=1001;
template <class T1, class T2>inline void getmax(T1 &a, T2 b) {if (b>a)a = b;}
template <class T1, class T2>inline void getmin(T1 &a, T2 b) {if (b<a)a = b;}
int read(){
int v = 0, f = 1;char c =getchar();
while( c < 48 || 57 < c ){if(c=='-') f = -1;c = getchar();}
while(48 <= c && c <= 57) v = v*10+c-48, c = getchar();
return v*f;}
int a;
int main()
{ll n,b,d;cin>>n>>b>>d;ll sum=0;ll ans=0;for(int i=0;i<n;i++){cin>>a;if(a<=b)sum+=a;if(sum>d)sum=0,ans++;   }cout<<ans;return 0;
}
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.

题意:给你n个点,要经过n-1个点才算完成比赛,问完成比赛的最小路程。

题解:因为要经过n-1个点,所以只要贪心一下a附近n-1个点就可以啦。

比如下面这图:a附近的X1到Xn-1。

还有的X0到Xn-2也一样。

再选其中路程最短就可以了。

代码:

#pragma comment(linker, "/STACK:102400000,102400000")
//#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<map>
#include<cmath>
#include<queue>
#include<set>
#include<stack>
#include <utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define mst(a) memset(a, 0, sizeof(a))
#define M_P(x,y) make_pair(x,y)
#define rep(i,j,k) for (int i = j; i <= k; i++)
#define per(i,j,k) for (int i = j; i >= k; i--)
#define lson x << 1, l, mid
#define rson x << 1 | 1, mid + 1, r
const int lowbit(int x) { return x&-x; }
const double eps = 1e-8;
const int INF = 1e9+7;
const ll inf =(1LL<<62) ;
const int MOD = 1e9 + 7;
const ll mod = (1LL<<32);
const int N = 110;
const int M=100010;
const int maxn=1001;
template <class T1, class T2>inline void getmax(T1 &a, T2 b) {if (b>a)a = b;}
template <class T1, class T2>inline void getmin(T1 &a, T2 b) {if (b<a)a = b;}
int read(){
int v = 0, f = 1;char c =getchar();
while( c < 48 || 57 < c ){if(c=='-') f = -1;c = getchar();}
while(48 <= c && c <= 57) v = v*10+c-48, c = getchar();
return v*f;}
ll num[200010];
int main()
{ll n,a;cin>>n>>a;for(int i=0;i<n;i++)cin>>num[i];sort(num,num+n);if(n==1){cout<<0;return 0;}ll x=min(abs(num[0]-a),abs(num[n-2]-a))+num[n-2]-num[0];ll y=min(abs(num[1]-a),abs(num[n-1]-a))+num[n-1]-num[1];cout<<min(x,y);return 0;
}
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 sand 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.
题解: 如果不是全部是a,就找到第一个不是a的子串shift。如果全部是a,最后一个a就变成z。
代码:
#pragma comment(linker, "/STACK:102400000,102400000")
//#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<map>
#include<cmath>
#include<queue>
#include<set>
#include<stack>
#include <utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define mst(a) memset(a, 0, sizeof(a))
#define M_P(x,y) make_pair(x,y)
#define rep(i,j,k) for (int i = j; i <= k; i++)
#define per(i,j,k) for (int i = j; i >= k; i--)
#define lson x << 1, l, mid
#define rson x << 1 | 1, mid + 1, r
const int lowbit(int x) { return x&-x; }
const double eps = 1e-8;
const int INF = 1e9+7;
const ll inf =(1LL<<62) ;
const int MOD = 1e9 + 7;
const ll mod = (1LL<<32);
const int N = 110;
const int M=100010;
const int maxn=1001;
template <class T1, class T2>inline void getmax(T1 &a, T2 b) {if (b>a)a = b;}
template <class T1, class T2>inline void getmin(T1 &a, T2 b) {if (b<a)a = b;}
int read(){
int v = 0, f = 1;char c =getchar();
while( c < 48 || 57 < c ){if(c=='-') f = -1;c = getchar();}
while(48 <= c && c <= 57) v = v*10+c-48, c = getchar();
return v*f;}int main()
{string s;cin>>s;int i=0;while(i<s.size() && s[i]=='a')i++;//cout<<"i="<<i<<endl;if(i==s.size()) s[s.size()-1]='z';for(;i<s.size();i++){if(s[i]=='a')break;s[i]=s[i]-1;}cout<<s;return 0;
}
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 a00, a01, a10 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 a00, a01, a10, a11 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 a00, a01, a10 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

题意:给你00,01,10,11这四个序列的个数。然后要你构造出合法的01序列。不存在合法的01序列就输出Impossible。

例如:0110有1个00,2个01,2个10,1个11。

题解:因为n*(n-1)=2*a00和m*(m-1)=2*a11和a01+a10=n*m。

所以可以先计算出0和1的数量,接下来先去构造a10,再构造a01就好了。构造题。
代码:
#pragma comment(linker, "/STACK:102400000,102400000")
//#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<map>
#include<cmath>
#include<queue>
#include<set>
#include<stack>
#include <utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define mst(a) memset(a, 0, sizeof(a))
#define M_P(x,y) make_pair(x,y)
#define rep(i,j,k) for (int i = j; i <= k; i++)
#define per(i,j,k) for (int i = j; i >= k; i--)
#define lson x << 1, l, mid
#define rson x << 1 | 1, mid + 1, r
const int lowbit(int x) { return x&-x; }
const double eps = 1e-8;
const int INF = 1e9+7;
const ll inf =(1LL<<62) ;
const int MOD = 1e9 + 7;
const ll mod = (1LL<<32);
const int N = 110;
const int M=100010;
const int maxn=1001;
template <class T1, class T2>inline void getmax(T1 &a, T2 b) {if (b>a)a = b;}
template <class T1, class T2>inline void getmin(T1 &a, T2 b) {if (b<a)a = b;}
int read(){
int v = 0, f = 1;char c =getchar();
while( c < 48 || 57 < c ){if(c=='-') f = -1;c = getchar();}
while(48 <= c && c <= 57) v = v*10+c-48, c = getchar();
return v*f;}ll a00,a01,a10,a11;
int main()
{ll n,m;cin>>a00>>a01>>a10>>a11;if(a00==0&&a01==0&&a10==0&&a11==0){cout<<0; return 0;}n=(1+(int)( sqrt(1+8*a00) ))/2; //n:0的个数 m=(1+(int)( sqrt(1+8*a11) ))/2; //m:1的个数 if(a01==0&&a10==0){if(a00==0) n=0;else m=0;}if(n*(n-1)!=2*a00||m*(m-1)!=2*a11||a01+a10!=n*m){cout<<"Impossible";return 0;}while(n+m){if(a01>=m){cout<<0;a01-=m;--n;}else{cout<<1;a10-=n;--m;}}return 0;
}

codeforces AIM Tech Round 3 (Div. 2) (A~D)相关推荐

  1. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

  2. Codeforces Round #712 Div.2(A ~ F) 超高质量题解(每日训练 Day.15 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #712 Div.2(A ~ F) 题解 比赛链接:https:// ...

  3. Codeforces Round #698 (Div. 2)(A ~ F)6题全,超高质量题解)【每日亿题】2021/2/4

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 [每日亿题]Codeforces Round #698 (Div. 2)(A ~ F)6题全,超 ...

  4. Codeforces Round #808 (Div. 1)(A~C)

    Codeforces Round #808 (Div. 1)(A~C) A:Doremy's IQ 题目大意 给你一个序列,然后你从左到右可以选择弄或者不弄. 然后你有一个智商值,如果你当前弄的数小于 ...

  5. Codeforces Round #699 (Div. 2) (A ~ F)6题全,超高质量良心题解【每日亿题】2021/2/6

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #699 (Div. 2) (A.B.C)[每日亿题]2021/2/ ...

  6. Codeforces Round #739 (Div. 3)(AK实况)

    Codeforces Round #739 (Div. 3) A. Dislike of Threes 找到第kkk个既不是333的倍数,个位数上也不是333的数,也已预处理然后O(1)O(1)O(1 ...

  7. Codeforces Round #703 (Div. 2)(A ~ F)超高质量题解【每日亿题2 / 19】

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A. Shifting Stacks B - Eastern Exhibition C1 - G ...

  8. Codeforces Round #764 (Div. 3)(A~G)

    考试结束rua!开始写题解. 这场打完后明显感觉到自己水平下降了很多,考试结束后该回回手了. 赛中过了A~D,F,E题题目读错了干想了一个多小时.....给整麻了 A. Plus One on the ...

  9. Codeforces Round #827 (Div. 4)(A~G)(F已更新)

    "爷爷,你关注的up主要更新拉!" 今天起开始CF/At不定期更新 A. Sum(暴力) 只需判断a,b,c是否为和关系即可 #include <bits/stdc++.h& ...

  10. Codeforces Round #784 (Div. 4)(A~F)

    更好的阅读体验 \color{red}{更好的阅读体验} 更好的阅读体验 文章目录 A. Division? B. Triple C. Odd/Even Increments D. Colorful ...

最新文章

  1. 2022-2028年中国氢化丁晴橡胶行业市场研究及前瞻分析报告
  2. 十个问题弄清JVMGC(二)
  3. ASP.NET Core 进程内(InProcess)托管(6)《从零开始学ASP.NET CORE MVC》:
  4. ASP.NET中Request.IsAuthenticated和Request.User.Identity.IsAuthenticated的区别
  5. 2 在会计中未发现任何后继凭证
  6. 链接(跳转)router-link 和 路由实例Router
  7. linux nginx安装php5.5,linux下搭建LNMP(linux+nginx+mysql+php)环境之mysql5.5安装
  8. 用计算机用图解法求理论塔板数,用Excel图解法求精馏塔理论塔板数.pdf
  9. routing zuul_金三银四跳槽季快到了:送上Spring cloud全家桶系列之Zuul
  10. 广告流量分析之评价指标的选择(二)
  11. python 除数总是提示为0_Python错误的处理方法
  12. 音频的相MATLAB,音频处理后频率响应和相位响应问题
  13. python多线程queue_python多线程+队列(提高爬虫时效性)
  14. 西部数据暂停与华为的合作关系及发货
  15. javascript怎么判断对象为空
  16. 基于iframe的CFS(Cross Frame Script)和Clickjacking(点击劫持)攻击
  17. FOR XML PATH 应用及其反向分解
  18. Unity导航小地图制作
  19. Python 爬取每日北上资金数据
  20. VS中进行C#编码时智能提示由英文切换为中文

热门文章

  1. 贝叶斯信念网络简介以及算法整理笔记
  2. ml5.js入门二(介绍)+featureExtractor特征提取器
  3. EPLAN中如何画屏蔽双绞线
  4. python中根据视频帧生成视频,保存为mp4格式
  5. 投资体系-01-房产投资-普通购房者和投资者 分水岭
  6. python制作qq机器人_使用python打造一个自己的QQ机器人 【基础篇】
  7. Android Camera聚焦区域和测光区域的设置
  8. STM32按键总结(低电平有效及上升沿有效)
  9. source ~/.bash_profile是什么意思
  10. ICCV 2019|70 篇论文抢先读,含目标检测/自动驾驶/GCN/等(提供PDF下载)