POJ - 3104 Drying

去水时间越长,干的衣服就越多,因此具有单调性,二分时间t。把放在暖气片上去水看出是加快某件衣服的烘干速度,

取k-1作为增量,当t确定的时候,相当于有t次加速去水的机会,贪心选取不能自然干燥的衣服。

/*********************************************************
*            ------------------                          *
*   author AbyssalFish                                   *
**********************************************************/
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
using namespace std;

const int maxn = 1e5;
int n, a[maxn], k;

bool P(int t)
{
    int c = 0;
    for(int i = 0; i < n; i++){
        if(a[i] > t){
            if((c += (a[i]-t-1+k)/k) > t) return false; //2e9
        }
    }
    return true;
}

//#define LOCAL
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    while(~scanf("%d",&n)){
        for(int i = 0; i < n; i++) scanf("%d",a+i);
        scanf("%d",&k);
        int lb = 1, ub = *max_element(a,a+n);//1e9;
        if(k-- == 1) lb = ub;
        while(lb < ub){
            int md = (lb+ub)>>1;
            P(md) ? ub = md: lb = md+1;
        }
        printf("%d\n",lb);
    }

    return 0;
}

 

posted @ 2015-11-17 14:08  陈瑞宇  阅读(196)  评论(0编辑  收藏  举报