QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#635582 | #7744. Elevator | hansue | TL | 1ms | 5504kb | C++14 | 1.4kb | 2024-10-12 20:14:11 | 2024-10-12 20:14:12 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N = 1e5;
int n;
LL k;
LL a[N + 3][2]; //floor i; even, odd
void sol(){
scanf("%d%lld", &n, &k);
memset(a, 0, sizeof a);
int maxf = 0;
for(int i = 1, c, w, f; i <= n; i++){
scanf("%d%d%d", &c, &w, &f);
maxf = max(maxf, f);
a[f][w & 1] += c;
}
int oddpos = maxf;
while(oddpos >= 1 && a[oddpos][1] == 0)
oddpos--;
LL ans = 0;
for(int f = maxf; f >= 1;){
while(f >= 1 && a[f][0] == 0 && a[f][1] == 0)
f--;
if(f == 0)
break;
LL tmp = 0;
int cost = f;
while(f >= 1 && (tmp + 2 * a[f][0] + a[f][1] <= k)){
tmp += 2 * a[f][0] + a[f][1];
f--;
}
if(f == 0){
ans += cost;
break;
}
if(tmp == k){
ans += cost;
continue;
}
if(tmp + 2 * a[f][0] > k){
a[f][0] -= (k - tmp) / 2;
if(tmp & 1){
if(a[f][1] > 0)
a[f][1]--;
else {
while(oddpos >= f || (oddpos >= 1 && a[oddpos][0] == 0))
oddpos--;
if(oddpos > 0){
a[oddpos][1]--;
}
}
}
ans += cost;
continue;
}
tmp += 2 * a[f][1];
a[f][1] -= k - tmp;
ans += cost;
}
printf("%lld\n", ans);
}
int main(){
int T;
scanf("%d", &T);
while(T--)
sol();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5504kb
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...