logo AlgoBeat OnlineJudge
登录 注册

#216597. [ICPC 2026 APC] Parallel Sums

内存限制:1024 MiB 时间限制:4000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

You are given two integers and . For a sequence of integers , the parallel sums of are the integers defined by for each ( ).

You are given the values of . Your task is to answer queries, described as follows. In the -th query, you are given two integers and , and you are asked to find the smallest possible value of among all sequences of integers (possibly negative) such that are the parallel sums of . Or determine if this value can be arbitrarily small.

输入格式

The first line of input contains two integers and ( ).

The second line contains integers ( ).

The third line contains a single integer ( ).

The -th of the next lines contains two integers and ( ).

输出格式

Output lines. The -th line should contain the smallest possible value of . If that value can be arbitrarily small, output unbounded instead.

样例

样例输入 1

8 4
4 -4 2 6 5
4
3 7
4 6
1 8
2 5

样例输出 1

2
unbounded
4
-1

数据范围与提示

Explanation for the sample input/output #1

For the first query, take . The parallel sums of are as required. Then . It can be shown that is the smallest possible value.

For the second query, you can make the value arbitrarily small.

For the third query, take . Then , which is the smallest possible value.