You are viewing a single comment's thread. Return to all comments →
using namespace std;
int test(const vector &a, int n, int d) { int res = 0; vectorb(a.begin(), a.begin() + d); sort(b.begin(), b.end()); for(int i = d; i < n; i++) { int sum = 0; if(d % 2 == 1) { sum = 2 * b[d / 2]; } else { sum = b[d / 2] + b[d / 2 - 1]; } if(a[i] >= sum) { res++; } b.erase(lower_bound(b.begin(), b.end(), a[i - d])); b.insert(lower_bound(b.begin(), b.end(), a[i]), a[i]); } return res; }
int main() { int n, d; cin >> n >> d; vector a(n); for(int i = 0; i < n; i++) { cin >> a[i]; } cout << test(a, n, d) << endl; return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Fraudulent Activity Notifications
You are viewing a single comment's thread. Return to all comments →
include
using namespace std;
int test(const vector &a, int n, int d) { int res = 0; vectorb(a.begin(), a.begin() + d); sort(b.begin(), b.end()); for(int i = d; i < n; i++) { int sum = 0; if(d % 2 == 1) { sum = 2 * b[d / 2]; } else { sum = b[d / 2] + b[d / 2 - 1]; } if(a[i] >= sum) { res++; } b.erase(lower_bound(b.begin(), b.end(), a[i - d])); b.insert(lower_bound(b.begin(), b.end(), a[i]), a[i]); } return res; }
int main() { int n, d; cin >> n >> d; vector a(n); for(int i = 0; i < n; i++) { cin >> a[i]; } cout << test(a, n, d) << endl; return 0; }