[NOISG 2024 Prelim] School Photo

Luogu
IDLGP10710
Time1000ms
Memory1024MB
DifficultyP3
2024双指针 two-pointerNOISG(新加坡)
Zane 是 NOI 学校的校长。NOI 学校有 $n$ 个班,每个班有 $s$ 名同学。第 $i$ 个班中的第 $j$ 名同学的身高是 $a_{i,j}$。 现在 Zane 想从每个班上选出一名同学拍照,使得这 $n$ 名同学中最高的同学和最低的同学的身高差最小。 请你输出这个最小值。 ## Input 第一行,两个整数 $n,s$; 接下来 $n$ 行,每行 $s$ 个整数,表示 $a$。 ## Output 一行一个整数表示答案。 [samples] ## Background 翻译自 [NOI SG 2024 Prelim C.School Photo](https://github.com/noisg/noi-2024-prelim)。 ## Note ### 【样例 #2 解释】 选择 $a_{1,3},a_{2,2},a_{3,2}$,答案为 $8-4=4$。 ### 【数据范围】 |$\text{Subtask}$|分值|特殊性质| |:-:|:-:|:-:| |$0$|$0$|样例| |$1$|$11$|$n=2$| |$2$|$22$|$n,s\le100$| |$3$|$9$|$n,s\le250$| |$4$|$33$|$n,s\le500$| |$5$|$25$|无| 对于 $100\%$ 的数据,$1\le n,s \le 1000,1\le a_{i,j} \le 10^9$。
Samples
Input #1
2 3
2 1 8
5 4 7
Output #1
1
Input #2
3 3
3 1 4
2 7 18
9 8 10
Output #2
4
API Response (JSON)
{
  "problem": {
    "name": "[NOISG 2024 Prelim] School Photo",
    "description": {
      "content": "Zane 是 NOI 学校的校长。NOI 学校有 $n$ 个班,每个班有 $s$ 名同学。第 $i$ 个班中的第 $j$ 名同学的身高是 $a_{i,j}$。 现在 Zane 想从每个班上选出一名同学拍照,使得这 $n$ 名同学中最高的同学和最低的同学的身高差最小。 请你输出这个最小值。",
      "description_type": "Markdown"
    },
    "platform": "Luogu",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 1048576
    },
    "difficulty": {
      "LuoguStyle": "P3"
    },
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "LGP10710"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Zane 是 NOI 学校的校长。NOI 学校有 $n$ 个班,每个班有 $s$ 名同学。第 $i$ 个班中的第 $j$ 名同学的身高是 $a_{i,j}$。\n\n现在 Zane 想从每个班上选出一名同学拍照,使得这 $n$ 名同学中最高的同学和最低的同学的身高差最小。\n\n请你输出这个最小值。\n\n## Input\n\n第一行,两个整数 $n,s$;\n\n接下来 $n$ 行,每行 $s$ 个整数,表示 $...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments