report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Sum of four values - MarisaOJ: Marisa Online Judge

Sum of four values

Time limit: 1000 ms
Memory limit: 256 MB
Given an array $A$ consisting of $n$ elements and an integer $x$, determine whether there exist four distinct indices $i, j, k, p$ such that $A_i + A_j + A_k + A_p = x$. ### Input - The first line contains two integers $n$ and $x$. - The second line contains $n$ integers $A_i$. ### Output - Print `YES` if such indices exist, otherwise print `NO`. ### Constraints - $1 \leq n \leq 1000$. - $1 \leq A_i, x \leq 10^9$. ### Example Input: ``` 8 15 3 2 5 8 1 3 2 3 ``` Output: ``` YES ```
Introduction to meet in the middle
Subset sum 2
Sum of four values
Robot
Minimum difference
Maximum sum subset
Stealing books
Topic
Others
Rating 800
Source CSES
Solution (1) Solution