美团第二题有无大佬可以帮我看看哪里有问题
全部评论 
 ```c++
#include <iostream>
(30316)#include <vector>
#include <cstring>
(31637)#include <algorithm>
using namespace std;
typedef unsigned long long LL;
const int N = 200010;
LL a[N];
LL mex[N];
LL cnt[N];
int main() {
    int T;
    cin >> T;
    while (T--) {
        memset(a, 0, sizeof a);
        memset(mex, 0, sizeof mex);
        memset(cnt, 0, sizeof cnt);
        LL n, k, x;
        scanf("%lld%lld%lld", &n, &k, &x);
        for (int i = 0; i < n; i++) {
            scanf("%lld", a + i);
            cnt[a[i]]++;
        }
        LL mx = 0;
        while (cnt[mx]) mx++;
        mex[0] = mx;
        for (int i = 1; i < n; i++) {
            cnt[a[i - 1]]--;
            if (cnt[a[i - 1]] == 0) mx = min(mx, a[i - 1]);
            mex[i] = mx;
        }
        
        LL res = 0x3f3f3f3f;
        res = res * res;
        LL sum = 0;
        for (int i = 0; i < n; i++) {
            res = min(res, sum + k * mex[i]);
            sum += x;
        }
        res = min(res, sum);
        cout << res << endl;
    }
    return 0;
}
```
中间运算j*x+right*k溢出了,直接将x和k定义成long lnog
define int ll
我设的自测输入
1
1 3 3
1
输出0到6全都不对,是我题目理解错了嘛

long 直接100%了,打过ACM或者蓝桥杯的话就会注意这些范围
首先用long long
相关推荐
 点赞 评论 收藏   
分享
 
查看2道真题和解析 点赞 评论 收藏   
分享
 