我也不知道发生了什么问题,帮忙看看
样例第一个都是对的,后面的就开始错了
#include <iostream>
#include <deque>
using namespace std;
const auto maxn = 1000005;
struct snake {
int id, ma;
bool operator < (snake b) const {
if (ma != b.ma) {
return ma < b.ma;
}
return id < b.id;
}
}sna[maxn];
int t, n;
deque<snake>q, q1, q2;
void solve() {
for (int i = 1; i <= n; i++) {
q1.push_back(sna[i]);
}
while (true) {
if (q1.size() + q2.size() == 2) {
cout << 1 << endl;
return;
}
snake st = q1.front();
q1.pop_front();
snake ed = q1.back();
//q1.pop_back();
if (!q2.empty() && ed < q2.back()) {
//q1.push_back(ed);
ed = q2.back();
q2.pop_back();
}
snake temp{};
temp.id = ed.id;
temp.ma = ed.ma - st.ma;
if (q1.front() < temp) {
q2.push_front(temp);
}
else {
q1.push_front(temp);
break;
}
}
}
int main() {
cin >> t >> n;
for (int i = 1; i <= n; i++) {
cin >> sna[i].ma;
sna[i].id = i;
}
solve();
cout << q1.size() + q2.size() << endl;
q1.clear();
q2.clear();
for (int i = 1; i < t; i++) {
int k;
cin >> k;
for (int j = 1; j <= k; j++) {
int u, v;
cin >> u >> v;
sna[u].ma = v;
}
solve();
cout << q1.size() + q2.size() << endl;
q1.clear();
q2.clear();
}
return 0;
}