codeforces-1023 B Pair of Toys
1 #include <iostream> 2 #include <unordered_map> 3 #include <algorithm> 4 #include <vector> 5 #include <queue> 6 7 using namespace std; 8 9 int main() 10 { 11 long long int n,k; 12 while(cin >> n >> k) 13 { 14 if(n*2-1<k || k<3) 15 { 16 cout << "0" << endl; 17 } 18 else 19 { 20 if((n&0x1)==1) 21 { 22 long long mid = n/2; 23 long long dis = abs(k-(n+1)); 24 cout << mid - dis/2 << endl; 25 } 26 else 27 { 28 long long mid = n/2; 29 long long dis = abs(k-(n+1)); 30 cout << mid - dis%2 - dis/2 << endl; 31 } 32 } 33 } 34 return 0; 35 }