atcoder abc245 c模拟拿满分

求助

atcoder abc 245
c题——

https://atcoder.jp/contests/abc245/tasks/abc245_c?lang=en

这是我的题解:

#include
#include
#include
#include
#include
using namespace std;
const int N = 2e5 + 10;
int n, k, a[N], b[N], c[N][2], flag = 1;
vector<int>vec;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> k;
	if (n == 1) {
		cout << "Yes";
		return 0;
	}
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) cin >> b[i];
	vec.push_back(a[1]);
	int i = 1;
	while (1) {
		if (vec.size()) {
			if (i == n + 1) {
				break;
			}
			if (c[i][0] == 0 && abs(vec.back() - a[i]) <= k) {
				if(i==1)vec.pop_back();
				vec.push_back(a[i]);
				i++;
				continue;
			} else if (c[i][1] == 0 && abs(vec.back() - b[i]) <= k) {
				vec.push_back(b[i]);
				i++;
				continue;
			} else {
				i--;
				if (vec.back() == a[i])c[i][0] = 1;
				if (vec.back() == b[i])c[i][1] = 1;
				vec.pop_back();
			}
		} else {
			flag = 0;
			break;
		}
	}
	if (flag)
		cout << "Yes";
	else cout << "No";
}

纯纯的模拟,可以得300分,但过不了,依旧显示wa啊555,可以帮我debug吗?感谢大佬们orz.

你可能感兴趣的:(c++,c++,算法,贪心算法)