Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created April 25, 2026 09:11
Show Gist options
  • Select an option

  • Save thinkphp/ead6365952a05fb7c6d2ff6d341865e6 to your computer and use it in GitHub Desktop.

Select an option

Save thinkphp/ead6365952a05fb7c6d2ff6d341865e6 to your computer and use it in GitHub Desktop.
False Alarm CodeForces.com codeforces-false-alarm.cpp
void solve() {
int n, x;//dimnesiune si butonul apasat: x secunde
cin>>n>>x;
int l = 1e5, r = -1;
for(int i = 0; i < n; ++i) {
int door;
cin>>door;
if(door == 1) {//daca usa este inchisa 1
l = min(l, i); //aflu indicele pe care se afla prima usa inchisa
r = max(r, i);//aflu indicele pe care se afla ultima usa inchisa
}
cout<< (x >= r - l + 1) ? "YES" : "NO"; //afli daca intervalul este mai mic sau egal decat numarul de secunde x
}
}
int main() {
int T;
cin>>T;
while(T--) solve();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment