Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- inline void prep ()
- {
- cin.tie (0);
- cin.sync_with_stdio (0);
- };
- int mod = 1000000007;
- long long mymod(long long num){
- if (num< 0){
- if (mod == 1){
- return 0;
- }
- return mod-abs(num)%mod;
- }else{
- return num%mod;
- }
- }
- double eps = .0000000001;
- int main ()
- {
- prep ();
- while (true){
- int n;
- cin >> n;
- if (n == 0){
- break;
- }
- int nums[n];
- for (int i=0; i<n; i++){
- cin >> nums[i];
- }
- int l = 0;
- int r = nums[n-1]*20;
- int mid = (l+r)>>1;
- vector<int> bestlst = {nums[n-1]};
- int lastbest = 0;
- while (l <= r){
- mid = (l+r)>>1;
- int startfrom = mid/20+1;
- int strt = 0;
- bool can = true;
- while (strt < n && nums[strt] <= startfrom){
- strt++;
- }
- if (strt == n){
- r = mid-1;
- continue;
- }
- int curroom = nums[strt];
- int stops = 0;
- vector<int> curlst;
- while (curroom <= nums[n-1] && can){
- // go up rooms until room can't reach strt with time
- // mark that room as a stop
- // go up num until you reach a floor that can't reach the last placed stop
- curroom = nums[strt];
- while (curroom <= nums[n-1]){
- int timee = stops*10+4*(curroom-1)+20*(curroom-nums[strt]);
- if (timee > mid){
- if (curroom == nums[strt]){
- can = false;
- break;
- }
- curlst.push_back(curroom-1);
- stops++;
- break;
- }
- curroom++;
- }
- if (!can){
- break;
- }
- bool chose = false;
- for (int i=strt; i<n; i++){
- if (nums[i] > curroom-1){
- int timee = max(0, stops-1)*10+4*(curroom-2)+20*(nums[i]-(curroom-1));
- if (timee > mid){
- strt = i;
- chose = true;
- break;
- }
- }
- }
- if (!chose){
- break;
- }
- }
- if (!can){
- l = mid+1;
- }else{
- r = mid-1;
- lastbest = mid;
- curlst.push_back(nums[n-1]);
- bestlst = curlst;
- }
- }
- cout << lastbest << '\n';
- cout << bestlst.size() <<" ";
- for (int i=0; i<bestlst.size(); i++){
- cout << bestlst[i];
- if (i != bestlst.size()-1){
- cout << " ";
- }
- }
- cout << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement