Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.11 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,k;
  11.     long long t;
  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.             if(i>=n){
  35.                 c1 += t-time;
  36.                 break;
  37.             }
  38.             if(a[i]>=t){
  39.                 c1 += t-time;
  40.                 break;
  41.             }
  42.             if(a[i]==time){
  43.                 time+= k;
  44.                 i++;
  45.             }
  46.             if(time>t)
  47.                 break;
  48.             if(i>=n){
  49.                 c1 += t-time;
  50.                 break;
  51.             }
  52.             if(time>t)
  53.                 break;
  54.             c1 += a[i]-time;
  55.             //i++;
  56.             time = a[i];
  57.             channel = 1;
  58.         }
  59.         else{
  60.             j = lower_bound(b.begin(),b.end(),time)-b.begin();
  61.             //cout << j << "\n";
  62.             if(j>=m){
  63.                 c2 += t-time;
  64.                 break;
  65.             }
  66.             if(b[j]>=t){
  67.                 c2 += t-time;
  68.                 break;
  69.             }
  70.             if(b[j]==time){
  71.                 time += k;
  72.                 j++;
  73.             }
  74.             /*if(j>=m){
  75.                 c2 += t-time;
  76.                 break;
  77.             }*/
  78.             if(time>t)
  79.                 break;
  80.             if(j>=m){
  81.                 c2 += t-time;
  82.                 break;
  83.             }
  84.             //cout << j << "\n";
  85.             c2 += b[j]-time;
  86.             time = b[j];
  87.             channel = 0;
  88.         }
  89.         //cout << c1 << " " << c2 << "\n";
  90.     }
  91.     cout << c1 << " " << c2;
  92.     return 0;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement