結果
| 問題 |
No.2422 regisys?
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-06 05:36:19 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,063 bytes |
| コンパイル時間 | 1,458 ms |
| コンパイル使用メモリ | 124,644 KB |
| 実行使用メモリ | 21,292 KB |
| 最終ジャッジ日時 | 2024-09-29 18:12:55 |
| 合計ジャッジ時間 | 12,388 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 40 WA * 21 |
ソースコード
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int main () {
int N, M; cin >> N >> M;
vector<int> A(N), B(N);
for (int i = 0; i < N; i++) cin >> A[i];
for (int i = 0; i < N; i++) cin >> B[i];
map<int, int> mma, non_mma;
for (int i = 0; i < M; i++) {
int T, C; cin >> T >> C;
if (T == 0) {
non_mma[C]++;
}
if (T == 1) {
mma[C]++;
}
}
enum TYPE {
MMA,
NON_MMA,
};
vector<bool> is_sold(N, false);
vector<tuple<int, TYPE, int>> items; // (idx, type, cost)
for (int i = 0; i < N; i++) {
items.push_back(make_tuple(i, MMA, B[i]));
items.push_back(make_tuple(i, NON_MMA, A[i]));
}
sort(items.begin(), items.end(), [](tuple<int, int, int> a, tuple<int, int, int> b) { return get<2>(a) > get<2>(b); });
for (auto& v : items) {
int idx = get<0>(v);
TYPE type = get<1>(v);
int cost = get<2>(v);
// もう売れている
if (is_sold[idx]) continue;
// 誰も買えない
if (mma.lower_bound(cost) == mma.end()
&& non_mma.lower_bound(cost) == non_mma.end()) continue;
auto nit = non_mma.lower_bound(cost);
auto it = mma.lower_bound(cost);
if (type == MMA) {
if (nit == non_mma.end()) {
(it->second)--;
if (it->second == 0) mma.erase(it);
}
else {
(nit->second)--;
if (nit->second == 0) non_mma.erase(nit);
}
}
if (type == NON_MMA) {
if (it == mma.end()) {
(nit->second)--;
if (nit->second == 0) non_mma.erase(nit);
}
else {
(it->second)--;
if (it->second == 0) mma.erase(it);
}
}
is_sold[idx] = true;
}
int ans = 0;
for (const auto& v : is_sold) if (!v) ans++;
cout << ans << "\n";
}