This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "king.h"
long long SendInfo(std::vector<int> W, std::vector<int> C) {
return 0;
}
#include "vassal.h"
#include <algorithm>
#include <iostream>
std::vector<std::pair<int, int>> chair; // chair weight, order of chair
std::vector<std::pair<int, int>> num; // chair total, chair remain
void Init(long long B, std::vector<int> C){
int N = C.size();
for (int i = 0; i < N; i++) {
if (!chair.empty() && chair.back().first == C[i]) {
num.back().first++, num.back().second++;
}
else {
chair.push_back(std::pair<int, int>(C[i], i));
num.push_back(std::pair<int, int>(1, 1));
}
}
}
int findidx(int first, int last, int weight, int cut) {
int mid;
while (first <= last) {
mid = (first + last) / 2;
if (mid != cut && chair[mid - 1].first < weight && chair[mid].first >= weight) {
return mid;
}
else if (chair[mid].first < weight) {
first = mid + 1;
}
else if (chair[mid].first >= weight && mid == cut) {
return mid;
}
else {
last = mid - 1;
}
}
return -1;
}
int Maid(int W){
int first = 0, last = (int)chair.size() - 1;
int idx;
while (1) {
idx = findidx(first, last, W, first);
if (idx == -1) {
return -1;
}
if (num[idx].second > 0) {
int index = chair[idx].second + (num[idx].first - num[idx].second);
num[idx].second--;
return index;
}
else {
for (int i = idx + 1; i < (int)chair.size(); i++) {
if (num[i].second > 0) {
int index = chair[i].second + (num[i].first - num[i].second);
num[i].second--;
return index;
}
}
return -1;
}
}
return -1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |