結果

問題 No.2757 Pin Game
ユーザー t98slider
提出日時 2024-05-17 21:21:34
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 736 bytes
コンパイル時間 2,099 ms
コンパイル使用メモリ 196,668 KB
最終ジャッジ日時 2025-02-21 14:26:33
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

template<class T> istream& operator >> (istream& is, vector<T>& vec) {
    for(T& x : vec) is >> x;
    return is;
}

template<class T> ostream& operator << (ostream& os, const vector<T>& vec) {
    if(vec.empty()) return os;
    os << vec[0];
    for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it;
    return os;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    cin >> x;
    sort(x.begin(), x.end());
    int pre = x[0], ans = 1;
    for(int i = 1; i < n; i++){
        if(x[i] >= pre + k){
            ans++;
            pre = x[i];
        }
    }
    cout << ans << '\n';
}
0