zoukankan      html  css  js  c++  java
  • CF709A Juicer 模拟

    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 n, b 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
    Copy
    2 7 10
    5 6
    Output
    Copy
    1
    Input
    Copy
    1 5 10
    7
    Output
    Copy
    0
    Input
    Copy
    3 10 10
    5 7 7
    Output
    Copy
    1
    Input
    Copy
    1 1 1
    1
    Output
    Copy
    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>
    #include<cstdlib>
    #include<cstring>
    #include<string>
    #include<cmath>
    #include<map>
    #include<set>
    #include<vector>
    #include<queue>
    #include<bitset>
    #include<ctime>
    #include<deque>
    #include<stack>
    #include<functional>
    #include<sstream>
    //#include<cctype>
    //#pragma GCC optimize(2)
    using namespace std;
    #define maxn 300005
    #define inf 0x3f3f3f3f
    //#define INF 1e18
    #define rdint(x) scanf("%d",&x)
    #define rdllt(x) scanf("%lld",&x)
    #define rdult(x) scanf("%lu",&x)
    #define rdlf(x) scanf("%lf",&x)
    #define rdstr(x) scanf("%s",x)
    typedef long long  ll;
    typedef unsigned long long ull;
    typedef unsigned int U;
    #define ms(x) memset((x),0,sizeof(x))
    const long long int mod = 1e9 + 7;
    #define Mod 1000000000
    #define sq(x) (x)*(x)
    #define eps 1e-3
    typedef pair<int, int> pii;
    #define pi acos(-1.0)
    const int N = 1005;
    #define REP(i,n) for(int i=0;i<(n);i++)
    typedef pair<int, int> pii;
    inline ll rd() {
    	ll x = 0;
    	char c = getchar();
    	bool f = false;
    	while (!isdigit(c)) {
    		if (c == '-') f = true;
    		c = getchar();
    	}
    	while (isdigit(c)) {
    		x = (x << 1) + (x << 3) + (c ^ 48);
    		c = getchar();
    	}
    	return f ? -x : x;
    }
    
    ll gcd(ll a, ll b) {
    	return b == 0 ? a : gcd(b, a%b);
    }
    ll sqr(ll x) { return x * x; }
    
    /*ll ans;
    ll exgcd(ll a, ll b, ll &x, ll &y) {
    	if (!b) {
    		x = 1; y = 0; return a;
    	}
    	ans = exgcd(b, a%b, x, y);
    	ll t = x; x = y; y = t - a / b * y;
    	return ans;
    }
    */
    
    int n, b, d;
    int a[maxn];
    int c[maxn];
    
    int main()
    {
    	//ios::sync_with_stdio(0);
    	int cnt = 0; int tot = 0;
    	rdint(n); rdint(b); rdint(d);
    	for (int i = 1; i <= n; i++)rdint(a[i]);
    	for (int i = 1; i <= n; i++) {
    		if (a[i] > b)continue;
    		else c[++cnt] = a[i];
    	}
    	ll sum = 0;
    	for (int i = 1; i <= cnt; i++) {
    		if (sum + (ll)c[i] > d) {
    			sum = 0; tot++; continue;
    		}
    		else sum += (ll)c[i];
    	}
    	cout << tot << endl;
    	return 0;
    }
    
    EPFL - Fighting
  • 相关阅读:
    常见的HTTP状态码有哪些?
    使用Hbuild打包APP
    Android APK反编译
    小程序|页面跳转的方法
    vi/vim 命令
    webpack学习笔记
    egg框架学习笔记
    IOS弹出系统键盘后,页面不恢复
    js上传文件
    webpack学习笔记
  • 原文地址:https://www.cnblogs.com/zxyqzy/p/10127162.html
Copyright © 2011-2022 走看看