본문 바로가기

Programming/BaekJoon

[C++] 백준 10040번 : 투표


https://www.acmicpc.net/problem/10040




#include <iostream>

using namespace std;

int main() {

int n, m;

cin >> n >> m;

int *A = new int[n];

int *cnt = new int[n];

int *B = new int[m];


for (int i = 0; i < n; i++)

cnt[i] = 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++)

for (int j = 0; j < n; j++)

if (A[j] <= B[i])

{

cnt[j]++;

break;

}


int max=0,max_index = 0;

for (int i = 0; i < n; i++)

if (cnt[i] > max)

{

max = cnt[i];

max_index = i;

}


cout << max_index+1;

}