Author: lllyouo
Date: 20251022
tag: 队列
link: https://www.luogu.com.cn/problem/P9422问题描述
分析
略
参考代码
cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m; cin >> n >> m;
deque<int> p, q;
for (int i = 1; i <= n; i++) {
int x; cin >> x;
p.push_back(x);
}
for (int i = 1; i <= m; i++) {
int x; cin >> x;
q.push_back(x);
}
int ans = 0;
while (p.size()) {
if (p.front() > q.front()) {
int x = q.front(); q.pop_front();
int y = q.front(); q.pop_front();
q.push_front(x + y);
ans++;
} else if (p.front() < q.front()) {
int x = p.front(); p.pop_front();
int y = p.front(); p.pop_front();
p.push_front(x + y);
ans++;
} else {
p.pop_front();
q.pop_front();
}
}
cout << ans << endl;
return 0;
}