Advertisement
Guest User

urzad

a guest
Jan 22nd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.58 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int T_time=20;
  5. int J_time=0;
  6. int Tend;
  7.  
  8. long long served[100001];
  9. bool visited[100001];
  10.  
  11. struct petent{
  12.    
  13.     int number;
  14.     int came, length, fee;
  15.    
  16.    
  17. };
  18.  
  19. bool operator<(const petent& x, const petent& y){
  20.    
  21.     return x.came<y.came;
  22.    
  23. };
  24.  
  25. int N;
  26. int T=0;
  27. priority_queue< pair<int, petent> > Jaromir;
  28. queue<petent> Teodora;
  29.  
  30. vector<petent> customers;
  31.  
  32.  
  33. int main(){
  34.    
  35.     //scanf("%d",&N);
  36.     cin>>N;
  37.    
  38.    
  39.     for(int n=0; n<N; n++){
  40.        
  41.         int t, s, p;
  42.         //scanf("%d %d %d",&t,&s,&p);
  43.         cin>>t>>s>>p;
  44.        
  45.         petent x;
  46.         x.number=n+1;
  47.         x.came=t;
  48.         x.length=s;
  49.         x.fee=p;
  50.         customers.push_back(x);
  51.  
  52.     }
  53.     //scanf("%d",&Tend);
  54.     cin>>Tend;
  55.  
  56.     sort(customers.begin(), customers.end());
  57.    
  58.     T=customers[0].came;
  59.     J_time=T;
  60.     if(T>20)
  61.         T_time=T;
  62.    
  63.     int i=0;
  64.     int k=i;
  65.     while(T<=Tend){
  66.        
  67.         //cout<<i<<endl;
  68.        
  69.         if(i<customers.size()&&Teodora.empty()&&T_time<J_time){
  70.             k=i;
  71.              T_time=customers[k].came;
  72.              k++;
  73.          }
  74.         else if(i<customers.size()&&Jaromir.empty()&&J_time<=T_time){
  75.             k=i;
  76.             J_time=customers[k].came;
  77.             k++;
  78.         }
  79.        
  80.         while(i<customers.size()&&customers[i].came<=T){
  81.            
  82.             Jaromir.push(make_pair(customers[i].fee, customers[i]));
  83.             Teodora.push(customers[i]);
  84.             i++;
  85.            
  86.         }
  87.         if(J_time<=T_time){
  88.            
  89.             if(!Jaromir.empty()){
  90.                
  91.                 while(!Jaromir.empty()&&visited[Jaromir.top().second.number]==true)
  92.                     Jaromir.pop();
  93.                
  94.                     if(!Jaromir.empty()){
  95.                         int s=Jaromir.top().second.length;
  96.                         J_time+=s;
  97.                         //cout<<"Jaromit topsecond "<<Jaromir.top().second.number<<endl;
  98.                         served[Jaromir.top().second.number]=s;
  99.                         visited[Jaromir.top().second.number]=true;
  100.                         Jaromir.pop();
  101.                 }
  102.             else if(i<customers.size()){
  103.                
  104.                 T=customers[i].came;
  105.                 J_time=T;
  106.                 T_time=T;
  107.                 }
  108.             else{
  109.                
  110.                 T=Tend+1;
  111.                 J_time=T;
  112.                 T_time=T;
  113.                 }
  114.                
  115.             }
  116.         }
  117.         else{
  118.            
  119.             if(!Teodora.empty()){
  120.                
  121.                 while(!Teodora.empty()&&visited[Teodora.front().number]==true)
  122.                     Teodora.pop();
  123.                
  124.                 //if(visited[Teodora.front().number]==false){
  125.                     int s= Teodora.front().length;
  126.                     T_time+=2*s+20;
  127.                     served[Teodora.front().number]=s;
  128.                     visited[Teodora.front().number]=true;
  129.                     Teodora.pop();
  130.                
  131.                
  132.             }
  133.             else if(i<customers.size()){
  134.                
  135.                 T=customers[i].came;
  136.                 J_time=T;
  137.                 T_time=T;
  138.             }
  139.             else{
  140.                
  141.                 T=Tend+1;;
  142.                 J_time=T;
  143.                 T_time=T;
  144.                 }
  145.            
  146.            
  147.         }
  148.        
  149.         T=min(T_time,J_time);
  150.        
  151.     }
  152.    
  153.     for(int j=0; j<N; j++)
  154.         cout<<served[j+1]<<endl;
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement