diff --git a/Problem-setting/githubusername-1/explanation.txt b/Problem-setting/githubusername-1/explanation.txt new file mode 100644 index 0000000..ac1d092 --- /dev/null +++ b/Problem-setting/githubusername-1/explanation.txt @@ -0,0 +1,5 @@ +Solution: +Every Second the count of ON bulbs increses by 1. +If either of the first or last bulb turns ON then it takes 2 seconds for the count to increase. +The maximum number of bulbs which will be ON is equal to ceil(n/2). +So the final answer can be calculated as shown in solution.cpp. diff --git a/Problem-setting/githubusername-1/solution.cpp b/Problem-setting/githubusername-1/solution.cpp new file mode 100644 index 0000000..63227d0 --- /dev/null +++ b/Problem-setting/githubusername-1/solution.cpp @@ -0,0 +1,25 @@ +#include +using namespace std; +#define int long long int + + +void solve(){ + int n,x; + cin>>n>>x; + int ans=0; + ans+=min(x-1,n-x); + ans+=(ceil(n*1.0/2)-ans-1)*2; + cout<>t; + while(t--){ + solve(); + } +return 0; +} diff --git a/Problem-setting/githubusername-1/statement.txt b/Problem-setting/githubusername-1/statement.txt new file mode 100644 index 0000000..2692cfc --- /dev/null +++ b/Problem-setting/githubusername-1/statement.txt @@ -0,0 +1,15 @@ + Fix the Bulb + +There are n bulbs, numbered from 1 to n. The Bulbs are malfunctioning(OFF initially).Initially at 0th second the bulb x is in ON state. Every second, the Bulb k + which is in ON state turns OFF and the Bulbs, k−1 + (if it exists) and k+1 (if it exists) turns ON. + +This process happens for all the Bulbs which are in ON state at the same time. +Your task is to determine the least second at which maximum number of Bulbs are turned ON. + +Input +The first line contains the number of test cases t (1≤t≤10000) +The one and only line of each test case contains two integers n and x (1≤n≤10^18;1≤x≤n) + — the number of Bulbs and the Bulb which is ON initially. +Output +output a single integer: the least second at which maximum number of Bulbs are turned ON. diff --git a/Problem-setting/githubusername-1/test.in b/Problem-setting/githubusername-1/test.in new file mode 100644 index 0000000..e8949cd --- /dev/null +++ b/Problem-setting/githubusername-1/test.in @@ -0,0 +1,4 @@ +3 +2 1 +10 8 +67 24 diff --git a/Problem-setting/githubusername-1/test.out b/Problem-setting/githubusername-1/test.out new file mode 100644 index 0000000..32c8bd9 --- /dev/null +++ b/Problem-setting/githubusername-1/test.out @@ -0,0 +1,3 @@ +0 +6 +43