QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#635666 | #7744. Elevator | hansue | TL | 1ms | 5364kb | C++14 | 1.6kb | 2024-10-12 20:32:50 | 2024-10-12 20:32:50 |
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
int m, b[N + 3];
void next(int &f){
int i = lower_bound(b + 1, b + m + 1, f) - b - 1;
if(i == m)
f = 0;
else
f = b[i + 1];
}
void sol(){
scanf("%d%lld", &n, &k);
memset(a, 0, sizeof a);
m = 0;
for(int i = 1, c, w, f; i <= n; i++){
scanf("%d%d%d", &c, &w, &f);
a[f][w & 1] += c;
b[++m] = f;
}
sort(b + 1, b + m + 1, greater<int>());
m = unique(b + 1, b + m + 1) - b - 1;
int oddpos = 1;
LL ans = 0;
for(int i = 1; i <= m;){
int f = b[i];
while(i <= m && a[b[i]][0] == 0 && a[b[i]][1] == 0)
i++;
if(i == m + 1)
break;
LL tmp = 0;
int cost = b[i];
while(i <= m && (tmp + 2 * a[b[i]][0] + a[b[i]][1] <= k)){
tmp += 2 * a[b[i]][0] + a[b[i]][1];
i++;
}
if(i == m + 1){
ans += cost;
break;
}
if(tmp == k){
ans += cost;
continue;
}
if(tmp + 2 * a[b[i]][0] > k){
a[b[i]][0] -= (k - tmp) / 2;
if(tmp & 1){
if(a[b[i]][1] > 0)
a[b[i]][1]--;
else {
while(oddpos <= i || (oddpos <= m && a[oddpos][0] == 0))
oddpos++;
if(oddpos <= m){
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: 5364kb
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...