#FT0000221. Mưa thiên thạch (MET-Meteors)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Mưa thiên thạch (MET-Meteors)
MET-Meteors
Source: Luogu
Version: Phuoc Hung OJ Extended
Problem Statement
An alliance has member countries and stations around a planet. Its orbit is divided into sectors numbered cyclically from to , so sector is adjacent to sector . Sector contains exactly one station, belonging to country ; a country may own several stations or none. Initially, no samples have been collected.
Country wants to collect at least meteorite samples in total from all stations that it owns.
There are predicted showers in chronological order. Shower affects all sectors from to in increasing cyclic order, wrapping from to if . Every station in the affected sectors receives additional samples.
For each country, determine the earliest shower after which the total collected by its stations reaches the target. If the target is never met after all showers, output NIE.
Input
- The first line contains , the number of countries and circular sectors.
- The second line contains integers , giving the owner of the station in each sector.
- The third line contains integers , the sampling targets.
- The fourth line contains , the number of predicted showers.
- Each of the next lines contains , specifying the affected circular range and the number of samples each station in that range receives.
Output
Print lines. Line contains the earliest shower number by which country reaches at least samples, or NIE if it never reaches the target.
Subtasks
-
Subtask 1 (20 points): ; ; ; ; for all valid indices.
-
Subtask 2 (30 points): ; ; ; ; for all valid indices.
-
Subtask 3 (50 points): ; ; ; ; for all valid indices.
Examples
Input
3 5
1 2 1 3 2
6 7 3
3
4 2 2
2 3 3
1 5 1
Output
3
2
3
Explanation
Sector ownership is , and the targets are . Shower 1 covers sectors , giving country totals . Shower 2 covers sectors , changing totals to ; country 2 reaches its target here. Shower 3 covers all five sectors, yielding ; countries 1 and 3 meet their targets for the first time. Thus the three answers are 3, 2, 3.