为什么会RE
查看原帖
为什么会RE
556181
__Emerald__楼主2024/3/27 13:12

这道题我写的代码为什么会RE?

#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n,k,sum,a[200005],b[200005],pos = 1;
bool have[200005];
int main(){
	cin >> n >> k;
	sum = k * (k + 1) / 2;
	for (ll i = 1;i <= n;i++){
		cin >> a[i];
		if (a[i] >= 1 && a[i] <= k && !have[a[i]]) b[pos] = a[i],pos++,have[a[i]] = true;
	}
	for (ll i = 1;i < pos;i++) sum -= b[i];
	cout << sum;
	return 0;
}
2024/3/27 13:12
加载中...