首页 > 其他分享 >csp202212-2

csp202212-2

时间:2023-02-25 15:23:10浏览次数:32  
标签:pre csp202212 int max flag mx

#include<bits/stdc++.h>
using namespace std;
int p[102];
int t[102];
int main(){
    int n,m;cin>>n>>m;
    bool flag=true;
    for(int i=1;i<=m;i++){
        scanf("%d",&p[i]);
    }
    for(int i=1;i<=m;i++){
        scanf("%d",&t[i]);
    }
    for(int i=1;i<=m;i++){//最早开始时间
        int pre=p[i];
        if(pre==0){
            printf("%d ",1);
        }else{
            int tot=1;
            while(pre!=0){
                tot+=t[pre];
                pre=p[pre];
            }
            printf("%d ",tot);
        }
    }
    cout<<"\n";
    for(int i=m-1;i>=1;i--){//最晚开始时间
        int mx=0;
        for(int j=m;j>=i+1;j--){
            int pre=p[j];
            //相当于i<-j把j所需要的时间加到i上
            //但是要考虑当i和k都->j
            if(pre==i){//找出所有前序为i的
                mx=max(t[j]+t[pre],mx);
            }
        }
        t[i]=max(t[i],mx);
        if(mx>n){flag=false;break;}
    }
    if(flag){
        for(int i=1;i<=m;i++){
            cout<<n-t[i]+1<<" ";
        }
    }
}

 

标签:pre,csp202212,int,max,flag,mx
From: https://www.cnblogs.com/yds0823/p/17154476.html

相关文章