카카오 코딩 테스트 풀이
무지의 먹방 라이브
by paysmile
2019. 9. 2.
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX = 1001;
vector<pair<int, int>> v;
bool cmp(pair<int, int> a, pair<int, int> b) {
if (a.second < b.second)
return true;
return false;
}
int solution(vector<int> food_times, long long k) {
int answer = -1;
int counts = 0;
int n = food_times.size();
for (int i = 0; i < food_times.size(); i++) {
v.push_back(make_pair(food_times[i],i+1));
}
sort(v.begin(), v.end());
for (vector<pair<int, int>>::iterator it = v.begin(); it != v.end();it++,n--) {
long long time = (long long) (it->first - counts) * n;
if (time == 0)
continue;
if (k >= time) {
counts = it->first;
k = k - time;
}
else {
k = k % n;
sort(it, v.end(),cmp);
answer = (it + k)->second;
break;
}
}
return answer;
}