Skip to content

Commit

Permalink
Drawing Book
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranjal authored Jun 16, 2017
1 parent d548d5f commit 7a3f16e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions DrawingBook.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <bits/stdc++.h>

using namespace std;

int solve(int n, int p){
// Complete this function
if(p == 1 || p == n){
return 0;
}

int ans = 1 + (p-2)/2;

if(n%2 == 0){
return min(ans, (int)(1 + (n-p-1)/2));
}

return min((int)(n-p)/2, ans);
}

int main() {
int n;
cin >> n;
int p;
cin >> p;
int result = solve(n, p);
cout << result << endl;
return 0;
}

0 comments on commit 7a3f16e

Please sign in to comment.