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 <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,m;
cin >> n >> m;
std::vector<int> times(m);
std::vector<int> positions(m);
for (int i = 0; i < m; i++) {
cin >> times[i];
}
for (int i = 0; i < m; i++) {
cin >> positions[i];
}
std::vector<int> idxes(m);
std::iota(idxes.begin(), idxes.end(), 0);
// for (int i = 0; i < m; i++) {
// idxes.push_back(i);
// }
std::sort(idxes.begin(), idxes.end(), [times, positions](int ia, int ib){
int sa = times[ia] + positions[ia];
int sb = times[ib] + positions[ib];
return sa == sb ? times[ia] < times[ib] : sa < sb;
});
std::vector<int> asdf(m);
for (int i = 0; i < m; i++) {
asdf[i] = positions[i]-times[i];
}
std::vector<int> frontier;
int num_arms = 0;
for (int idx : idxes) {
int sel = num_arms;
for (int st = 1<<20; st >>= 1; st > 0) {
int idx2 = sel-st;
if (idx2 < 0) continue;
if (asdf[idx] > frontier[idx2]) continue;
sel -= st;
}
// for (int i = 0; i < num_arms; i++) {
// int idx2 = frontier[i];
// // check if we can reach the button
// if (positions[idx]-times[idx] > positions[idx2]-times[idx2]) continue;
// // use the "least useful" hand
// if (selected_score < positions[idx2]-times[idx2]) continue;
// // cout << idx2 << " is better\n";
// selected_score = positions[idx2]-times[idx2];
// selected_idx = i;
// }
if (sel == num_arms) {
// cout << "pushed" << "\n";
frontier.push_back(asdf[idx]);
num_arms++;
} else {
// cout << "replaced " << sel << "\n";
frontier[sel] = asdf[idx];
}
// cout << "frontier: ";
// for (int i : frontier) {
// cout << i << " ";
// }
// cout << "\n";
}
cout << num_arms << '\n';
}
Compilation message (stderr)
Arcade.cpp: In function 'int main()':
Arcade.cpp:46:43: warning: for increment expression has no effect [-Wunused-value]
46 | for (int st = 1<<20; st >>= 1; st > 0) {
| ~~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |