PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000307. Tavas và dãy rau cần (Tavas and Karafs)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tavas và dãy rau cần (Tavas and Karafs)
Tavas and Karafs
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
An infinite one-based sequence has heights . In query , one bite reduces up to m distinct positive heights by one. Find the greatest for which all plants from l through r can be consumed in at most t bites. Queries are independent.
Input
First line: . Each of the next q lines contains .
Output
For each query, print the greatest r, or -1 if none exists.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; .
Examples
Input 1
2 1 4
1 5 3
3 3 10
7 10 2
6 4 8
Output 1
4
-1
8
-1
Explanation
First query: heights 2,3,4,5 sum to 14, within 15; the next height 6 exceeds t. Queries 2 and 4 fail at the first plant. Query 3 permits heights 8,9, but adding 10 exceeds total capacity 20.