PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SRD0000078. Những món quà lưu niệm (Souvenirs)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Những món quà lưu niệm (Souvenirs)
Souvenirs
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Each position is a shop with price . For each interval containing at least two shops, choose two distinct indices minimizing the absolute price difference . Equal prices yield 0.
Input
Read , its prices, , then ranges with .
Output
Print the minimum price difference for each interval.
Subtasks
- Subtask 1 (10 points): , . ; ; .
- Subtask 2 (20 points): , . ; ; .
- Subtask 3 (25 points): , . ; ; .
- Subtask 4 (45 points): , . ; ; .
Examples
Input
8
3 1 4 1 5 9 2 6
4
1 8
1 3
4 8
5 7
Output
0
1
1
3
Explanation
In the whole array, two different shops offer price 1, giving 0. In , prices have minimum difference 1. In , the smallest difference is 3.