Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int main(){
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int n,m,k;
- long long t;
- cin >> n >> m >> t >> k;
- vector <long long> a(n);
- for(int i = 0;i<n;++i){
- cin >> a[i];
- }
- vector <long long> b(m);
- for(int i = 0;i<m;++i){
- cin >> b[i];
- }
- if(t<=a[0]){
- cout << t << " " << 0;
- return 0;
- }
- long long c1 = a[0],c2 = 0;
- long long time = a[0];
- int channel = 1;
- int i,j;
- while(time<t){
- if(time>t)
- break;
- if(channel==0){
- i = lower_bound(a.begin(),a.end(),time)-a.begin();
- if(i>=n){
- c1 += t-time;
- break;
- }
- if(a[i]>=t){
- c1 += t-time;
- break;
- }
- if(a[i]==time){
- time+= k;
- i++;
- }
- if(time>t)
- break;
- if(i>=n){
- c1 += t-time;
- break;
- }
- if(time>t)
- break;
- c1 += a[i]-time;
- //i++;
- time = a[i];
- channel = 1;
- }
- else{
- j = lower_bound(b.begin(),b.end(),time)-b.begin();
- //cout << j << "\n";
- if(j>=m){
- c2 += t-time;
- break;
- }
- if(b[j]>=t){
- c2 += t-time;
- break;
- }
- if(b[j]==time){
- time += k;
- j++;
- }
- /*if(j>=m){
- c2 += t-time;
- break;
- }*/
- if(time>t)
- break;
- if(j>=m){
- c2 += t-time;
- break;
- }
- //cout << j << "\n";
- c2 += b[j]-time;
- time = b[j];
- channel = 0;
- }
- //cout << c1 << " " << c2 << "\n";
- }
- cout << c1 << " " << c2;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement