Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main(){
  8.     ios_base::sync_with_stdio(0);
  9.     cin.tie(0);
  10.     int n,m;
  11.     long long t,k;
  12.     cin >> n >> m >> t >> k;
  13.     vector <long long> a(n);
  14.     for(int i = 0;i<n;++i){
  15.         cin >> a[i];
  16.     }
  17.     vector <long long> b(m);
  18.     for(int i = 0;i<m;++i){
  19.         cin >> b[i];
  20.     }
  21.     if(t<=a[0]){
  22.         cout << t << " " << 0;
  23.         return 0;
  24.     }
  25.     long long c1 = a[0],c2 = 0;
  26.     long long time = a[0];
  27.     int channel = 1;
  28.     int i,j;
  29.     while(time<t){
  30.         if(time>t)
  31.             break;
  32.         if(channel==0){
  33.             i = lower_bound(a.begin(),a.end(),time)-a.begin();
  34.             int prev = i-1;
  35.             if(prev!=-1){
  36.                 time = max(time,a[prev]+k);
  37.             }
  38.             if(i>=n){
  39.                 c1 += t-time;
  40.                 break;
  41.             }
  42.             if(a[i]>=t){
  43.                 c1 += t-time;
  44.                 break;
  45.             }
  46.             if(a[i]==time){
  47.                 time+= k;
  48.                 i++;
  49.             }
  50.             if(time>t)
  51.                 break;
  52.             if(i>=n){
  53.                 c1 += t-time;
  54.                 break;
  55.             }
  56.             if(time>t)
  57.                 break;
  58.             c1 += a[i]-time;
  59.             //i++;
  60.             time = a[i];
  61.             channel = 1;
  62.         }
  63.         else{
  64.             j = lower_bound(b.begin(),b.end(),time)-b.begin();
  65.             int prev = j-1;
  66.             //cout << j << "\n";
  67.             if(prev!=-1){
  68.                 time = max(time,b[prev]+k);
  69.             }
  70.             if(j>=m){
  71.                 c2 += t-time;
  72.                 break;
  73.             }
  74.             if(b[j]>=t){
  75.                 c2 += t-time;
  76.                 break;
  77.             }
  78.             if(b[j]==time){
  79.                 time += k;
  80.                 j++;
  81.             }
  82.             /*if(j>=m){
  83.                 c2 += t-time;
  84.                 break;
  85.             }*/
  86.             if(time>t)
  87.                 break;
  88.             if(j>=m){
  89.                 c2 += t-time;
  90.                 break;
  91.             }
  92.             //cout << j << "\n";
  93.             c2 += b[j]-time;
  94.             time = b[j];
  95.             channel = 0;
  96.         }
  97.         //cout << c1 << " " << c2 << "\n";
  98.     }
  99.     cout << c1 << " " << c2;
  100.     return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement