Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created April 26, 2026 12:28
Show Gist options
  • Select an option

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

Select an option

Save thinkphp/a249b7f070b2ae783c9fb560366dede8 to your computer and use it in GitHub Desktop.
Fast Alarm Codeforce java
import java.util.Scanner;
public class FalseAlarm {
static Scanner scanner = new Scanner(System.in);
static void solve() {
int n = scanner.nextInt(); //citim size array
int x = scanner.nextInt(); //button , cate secunde are efect
int l = 100000, r = -1;
//1 0 1 1 0 0
//0 1 2 3 4 5 (i)
for(int i = 0; i < n; ++i) {
int door = scanner.nextInt(); //daca door = 0 atunci usa este open; daca door = 1; //usa este closed;
if( door == 1 ) {
l = Math.min(l, i);//min(100000, 1)=1; min(1,2) = 1
r = Math.max(r, i);//max(-1,1) = 1 ;max(1,2) = 2
}
}
System.out.println(x >= r - l + 1 ? "YES": "NO"); //2>=2 YES
}
public static void main(String[] args) {
int T = scanner.nextInt();
while(T-- > 0) solve();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment