A. Arpa and a research in Mexican wave
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Arpa is researching the Mexican wave.

There are n spectators in the stadium, labeled from 1 to n. They start the Mexican wave at time 0.

  • At time 1, the first spectator stands.
  • At time 2, the second spectator stands.
  • ...
  • At time k, the k-th spectator stands.
  • At time k + 1, the (k + 1)-th spectator stands and the first spectator sits.
  • At time k + 2, the (k + 2)-th spectator stands and the second spectator sits.
  • ...
  • At time n, the n-th spectator stands and the (n - k)-th spectator sits.
  • At time n + 1, the (n + 1 - k)-th spectator sits.
  • ...
  • At time n + k, the n-th spectator sits.

Arpa wants to know how many spectators are standing at time t.

Input

The first line contains three integers n, k, t (1 ≤ n ≤ 109, 1 ≤ k ≤ n, 1 ≤ t < n + k).

Output

Print single integer: how many spectators are standing at time t.

Examples
Input
10 5 3
Output
3
Input
10 5 7
Output
5
Input
10 5 12
Output
3
Note

In the following a sitting spectator is represented as -, a standing spectator is represented as ^.

  • At t = 0  ---------- A. Arpa and a research in Mexican wave number of standing spectators = 0.
  • At t = 1  ^--------- A. Arpa and a research in Mexican wave number of standing spectators = 1.
  • At t = 2  ^^-------- A. Arpa and a research in Mexican wave number of standing spectators = 2.
  • At t = 3  ^^^------- A. Arpa and a research in Mexican wave number of standing spectators = 3.
  • At t = 4  ^^^^------ A. Arpa and a research in Mexican wave number of standing spectators = 4.
  • At t = 5  ^^^^^----- A. Arpa and a research in Mexican wave number of standing spectators = 5.
  • At t = 6  -^^^^^---- A. Arpa and a research in Mexican wave number of standing spectators = 5.
  • At t = 7  --^^^^^--- A. Arpa and a research in Mexican wave number of standing spectators = 5.
  • At t = 8  ---^^^^^-- A. Arpa and a research in Mexican wave number of standing spectators = 5.
  • At t = 9  ----^^^^^- A. Arpa and a research in Mexican wave number of standing spectators = 5.
  • At t = 10 -----^^^^^ A. Arpa and a research in Mexican wave number of standing spectators = 5.
  • At t = 11 ------^^^^ A. Arpa and a research in Mexican wave number of standing spectators = 4.
  • At t = 12 -------^^^ A. Arpa and a research in Mexican wave number of standing spectators = 3.
  • At t = 13 --------^^ A. Arpa and a research in Mexican wave number of standing spectators = 2.
  • At t = 14 ---------^ A. Arpa and a research in Mexican wave number of standing spectators = 1.
  • At t = 15 ---------- A. Arpa and a research in Mexican wave number of standing spectators = 0.

  其实就是一个m串,规定了最多有n个可以一起亮,而时间间隔为一秒则亮一个,依次亮到了末尾时又依次暗直到全部暗.

 1 #include<iostream>
 2 using namespace std;
 3 int main(){
 4   int n,k,t;
 5   cin>>n>>k>>t;
 6   if(n>=k&&n>=t){
 7     if(k>t){
 8       cout<<t<<endl;
 9     }else{
10       cout<<k<<endl;
11     }
12   }else{
13     cout<<n+k-t<<endl;
14   }
15   return 0;
16 }

 

 

相关文章:

  • 2021-09-10
  • 2022-12-23
  • 2021-04-06
  • 2021-12-27
  • 2021-11-29
  • 2022-12-23
  • 2021-07-23
猜你喜欢
  • 2022-12-23
  • 2021-10-02
  • 2022-03-03
  • 2022-12-23
  • 2021-12-25
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案