1521 : 蚂蚁运货
时间限制Time Limit
1
秒Sec
内存限制Memory Limit
128
兆MB
提交次数Submitted
0 次Times
通过次数Solved
0 次Times
标准评测 Standard
从标准输入读入,结果写到标准输出。评测将输出拆成 token,与标准答案逐项比较,不按整段逐字节比对。
Read from standard input and write to standard output. The judge splits the output into tokens and compares them with the official answer; it does not compare raw bytes.
| 比对Compare | token 相同即通过。中间的空格、制表符、换行可多可少。Matching tokens pass. Extra spaces, tabs, or newlines between them are ignored. |
|---|---|
| 不同则错Differs | token 个数或内容不同即错误。23 与 2 3、02 与 2、2.0 与 2 均视为不同。A different token count or value is wrong. 23 vs 2 3, 02 vs 2, and 2.0 vs 2 all differ. |
| 输入Input | 标准输入,格式见题面。Standard input; format as in the statement. |
| 输出Output | 标准输出。Standard output. |
题目描述Description
一根长为 L 的独木桥上,有 N 只蚂蚁。给定每只蚂蚁的初始坐标 x_i、朝向(向左或向右)以及它背负的货物的重量 w_i。所有蚂蚁的爬行速度相同。
当两只蚂蚁相撞时,它们会立刻掉头(反向爬行)。当蚂蚁走到 x=0 或 x=L 时,就会掉下独木桥。
请问所有从左边(x=0)掉下独木桥的蚂蚁,它们背负的货物重量总和是多少?
输入格式Input
第一行包含两个整数 N 和 L,分别表示蚂蚁的数量和独木桥的长度。
接下来 N 行,每行包含三个整数 x_i、d_i、w_i:
x_i:第 i 只蚂蚁的初始坐标
d_i:第 i 只蚂蚁的朝向(0 表示向左,1 表示向右)
w_i:第 i 只蚂蚁背负的货物重量
输出格式Output
输出一行一个整数,表示从左边掉下独木桥的蚂蚁背负的货物重量总和。
样例Sample
提示Hint
样例 1 说明
初始有 2 只蚂蚁向左(坐标 1 和 8),所以最终有 2 只蚂蚁从左边掉下。
按坐标排序后,最靠左的 2 只蚂蚁坐标为 1 和 5。
坐标 1 的蚂蚁重量为 5
坐标 5 的蚂蚁重量为 3
因此答案为 5 + 3 = 8。
数据范围
对于 100\% 的数据,保证:
1 \le N \le 10^5
2 \le L \le 10^9
1 \le x_i \le L-1
1 \le w_i \le 10^9
所有蚂蚁的初始坐标互不相同