Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int T_time=20;
- int J_time=0;
- int Tend;
- long long served[100001];
- bool visited[100001];
- struct petent{
- int number;
- int came, length, fee;
- };
- bool operator<(const petent& x, const petent& y){
- return x.came<y.came;
- };
- int N;
- int T=0;
- priority_queue< pair<int, petent> > Jaromir;
- queue<petent> Teodora;
- vector<petent> customers;
- int main(){
- //scanf("%d",&N);
- cin>>N;
- for(int n=0; n<N; n++){
- int t, s, p;
- //scanf("%d %d %d",&t,&s,&p);
- cin>>t>>s>>p;
- petent x;
- x.number=n+1;
- x.came=t;
- x.length=s;
- x.fee=p;
- customers.push_back(x);
- }
- //scanf("%d",&Tend);
- cin>>Tend;
- sort(customers.begin(), customers.end());
- T=customers[0].came;
- J_time=T;
- if(T>20)
- T_time=T;
- int i=0;
- int k=i;
- while(T<=Tend){
- //cout<<i<<endl;
- if(i<customers.size()&&Teodora.empty()&&T_time<J_time){
- k=i;
- T_time=customers[k].came;
- k++;
- }
- else if(i<customers.size()&&Jaromir.empty()&&J_time<=T_time){
- k=i;
- J_time=customers[k].came;
- k++;
- }
- while(i<customers.size()&&customers[i].came<=T){
- Jaromir.push(make_pair(customers[i].fee, customers[i]));
- Teodora.push(customers[i]);
- i++;
- }
- if(J_time<=T_time){
- if(!Jaromir.empty()){
- while(!Jaromir.empty()&&visited[Jaromir.top().second.number]==true)
- Jaromir.pop();
- if(!Jaromir.empty()){
- int s=Jaromir.top().second.length;
- J_time+=s;
- //cout<<"Jaromit topsecond "<<Jaromir.top().second.number<<endl;
- served[Jaromir.top().second.number]=s;
- visited[Jaromir.top().second.number]=true;
- Jaromir.pop();
- }
- else if(i<customers.size()){
- T=customers[i].came;
- J_time=T;
- T_time=T;
- }
- else{
- T=Tend+1;
- J_time=T;
- T_time=T;
- }
- }
- }
- else{
- if(!Teodora.empty()){
- while(!Teodora.empty()&&visited[Teodora.front().number]==true)
- Teodora.pop();
- //if(visited[Teodora.front().number]==false){
- int s= Teodora.front().length;
- T_time+=2*s+20;
- served[Teodora.front().number]=s;
- visited[Teodora.front().number]=true;
- Teodora.pop();
- }
- else if(i<customers.size()){
- T=customers[i].came;
- J_time=T;
- T_time=T;
- }
- else{
- T=Tend+1;;
- J_time=T;
- T_time=T;
- }
- }
- T=min(T_time,J_time);
- }
- for(int j=0; j<N; j++)
- cout<<served[j+1]<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement