0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[AtCoder備忘録記事]AtCoder Beginner Contest 348 C問題

Posted at

AtCoder Beginner Contest 348 C問題
こちらの問題です。

問題

image.png

入出力例

image.png

解法

mapでそれぞれの色でグループ化し、それぞれのグループの最小値の中での最大の値を出力します。

#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <cmath> 
#include <map>
#include <algorithm>
#include <limits>
using namespace std;


int main() {
    int N;
    cin >> N;
    map<int, vector<int>> groups;

    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        groups[y].push_back(x);
    }

    int maxOfMins = numeric_limits<int>::min(); 

    for (const auto& group : groups) {
        int minInGroup = *min_element(group.second.begin(), group.second.end());
        maxOfMins = max(maxOfMins, minInGroup);
    }

    cout << maxOfMins << endl;

    return 0;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?