QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#265369 | #7744. Elevator | ucup-team1074 | TL | 0ms | 8376kb | C++20 | 2.2kb | 2023-11-25 18:04:42 | 2023-11-25 18:04:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define x first
#define y second
#define endl '\n'
const LL maxn = 4e05+7;
const LL N = 1e05+10;
const LL mod = 1e09+7;
const int inf = 0x3f3f;
const LL llinf = 5e18;
typedef pair<int,int>pl;
priority_queue<LL , vector<LL>, greater<LL> >mi;//小根堆
priority_queue<LL> ma;//大根堆
LL gcd(LL a, LL b){
return b > 0 ? gcd(b , a % b) : a;
}
LL lcm(LL a , LL b){
return a / gcd(a , b) * b;
}
LL n , m;
LL a[N];
vector<vector<LL>>cnt_f(N , vector<LL>(2));
void init(int n){
for(int i = 0 ; i <= n ; i ++){
a[i] = 0 ,cnt_f[i][0] = cnt_f[i][1] = 0;
}
}
void solve()
{
cin >> n >> m;
set<LL>num;
set<int>st[2];
for(int i = 0 ; i < n ; i ++){
LL x , y , z;
cin >> x >> y >> z;
num.insert(z);
cnt_f[z][y - 1] += x;
st[y - 1].insert(z);
}
vector<LL>f;
for(auto it : num){
f.pb(it);
}
auto cmp = [&](int x , int y){
return x > y;
};
sort(f.begin() , f.end() , cmp);
LL res = 0;
int len = f.size();
for(int i = 0 ; i < len ; ){
LL eve = m;
LL t = f[i];
while(i < len && eve >= cnt_f[f[i]][0] + cnt_f[f[i]][1] * 2){
eve -= cnt_f[f[i]][0] + cnt_f[f[i]][1] * 2;
st[0].erase(f[i]);
st[1].erase(f[i]);
cnt_f[f[i]][0] = 0;
cnt_f[f[i]][1] = 0;
i++;
}
if(i >= len){
res += t;
break;
}
if(eve >= cnt_f[f[i]][1] * 2){
eve -= cnt_f[f[i]][1] * 2;
cnt_f[f[i]][1] = 0;
st[1].erase(f[i]);
}
else{
cnt_f[f[i]][1] -= eve / 2;
eve = eve % 2 == 0 ? 0 : 1;
}
if(eve >= cnt_f[f[i]][0]){
eve -= cnt_f[f[i]][0];
cnt_f[f[i]][0] = 0;
st[0].erase(f[i]);
}
else{
cnt_f[f[i]][0] -= eve;
eve = 0;
}
if(eve > 0){
auto it = st[0].lower_bound(f[i]);
if(it != st[0].begin()){
it--;
int x = *it;
cnt_f[x][0]--;
if(cnt_f[x][0] == 0){
st[0].erase(x);
}
}
}
res += t;
}
cout << res << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout.precision(10);
int t=1;
cin>>t;
while(t--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 8376kb
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...
output:
9 1 23 4 5 7 1 3 9 6 1 10 4 9 17 6 4 1 8 5 5 7 1 3 23 6 3 3 2 2 2 3 8 1 5 6 9 11 147 7 10 2 7 7 8 6 5 5 1 7 3 5 10 7 7 10 8 1 4 2 3 9 1 5 2 9 1 6 7 7 6 10 18 8 10 4 10 9 2 8 3 5 9 3 6 5 3 2 6 1 3 2 2 1 6 9 6 3 4 8 9 9 2 6 1 2 6 7 5 2 5 21 8 1 2 3 4 9 3 4 6 5 9 6 1 7 3 7 3 2 2 8 7 3 5 9 7 10 7 3 2 4 ...