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

Number of pairs

Time limit: 1000 ms
Memory limit: 256 MB
Given an array $A$ of $n$ distinct integers in ascending order. Find the number of pairs $i < j$ such that $A_i + A_j = x$. ### Input - The first line contains two integers $n, x$. - The second line contains $n$ integers $A_i$. ### Output - Print the number of pairs $(i, j)$. ### Constraints - $1 \le n \le 10^5$. - $1 \le A_i, x \le 10^9$. ### Example Input: ``` 5 6 1 2 3 4 5 ``` Output: ``` 2 ```
Introduction to two pointers
Merge array
Brewing potion 2
Unique elements
Small range
Number of pairs
Sum of three values
Brewing potion 3
Brewing potion 4
Three sequences
Biggest submatrix
Choosing numbers
Topic
Two pointers
Rating 800
Solution (1) Solution