Submission
Status:
----------
Score: 0
User: xBIwJEtx
Problemset: ลำแสงเลเซอร์สะท้อน
Language: cpp
Time: 0.002 second
Submitted On: 2025-04-07 22:23:52
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using piii = pair<int, pair<int, int>>;
int ans = 1;
int a[503], b[503];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,m;
cin >> n >> m;
a[0] = b[0] = 1e6;
for(int i=1; i<=n; i++){
cin >> a[i];
}
for(int i=1; i<=m; i++){
cin >> b[i];
}
int temp = 1;
for(int i=1; i<=n; i++){
for(int j=temp; j<=m; j++){
if(a[i] == b[j]){
ans++;
}
else if(b[j] > a[i]){
temp = j;
break;
}
else if(b[j-1] < a[i-1] && b[j] > a[i] && ((i-1)%2) == ((j-1)%2)){
ans++;
}
else if(b[j-1] > a[i-1] && b[j] < a[i] && ((i-1)%2) == ((j-1)%2)){
ans++;
}
else if((a[i-1] < b[i] || b[j-1] < a[i]) && ((i-1)%2) != ((j-1)%2) && (b[j] > a[i] || a[i] >= b[j])){
ans++;
}
}
}
cout << ans;
}