QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#695040 | #7744. Elevator | Pinkychoww | RE | 0ms | 3708kb | C++14 | 2.1kb | 2024-10-31 19:12:49 | 2024-10-31 19:12:50 |
Judging History
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(y>m)continue;
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 && dc){
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 && dc){
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';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3708kb
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...