入门题求助
查看原帖
入门题求助
757864
ruye楼主2023/11/4 16:13
#include <bits/stdc++.h> // By Lucky Ox
using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
//#define double long double
#define endl '\n'
#define pii pair<int, int> 
#define INF 0x3f3f3f3f3f3f3f3f
#define npos string::npos
#define mod 1000000000 + 7
int lcm(int x, int y){return x * y / __gcd(x, y);}
int qmi(int a, int k){int res = 1; while(k){ if(k & 1) res =  res * a % mod; k >>= 1;a = a * a % mod;} return res;}

signed main(){
    IOS;
    int n, k;
    cin >> n >> k;
    map<int, bool>mp;
    for(int i = 1; i <= n; i ++ ){
        int x;
        cin >> x;
        mp[x] = 1;
    }
    if(!k) {
        cout << "Yes" << endl;
        return 0;
    }

    for(auto t : mp){
        if(mp[t.first - k] == 1){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

我这串代码在运行样例2的时候会TLE 不知道什么原因

2023/11/4 16:13
加载中...