Submission

Status:

(PPPPPPPPPPPPP)(PPPPPPPPP)(PPPPPPPPPP)(PPPPPPPPPP)(PPPPPPPPPPPPPP)(PPPPPPTSSSSSSSSSSSS)(PPPPPPTSSSSSSSSSSSSSSS)

Subtask/Task Score:

{4/4}{4/4}{5/5}{7/7}{25/25}{0/34}{0/21}

Score: 45

User: GGEZLOLx3D

Problemset: ร้านปลอดภาษี (Duty Free)

Language: cpp

Time: 1.096 second

Submitted On: 2026-03-26 18:03:59

#include<bits/stdc++.h>
#include "duty_free.h"
using namespace std;

// you can write more function here
int minimum_bag_rearrangement_time(std::vector<int> max_allowed_positions) {
    int n=max_allowed_positions.size();
    vector<bool> mp(n+1,false);
    vector<int> res;
    int c=0,i,j;
    for(i=0;i<n;i++){
        //cout << mp[max_allowed_positions[i]] << "\n";
        if(!mp[max_allowed_positions[i]]){
            mp[max_allowed_positions[i]]=true;
            res.push_back(max_allowed_positions[i]);
        }
        else{
            bool ch=false;
            for(j=max_allowed_positions[i];j>=1;j--){
                if(!mp[j]){
                    mp[j]=true;
                    res.push_back(j);
                    ch=true;
                    break;
                }
            }
            if(ch){
                continue;
            }
            else{
                c++;

                for(j=0;j<res.size();j++){
                    mp[res[j]]=false;

                }
                res.clear();
                i--;
            }
        }

    }
  return c;
}