QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 32 MB Puntuación total: 100

#11870. 公交车

Estadísticas

字节城的街道构成了一个规则的棋盘状网络——它们要么是南北向的,要么是东西向的。我们称之为 NS 街道和 WE 街道。此外,每条街道都贯穿整个城市。每条 NS 街道都与每条 WE 街道相交,反之亦然。NS 街道从西向东编号为 $1$ 到 $n$,WE 街道从南向北编号为 $1$ 到 $m$。第 $i$ 条 NS 街道与第 $j$ 条 WE 街道的交点记为坐标对 $(i,j)$(其中 $1 \le i \le n$,$1 \le j \le m$)。

字节城有一条公交线路,以这些交点作为公交车站。公交车从 $(1,1)$ 交点出发,在 $(n,m)$ 交点结束行程。此外,公交车只能向东和/或向北行驶。

在某些交点处有乘客在等待公交车。公交车司机希望选择一条路线,以便尽可能多地接载乘客。(我们假设公交车内部空间足够大,可以容纳所有等待的乘客,无论选择哪条路线。)

请编写一个程序:

  • 从标准输入读取道路网络的描述以及每个交点处等待的乘客数量,
  • 计算公交车最多能接载多少名乘客,
  • 将结果输出到标准输出。

输入格式

标准输入的第一行包含三个正整数 $n$、$m$ 和 $k$,分别表示 NS 街道的数量、WE 街道的数量以及有乘客等待的交点数量($1 \le n \le 10^9$,$1 \le m \le 10^9$,$1 \le k \le 10^5$)。

接下来的 $k$ 行描述了等待公交车的乘客分布情况,每行描述一个交点。第 $i+1$ 行包含三个正整数 $x_i$、$y_i$ 和 $p_i$,以空格分隔,$1 \le x_i \le n$,$1 \le y_i \le m$,$1 \le p_i \le 10^6$。该三元组表示在交点 $(x_i,y_i)$ 处有 $p_i$ 名乘客在等待公交车。每个交点在输入数据中最多出现一次。等待公交车的乘客总数不超过 $1\,000\,000\,000$。

输出格式

程序应向标准输出写入一行,包含一个整数,即公交车最多能接载的乘客数量。

样例

样例输入 1

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

样例输出 1

11

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.