QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#268194#7744. Elevatortonylin1026TL 0ms3820kbC++202.6kb2023-11-28 13:13:052023-11-28 13:13:05

Judging History

你现在查看的是最新测评结果

  • [2023-11-28 13:13:05]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3820kb
  • [2023-11-28 13:13:05]
  • 提交

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';
        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++;
        } else {
            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();
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3820kb

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:


result: