test sai nhe
input: 7 3 1 2 4 5 7 8 10 extended output: 5 output (theo đề bài cho): 4 (Sai so với code full AC)
code tham khảo:
C++ 17
#include #include #include using namespace std; typedef long long ll; typedef vector vi;
int main() { ios::sync_with_stdio(0); cin.tie(0);
int N,K; cin >> N >> K;
vi A(N);
for(int i=0;i<N;i++) cin >> A[i];
ll cnt = 0;
for(int i=0;i<N;i++) {
int t = A[i]+K;
auto l = lower_bound(A.begin()+i+1, A.end(), t);
auto r = upper_bound(A.begin()+i+1, A.end(), t);
cnt += (r-l);
}
cout << cnt << '\n';
return 0;
}
Tổng cộng 2 trả lời
cam on mao le