洛谷P2827 蚯蚓-noip2007

先砍掉的同比例的一定比后砍掉的长,排序后分为3队,每次取最值。

#include <cstdio>
#include <queue>
#include <algorithm>
#include <cstring>
#include<iostream>
using namespace std;

const int maxn=7e6+10,inf=2e9;
int n,m,qa,u,v,t,add,a[maxn];
int q[3][maxn],head[3]= {1,1,1},tail[3];
int cmp(int x,int y) { return x>y;}
int get_front(int x) {
    if(head[x]>tail[x])return -inf;
    else return q[x][head[x]]+add;
}
int compare_front() {
    int maxq=-inf,pos;
    for(int i=0; i<3; i++){
        int x=get_front(i);
        if(x>maxq)maxq=x,pos=i;
    }	
    q[pos][head[pos]++];//最大数据出队;
    return maxq;
}

int main() {
    scanf("%d%d%d%d%d%d",&n,&m,&qa,&u,&v,&t);
    for(int i=1; i<=n; i++) scanf("%d",&q[0][i]);
    sort(q[0]+1,q[0]+n+1,cmp);
    tail[0]=n;
    for(int i=1; i<=m; add+=qa,i++) {
        int cur=compare_front(),
            l1=(long long)cur*u/v,
            l2=cur-l1;
        q[1][++tail[1]]=l1-add-qa;
        q[2][++tail[2]]=l2-add-qa;
        if(i%t==0) printf("%d ",cur);
    }
    printf("\n");
    for(int i=1; i<=n+m; i++) {
        int x=compare_front();
        if(i%t==0)printf("%d ",x);
    }
    printf("\n");
    return 0;
}

猜你喜欢

转载自blog.csdn.net/lengxuenong/article/details/81542637
今日推荐