結果

問題 No.647 明太子
ユーザー kichirb3
提出日時 2018-03-02 08:35:45
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 46 ms / 4,500 ms
コード長 1,325 bytes
コンパイル時間 797 ms
コンパイル使用メモリ 80,692 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-27 02:47:01
合計ジャッジ時間 1,726 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

// No.647 明太子
// https://yukicoder.me/problems/no/647
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

int main() {
    cin.tie(nullptr);

    // メンバーの購入条件を設定
    int N;
    cin >> N;
    vector<pair<int, int>> criteria;
    for (auto i = 0; i < N; ++i) {
        int A, B;
        cin >> A >> B;
        criteria.emplace_back(make_pair(A, B));
    }

    // 明太子の価格と辛さを確認
    int M;
    cin >> M;
    vector<pair<int, int>> mentaiko;
    for (auto i = 0; i < M; ++i) {
        int X, Y;
        cin >> X >> Y;
        mentaiko.emplace_back(make_pair(X, Y));
    }

    // メンバごとに条件にマッチする明太子を購入
    vector<int> votes(M+1, 0);
    for (auto i = 0; i < N; ++i) {
        for (auto j = 0; j < M; ++j) {
            if (mentaiko[j].first <= criteria[i].first && mentaiko[j].second >= criteria[i].second)
                ++votes[j];
        }
    }

    int votes_max = *max_element(votes.begin(), votes.end()); // 奇跡の明太子の購入者数
    if (votes_max == 0) {
        cout << 0 << endl;
    } else {
        for (auto i = 0; i < M; ++i) {
            if (votes[i] == votes_max)
                cout << i + 1 << endl; // 0起算なので+1して出力
        }
    }
}
0