#K13406. Taco Package Management
Taco Package Management
Taco Package Management
Given N packages with their initial weights, you are to process Q operations. There are two types of operations:
Type 1 (Query): Given a weight threshold W, find the package with the smallest weight that satisfies \(w_i \geq W\). If such a package exists, output its 1-indexed position; otherwise, output -1.
Type 2 (Update): Given indices L and R along with a value X, increase the weight of each package from index L to R by X.
Your task is to output the result for each query (Type 1) operation after processing all operations.
inputFormat
The input is provided via standard input in the following format:
- The first line contains two integers \(N\) and \(Q\) — the number of packages and the number of operations.
- The second line contains \(N\) integers \(w_1, w_2, \ldots, w_N\) representing the initial weights of the packages.
- Each of the next \(Q\) lines describes an operation:
- For a query operation (Type 1): the line contains two integers:
1 W
, where \(W\) is the threshold weight. - For an update operation (Type 2): the line contains four integers:
2 L R X
, meaning that for all \(i\) from \(L\) to \(R\) (inclusive), add \(X\) to \(w_i\).
- For a query operation (Type 1): the line contains two integers:
outputFormat
For each query (Type 1) operation, output a single integer on a new line representing the 1-indexed position of the package with the smallest weight that is at least \(W\). If no such package exists, output -1.
## sample5 3
10 20 30 40 50
1 25
2 2 4 10
1 25
3
2
</p>