Coding_Test 연습/SWEA

[SWEA] (C++) D4 3347 올림픽 종목 투표

Codetesing 2022. 4. 13. 05:28

딱히 어렵지 않은 문제다.

문제의 조건만 잘 이해 한다면 쉬운문제다. 가장 Bi이하중 큰 종목이 아니라 가장 앞의 종목인것을 유의해서 풀면 된다.

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(int argc, char** argv)
{
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int test_case;
	int T;

	cin >> T;

	for (test_case = 1; test_case <= T; ++test_case)
	{
		int N, M; cin >> N >> M;
		vector<int> A(N);
		vector<int> B(M);
		vector<int> voted(N, 0);
		for (int i = 0; i < N; i++) cin >> A[i];
		for (int i = 0; i < M; i++) cin >> B[i];

		for (int i = 0; i < M; i++)
		{
			int max_A = 0;
			int index = 0;

			for (int j = 0; j < N; j++)
				if (A[j] <= B[i])
				{
					index = j;
					break;
				}

			voted[index]++;
		}

		int out = max_element(voted.begin(), voted.end()) - voted.begin();

		cout << '#' << test_case << ' ' << out + 1<< '\n';
	}
	return 0;
}