This is the 0-1 [quadratic knapsack problem][1], which is NP-hard.  The binary decision variables $x_i$ indicate whether $i\in S$, and the knapsack capacity is $k$.

  [1]: https://en.wikipedia.org/wiki/Quadratic_knapsack_problem