CF2184B.Hourglass
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Vadim's hourglass measures s minutes. He flipped it over, and the time started. Every k minutes, Vadim will flip his hourglass again. He will do this even if the sand is still falling. Also, if the sand has already finished falling but there are still some minutes left, Vadim will wait for the required time and only then flip the hourglass. Each flip is done instantly.
However, Vadim needs to leave for errands in m minutes, and he will stop flipping the hourglass (if Vadim needs to flip the hourglass in the last minute, he will do so). Determine how many minutes the sand will continue to fall after Vadim leaves.
瓦季姆的沙漏计时 s 分钟。他将沙漏翻转后,计时开始。此后,每过 k 分钟,瓦季姆就会再次翻转沙漏。即使此时沙子仍在下落,他也会执行翻转操作;此外,若沙子已全部落完但剩余时间仍未耗尽,瓦季姆会等待所需时间,然后才翻转沙漏。每次翻转均瞬间完成。
然而,瓦季姆需在 m 分钟后外出办事,届时他将停止翻转沙漏(若在最后一分钟恰好需要翻转沙漏,他仍会执行该操作)。请确定瓦季姆离开后,沙子还将继续下落多少分钟。
输入格式
Each test consists of several test cases. The first line contains a single integer t (1≤t≤104) — the number of test cases. The following lines describe the test cases.
In a single line of each test case, there are three integers s, k, and m — the number of minutes the hourglass measures, the number of minutes after which the hourglass flips, and the number of minutes after which Vadim will leave for errands (1≤s,k,m≤109).
每个测试包含若干测试用例。第一行包含一个整数 t(1≤t≤104),表示测试用例的数量。接下来的行描述各个测试用例。
每个测试用例占一行,包含三个整数 s、k 和 m,分别表示沙漏计时的分钟数、沙漏翻转的分钟数,以及 Vadim 出门办事的分钟数(1≤s,k,m≤109)。
输出格式
For each test case, output how many minutes the sand will continue to fall after Vadim leaves.
对于每个测试用例,输出 Vadim 离开后沙子还将继续下落多少分钟。
输入输出样例
输入#1
6 8 8 12 5 10 17 12 2 3 16 7 7 1 1 10 2 60 15
输出#1
4 0 1 7 1 0
说明/提示
In the first test case, Vadim will flip the hourglass just as the sand stops falling, then 4 minutes pass, Vadim leaves, and 4 minutes will remain.
In the second test case, Vadim will flip the hourglass at the 10-th minute, in the next 5 minutes the sand will completely finish falling, and in 2 minutes Vadim will leave, resulting in 0 minutes remaining.
In the third test case, 2 minutes of sand have already fallen before the first flip, so after the flip, this sand will continue to fall. After 1 minute, 1 minute will remain.
In the fourth test case, 7 minutes of sand have already fallen before the first flip, Vadim will perform it and immediately leave, so 7 minutes will remain.
在第一个测试用例中,瓦季姆将在沙子刚好停止下落时翻转沙漏,然后经过 4 分钟,瓦季姆离开,此时剩余 4 分钟。
在第二个测试用例中,瓦季姆将在第 10 分钟时翻转沙漏;接下来的 5 分钟内沙子将完全流完,而瓦季姆将在 2 分钟后离开,因此剩余时间为 0 分钟。
在第三个测试用例中,首次翻转前已有 2 分钟的沙子流下,因此翻转后这部分沙子将继续下落;再过 1 分钟后,将剩余 1 分钟。
在第四个测试用例中,首次翻转前已有 7 分钟的沙子流下,瓦季姆将立即翻转沙漏并立刻离开,因此剩余时间为 7 分钟。
输入解题思路,AI测评打分。不知道怎么写?