1 solutions

  • 0
    @ 2025-11-5 17:35:23

    C++ :

    #include<cstdio>
    #include<queue>
    using namespace std;
    struct Node{
        int id,be,las,lo;
        short per;
        bool friend operator < (Node a,Node b){
            if(a.per==b.per) return a.be>b.be;
            return a.per<b.per;
        }
    }ks,in,ls;
    int sum;
    int t;
    priority_queue<Node>op;
    int main(){
    	
        while(scanf("%d%d%d%hd",&in.id,&in.be,&in.las,&in.per)!=EOF){
    		in.lo=in.be;
            while(!op.empty()){
                ks=op.top();
                if(in.be-ks.lo>=ks.las){
                    t=ks.lo+ks.las;
    				op.pop();
                    printf("%d %d\n",ks.id,ks.lo+ks.las);
                    if(!op.empty()){
                        ks=op.top();
                        ks.lo=t;
                        op.pop();
                        op.push(ks);
                    }
                }
                else{
                    break;
                }
            }
            if(op.empty()||in.per<=op.top().per){
               // in.lo=in.be;
                op.push(in);
                continue;
            }
            else{
              /*  ks=op.top();
                if(in.per<=ks.per){
                    op.push(in);
                    continue;
                }
                else{*/
                   // ks=op.top();
                  //  ls=ks;
                   // ls.lo=ks.lo;
                    ks.las=ks.las-(in.be-ks.lo);
                    op.pop();
                    op.push(ks);
                  //  in.lo=in.be;
                    op.push(in);
                }
           // }
        }
    //  puts("*********");
        while(!op.empty()){
            ks=op.top();
            printf("%d %d\n",ks.id,ks.las+ks.lo);
            t=ks.las+ks.lo;
            op.pop();
            if(!op.empty()){
                ks=op.top();
                op.pop();
                ks.lo=t;
                op.push(ks);
            }
        }
    getchar(); getchar(); getchar();
    }
    
    
    • 1

    Information

    ID
    18577
    Time
    3000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By