#P7593. Exact k Numbers Sum Problem

    ID: 20787 Type: Default 1000ms 256MiB

Exact k Numbers Sum Problem

Exact k Numbers Sum Problem

Given the integers from 1 to n, determine whether it is possible to choose exactly k distinct numbers such that their sum is s. Each number can only be used at most once.

Explanation:

The minimum possible sum when selecting k numbers from 1 to n is \(\frac{k(k+1)}{2}\) (by choosing the smallest k numbers) and the maximum possible sum is \(kn - \frac{k(k-1)}{2}\) (by choosing the largest k numbers). The answer is "YES" if \(s\) lies in the inclusive interval \([\frac{k(k+1)}{2}, kn - \frac{k(k-1)}{2}]\); otherwise, the answer is "NO".

inputFormat

The input consists of a single line containing three integers \(n\), \(k\), and \(s\), separated by spaces.

Constraints: You may assume that \(n, k, s\) are such that \(1 \leq k \leq n\) and \(s\) is a positive integer.

outputFormat

Output a single line with the answer: "YES" if it is possible to choose exactly k numbers from 1 to n such that their sum is exactly s, and "NO" otherwise.

sample

3 2 4
YES