Skip to content

Commit

Permalink
Merge pull request opencodeiiita#91 from kenma-w/main
Browse files Browse the repository at this point in the history
created problem
  • Loading branch information
rishabhking authored Dec 23, 2024
2 parents 7d88332 + 8c29b38 commit 548c925
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Problem-setting/githubusername-1/explanation.txt
Original file line number Diff line number Diff line change
@@ -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.
25 changes: 25 additions & 0 deletions Problem-setting/githubusername-1/solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include<bits/stdc++.h>
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<<ans<<endl;
}

signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);

int t;
cin>>t;
while(t--){
solve();
}
return 0;
}
15 changes: 15 additions & 0 deletions Problem-setting/githubusername-1/statement.txt
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 4 additions & 0 deletions Problem-setting/githubusername-1/test.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
3
2 1
10 8
67 24
3 changes: 3 additions & 0 deletions Problem-setting/githubusername-1/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0
6
43

0 comments on commit 548c925

Please sign in to comment.