QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#658724 | #7744. Elevator | mitthu | TL | 0ms | 3920kb | C++17 | 2.5kb | 2024-10-19 17:28:25 | 2024-10-19 17:28:30 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
const int maxn = 1e5 + 5;
using namespace std;
int n, T;
ll k, ans;
struct node{
int c, w, f;
bool operator<(const node &x)const{
if(f != x.f) return f > x.f;
else if(w != x. w) return w > x.w;
else return c > x.c;
}
}st[maxn];
set<int> one, zero;
void add(int x, int w){
if(w == 1) one.insert(x);
else zero.insert(x);
}
void del(int x, int w){
if(w == 1) one.erase(x);
else zero.erase(x);
}
int main(){
scanf("%d",&T);
for (; T; T--){
scanf("%d %lld",&n, &k);ans = 0;
one.clear();zero.clear();
for (int i = 1; i <= n; i++)
scanf("%d %d %d",&st[i].c, &st[i].w, &st[i].f);
sort(st + 1, st + n + 1);
for (int i = 1; i <= n; i++)
add(i, st[i].w);
while(one.size() > 0 || zero.size() > 0){
int l = n + 1;
if(one.size() > 0) l = min(l, *one.begin());
if(zero.size() > 0) l = min(l, *zero.begin());
if(1LL * st[l].c *st[l].w > k){
ll cnt = 1LL * st[l].c * st[l].w / k;
st[l].c -= (k / st[l].w) * cnt; ans += 1LL * cnt * st[l].f;
}
if(st[l].c <= 0)del(l, st[l].w);
if(st[l].c <= 0) continue;
ll res = k - 1LL * st[l].c * st[l].w;del(l, st[l].w);
while(1){
if(one.size() == 0 && zero.size() == 0) break;
if(res == 0) break;
if(res == 1 && one.size() == 0)break;
if(one.size() > 0 && zero.size() > 0){
int r = min(*one.begin(), *zero.begin());
int num = min(1LL*st[r].c, res / st[r].w);
st[r].c -= num, res -= 1LL* num * st[r].w;
if(!st[r].c)del(r, st[r].w);
}
else if(one.size() > 0){
int r = *one.begin();
int num = min(1LL*st[r].c, res / st[r].w);
st[r].c -= num, res -= 1LL* num * st[r].w;
if(!st[r].c)del(r, st[r].w);
}
else {
int r = *zero.begin();
int num = min(1LL*st[r].c, res / st[r].w);
st[r].c -= num, res -= 1LL* num * st[r].w;
if(!st[r].c)del(r, st[r].w);
}
}
ans += st[l].f;
}
printf("%lld\n", ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3920kb
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
Time Limit Exceeded
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...