cswork / OAOpen practice workspace

IBMOA #2

Triplets

Estimated MediumStatement and editorial — judging is being prepared

Topics (AI-labelled)Two PointersIn-place Arrays

Given an array d[n] of distinct integers and an integer threshold t, count the index triplets (a, b, c) satisfying both:

  • d[a] + d[b] < d[c]
  • d[a] + d[b] + d[c] < t

Example

d = [1, 2, 3, 4, 5], t = 8
Triplets (sorted): (1,2,4) sum=7<8 and 1+2<4 ok; (1,2,3) 1+2<3? no; (1,3,4) 4<4? no.
Answer: 1

Editorial

Loading solution…