QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#279044 | #7744. Elevator | Freeuni1# | TL | 0ms | 3556kb | C++17 | 1.8kb | 2023-12-08 03:48:56 | 2023-12-08 03:48:57 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define MAXA(x, y) (x) = ((x) > (y)) ? (x) : (y)
#define MINA(x, y) (x) = ((x) < (y)) ? (x) : (y)
#define MAX(x, y) ((x) > (y)) ? (x) : (y)
#define MIN(x, y) ((x) < (y)) ? (x) : (y)
#define ADD(x, y, mod) (x) = (((x)+(y) >= (mod)) ? ((x)+(y) - (mod)) : (((x)+(y) < 0) ? ((x)+(y)+(mod)) : ((x)+(y))) )
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define count1(x) __builtin_popcount(x)
#define endl '\n'
using namespace std;
// lllllllllllll
const int N = 102;
void test_case(){
ll n, k;
cin >> n >> k;
pair<int, pii> P[n];
for(int i = 0; i < n; i++){
cin >> P[i].ss.ff >> P[i].ss.ss >> P[i].ff;
}
sort(P, P+n);
vector<int> v;
for(int i = 0; i < n; i++){
if(P[i].ss.ss == 1){
v.push_back(i);
}
}
int p = n-1;
ll answer = 0;
while(p >= 0){
ll cur = 0;
answer += P[p].ff;
while(p >= 0 && cur <= k-1){
auto [f, a] = P[p];
auto [c, w] = a;
ll rao = min((k - cur)/w, (ll)c);
cur += rao * w;
P[p].ss.ff -= rao;
if(P[p].ss.ff == 0) p--;
//cout << cur << endl;
}
if(cur < k && p >= 0){
while(v.size() > 0 && v.back() > p) v.pop_back();
if(v.size()){
P[v.back()].ss.ff--;
if(P[v.back()].ss.ff == 0) v.pop_back();
}
}
}
cout << answer << endl;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t = 1;
cin >> t;
while(t--){
test_case();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3556kb
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...