QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#268203 | #7744. Elevator | tonylin1026 | TL | 1ms | 3596kb | C++20 | 2.7kb | 2023-11-28 13:21:29 | 2023-11-28 13:21:30 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define ite map<int, int, greater<int>>::iterator
using namespace std;
struct node {
int c, w, f;
};
void solve() {
int n, k;
cin >> n >> k;
map<int, int, greater<int>> mp[3];
for (int i = 0; i < n; i++) {
int c, w, f;
cin >> c >> w >> f;
if (w == 1) {
mp[1][f] += c;
} else
mp[2][f] += c;
}
int ans = 0, last = k, nowf = 0;
for (ite it1 = mp[1].begin(), it2 = mp[2].begin();
it1 != mp[1].end() || it2 != mp[2].end();) {
// cerr<<ans<<' '<<last<<' '<<nowf<<'\n';
// cerr<<(*it1).first<<' '<<(*it2).first<<'\n';
if (it1 == mp[1].end() || (*it2).first >= (*it1).first) {
if ((*it2).second * 2 < last) {
nowf = max(nowf, (*it2).first), last -= (*it2).second * 2;
} else if ((*it2).second * 2 == last) {
ans += max(nowf, (*it2).first), nowf = 0, last = k;
} else {
if (last & 1) {
if (it1 != mp[1].end()) {
(*it1).second--, last--;
if ((*it1).second == 0) {
it1++;
}
}
}
(*it2).second -= last / 2, ans += max(nowf, (*it2).first),
last = k, nowf = (*it2).first;
ans += (*it2).second / (last / 2) * nowf;
(*it2).second %= (last / 2);
if ((*it2).second == 0) {
nowf = 0;
} else {
last -= (*it2).second * 2;
}
}
it2++;
continue;
}
if (it2 == mp[2].end() || (*it2).first < (*it1).first) {
if ((*it1).second < last) {
nowf = max(nowf, (*it1).first), last -= (*it1).second;
} else if ((*it1).second == last) {
ans += max(nowf, (*it1).first), nowf = 0, last = k;
} else {
(*it1).second -= last, ans += max(nowf, (*it1).first),
last = k, nowf = (*it1).first;
ans += (*it1).second / last * nowf;
(*it1).second %= last;
if ((*it1).second == 0) {
nowf = 0;
} else {
last -= (*it1).second;
}
}
it1++;
}
}
if (last != k) {
ans += nowf;
}
cout << ans << '\n';
return;
}
signed main() {
// ios::sync_with_stdio(0), cin.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3596kb
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...