QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#268202 | #7744. Elevator | tonylin1026 | WA | 1ms | 3400kb | C++20 | 2.7kb | 2023-11-28 13:20:58 | 2023-11-28 13:21:00 |
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++;
}
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: 0
Wrong Answer
time: 1ms
memory: 3400kb
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:
31361839915155 100000
result:
wrong answer 1st lines differ - expected: '24', found: '31361839915155'