Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <algorithm>
- #include <vector>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- int len, buses;
- cin >> len >> buses;
- vector<int> v(buses);
- vector<int> occupied(len + 1, 0);
- for(int& x : v) {
- cin >> x;
- occupied[x] = -1;
- }
- int bus_length, cnt;
- cin >> cnt >> bus_length;
- int tmp = 0;
- vector<pair<int, int> > spaces;
- int sum = 0;
- int idx = -1;
- for(int i = 1; i <= len; i++) {
- if(occupied[i] == -1 and tmp > 0) {
- spaces.push_back(make_pair(tmp / bus_length, idx));
- idx = -1;
- sum += (tmp / bus_length);
- tmp = 0;
- }
- else if(occupied[i] == 0){
- if(idx == -1) {
- idx = i;
- }
- ++tmp;
- }
- }
- if(tmp > 0) {
- spaces.push_back(make_pair(tmp / bus_length, idx));
- sum += (tmp / bus_length);
- }
- sort(spaces.rbegin(), spaces.rend());
- int ret = 0;
- vector<pair<int, int> > ans;
- for(int i = 0; i < (int) spaces.size(); i++) {
- if(sum - spaces[i].first >= cnt) {
- sum -= spaces[i].first;
- ret += spaces[i].first;
- ans.push_back(make_pair(spaces[i].first, spaces[i].second));
- }
- else {
- ret += sum + 1 - cnt;
- ans.push_back(make_pair((sum + 1 - cnt), spaces[i].second));
- sum -= (sum + 1 - cnt);
- break;
- }
- }
- cout << ret << endl;
- for(int i = 0; i < (int) ans.size(); i++) {
- // cout << ans[i].first << " " << ans[i].second << endl;
- for(int j = ans[i].second + bus_length - 1, broken = 0; broken < ans[i].first; j += bus_length, broken++) {
- cout << j << " " ;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement