QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#694984#7744. ElevatorPinkychowwRE 0ms3588kbC++142.1kb2024-10-31 19:05:042024-10-31 19:05:05

Judging History

你现在查看的是最新测评结果

  • [2024-10-31 19:05:05]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3588kb
  • [2024-10-31 19:05:04]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct wp{
    ll h,sum,w;
    bool operator <(const wp s)const{
        return h<s.h;
    }
};
priority_queue<wp>j,o;
ll n,m,t;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>t;
    while(t--){
        cin>>n>>m;
        while(j.size())j.pop();while(o.size())o.pop();
        for(int i=1;i<=n;i++){
            int x,y,z;cin>>x>>y>>z;
            if(z&1)j.push({z,x,y});else o.push({z,x,y});
        }
        ll ans=0,lm=0;
        while(j.size() || o.size()){
            if(lm==1){
                lm=0;
                if(!j.empty()){
                    auto u=j.top();j.pop();
                    u.sum--;
                    if(u.sum)j.push(u);
                }
            }
            if(!lm){
                lm=m;
                if(j.empty())ans+=o.top().h;
                else if(o.empty())ans+=j.top().h;
                else ans+=max(j.top().h,o.top().h);
            }
            int cs=0;
            if(j.empty() || (!j.empty() && !o.empty() &&j.top().h<o.top().h))cs=1;
            if(cs==0){
                auto u=j.top();j.pop();
                ll dc=m/u.w;
                if(dc<u.sum){
                    ans+=u.h*(u.sum/dc);
                    u.sum=u.sum%dc;
                }
                if(u.sum>lm/u.w){
                    u.sum-=lm/u.w;
                    lm=lm%u.w;
                    j.push(u);
                }
                else {
                    lm-=u.sum*u.w;
                }
            }
            else {
                auto u=o.top();o.pop();
                ll dc=m/u.w;
                if(dc<u.sum){
                    ans+=u.h*(u.sum/dc);
                    u.sum=u.sum%dc;
                }
                if(u.sum>lm/u.w){
                    u.sum-=lm/u.w;
                    lm=lm%u.w;
                    o.push(u);
                }
                else {
                    lm-=u.sum*u.w;
                }                
            }
        }
        cout<<ans<<'\n';
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3588kb

input:

2
4 6
1 1 8
7 2 5
1 1 7
3 2 6
8 1200000
100000 1 100000
100000 1 12345
100000 2 100000
100000 2 12345
100000 1 100000
100000 1 12345
100000 2 100000
100000 2 12345

output:

24
100000

result:

ok 2 lines

Test #2:

score: -100
Runtime Error

input:

5501
8 104
5 2 3
6 2 4
5 2 3
6 2 9
8 2 4
2 1 3
7 2 4
8 2 8
1 290
3 1 1
12 12
6 1 2
1 2 2
1 1 2
1 2 4
6 1 1
1 2 5
6 1 4
4 1 4
6 2 4
6 2 5
4 2 5
4 1 4
5 334
1 1 4
1 2 3
4 2 1
5 1 1
2 1 2
13 218
5 2 3
5 1 4
1 2 1
1 2 5
3 2 2
1 1 3
4 2 2
1 2 5
2 2 1
2 1 5
3 2 1
5 2 1
1 1 4
10 260
7 2 1
5 1 1
5 2 4
6 1 6...

output:


result: