id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n\n bool check(int mid, vector<pair<int, int>> &interval){\n int f = interval[0].first;\n int n = interval.size();\n for(int i = 1; i<n; i++){\n int current = max(f+mid, interval[i].first);\n if(current>interval[i].second){\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "#include <vector>\n#include <algorithm>\n#include <iostream>\n\nusing namespace std;\n\nclass Solution {\npublic:\n bool canAchieveMinimumDifference(const vector<long long>& start, long long d, long long minDiff) {\n int n = start.size();\n long long lastChosen = start[0];\n \n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n bool ispossibleScore(vector<int>& start,vector<int>& end, long long num){\n long long prev = start[0];\n for(int i=1;i<start.size();i++){\n long long next = prev + num;\n if(next >= start[i] && next <= end[i]){\n prev = next;...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n bool isSol(vector<int>& start, int d, long long minDiff) {\n int n = start.size();\n long long prev = start[0];\n //cout<<\"diff \"<<minDiff<<endl;\n for (int i = 1; i < n; i++) {\n if (prev + minDiff <= start[i] + d) {\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "#include<bits/stdc++.h>\nusing namespace std ; \ntypedef long long int64 ; \n\nconst int64 INF = 1e17 ; \n\nclass Solution {\npublic:\n vector<int> a , f, up ; \n int n ; \n int D ; \n\n int check( int64 step ) {\n \n int64 last = a[0] ; \n\n \n for( int j = 1 ; j < n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n int maxPossibleScore(vector<int>& start, int d) {\n int n = start.size();\n vector<int> ends(n);\n \n // Calculate the end of each range\n for (int i = 0; i < n; i++) {\n ends[i] = start[i] + d;\n }\n \n // So...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n int maxPossibleScore(vector<int>& a, int d) {\n sort(a.begin(),a.end());\n int n=a.size();\n vector<int> maxi(n);\n for(int i=0;i<n;i++){\n maxi[i] = a[i]+d;\n }\n vector<long long> temp(n);\n for(int i=0;i<n;i++){\n...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n int maxPossibleScore(vector<int>& start, int d) {\n int n = start.size();\n vector<pair<long, long>> intervals(n);\n for (int i = 0; i < n; i++) {\n intervals[i] = {start[i], (long)start[i] + d};\n }\n\n sort(intervals.begin(), in...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "#define ll long long\nclass Solution {\npublic:\n int maxPossibleScore(vector<int>& start, int d) {\n ll n = start.size();\n vector<pair<ll, ll>> v(n);\n \n // Create intervals [start[i], start[i] + d]\n for (ll i = 0; i < n; ++i) {\n v[i] = {start[i], start...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "#define ll long long\nclass Solution {\npublic:\n int maxPossibleScore(vector<int>& start, int d) {\n ll n = start.size();\n vector<pair<ll, ll>> v(n);\n \n // Create intervals [start[i], start[i] + d]\n for (ll i = 0; i < n; ++i) {\n v[i] = {start[i], start...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n#define siddhantnema ios_base::sync_with_stdio(0); cin.tie(0);\n#define ll long long\n#define inparr(arr, N) for (ll i = 0; i < N; i++) { cin >> arr[i]; }\n#define forn(_i, N) for (ll _i = 0; _i < N; _i++)\n#define trc(x) cout << #x << \" -> \" << x << '\\n';...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n bool check(long long &d, vector<pair<int, int>> &nums)\n {\n long long prev = nums[0].first;\n for(int i = 1; i < nums.size(); i++)\n {\n if(nums[i].first - prev >= d)\n prev = nums[i].first;\n else if(prev + d >= n...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n bool solve(long long mid,vector<pair<int,int>>&vec){\n long long prev=vec[0].first;\n for(int i=1;i<vec.size();i++){\n long long int next=max(prev+mid,(long long int)vec[i].first);\n if(next>vec[i].second)return false;\n prev=nex...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n bool check(long long mid, vector<long long> &start, int d){\n long long curr=start[0];\n for(int i=1;i<start.size();i++){\n if(start[i]>=curr+(long long )mid){\n curr=start[i];\n }\n else if(curr+(long long)mid <= ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n \n bool isPossible(vector<pair<int, int>>& ranges, int minDiff) {\n long long lastPicked = ranges[0].first; \n for (int i = 1; i < ranges.size(); ++i) {\n \n if (ranges[i].first >= lastPicked + minDiff) {\n lastPicked = r...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n \n bool isPossible(vector<pair<int, int>>& ranges, int minDiff) {\n long long lastPickedNumber = ranges[0].first; \n for (int i = 1; i < ranges.size(); ++i) {\n \n if (ranges[i].first >= lastPickedNumber + minDiff) {\n la...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n bool solve(const std::vector<std::pair<int, int>>& arr, long long k) {\n long long count = 1;\n long long prev = arr[0].first;\n \n for (size_t i = 1; i < arr.size(); ++i) {\n if (prev + k <= arr[i].second) {\n prev = std:...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n bool is_possible(vector<int> &a, int n, long long mid, int d){\n long long x=a[0];\n for(int i=1;i<n;i++){\n long long y=x+mid;\n if(y>a[i]+d){\n return false;\n }\n x=max(y,(long long)a[i]);\n }\...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n vector<long long> b;\n vector<long long> a;\n long long d;\n\n bool check(long long x) {\n b[0]=a[0]+d;\n for(int i=1;i<b.size();i++) {\n b[i]=min(a[i]+d, b[i-1]-x);\n if(b[i]<a[i]) return false;\n }\n return true;\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n int n=0;\n bool poss(vector<int>a,int d,long long int maxv)\n {\n long long int dp[n];\n dp[0]=a[0];\n dp[n-1]=a[n-1]+d;\n for(int i=1;i<n;i++)\n {\n long long int k=a[i]+d;\n if(i==n-1)\n {\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n int maxPossibleScore(vector<int>& initialPoints, int range) {\n ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);\n int totalCount = initialPoints.size();\n vector<pair<long long, long long>> boundaryPairs;\n for (int i = 0; i < totalC...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "static auto TheNameIsRishabhMaheshwari = [](){\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\n return nullptr;\n}();\nclass Solution {\npublic:\n int maxPossibleScore(vector<int>& start, int d) {\n int n = start.size();\n vector<pair<long long, long l...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n #define ll long long\n int maxPossibleScore(vector<int>& start, int d) {\n int n = start.size();\n sort(start.begin(),start.end());\n\n vector<pair<ll,ll>> arr;\n for(auto a:start){\n arr.push_back({a,a+d});\n }\n\n ll l...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n int maxPossibleScore(vector<int>& start, int d) {\n vector<pair<long long int,long long int>>nums;\n int n=start.size();\n for(int i=0;i<n;i++){\n nums.push_back({(long long int)start[i],(long long int)start[i]+(long long int) d});\n }\n...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n\n bool isPossible(vector<pair<long long int,long long int>> &v,long long int mid){\n long long int n=v.size();\n long long int p=v[0].first;\n bool flag=false;\n for(int i=1;i<n;i++){\n long long int f=p+mid;\n if(f>=v[i].first && f<=v[i].second){\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n\n bool isPossible(vector<pair<long long int,long long int>> &v,long long int mid){\n long long int n=v.size();\n long long int p=v[0].first;\n bool flag=false;\n for(int i=1;i<n;i++){\n long long int f=p+mid;\n if(f>=v[i].first && f<=v[i].second){\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n int maxPossibleScore(vector<int>& start, int d) {\n int n = start.size();\n vector<pair<long long, long long>> intervals;\n for (int s : start) {\n intervals.push_back({(long long)s, (long long)s + d});\n }\n sort(intervals.begin(...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n int maxPossibleScore(vector<int>& start, int d) {\n int n = start.size();\n vector<pair<long long, long long>> intervals;\n for (int s : start) {\n intervals.emplace_back(s, static_cast<long long>(s) + d);\n }\n sort(intervals.beg...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n int maxPossibleScore(vector<int>& start, int d) {\n int n = start.size();\n vector<pair<long long, long long>> intervals;\n for (int s : start) {\n intervals.emplace_back(s, (long long)s + d);\n }\n sort(intervals.begin(), interva...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "using ll = long long int;\nclass Solution {\npublic:\n int n;\n vector<ll> bounds[2];\n bool check(ll mid) {\n int cnt = 1;\n ll st = bounds[0][0];\n ll en = st + mid;\n while (cnt < n && en <= bounds[1][n-1]) {\n ll ast = bounds[0][cnt];\n ll aen ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n int maxPossibleScore(vector<int>& start, int d) {\n \n int kt2=0;\n int sz=start.size();\n std::sort(start.begin(), start.end());\n \n int n = start.size();\n int minDiff_aaya = INT_MAX;\n int kt=0;\n for (int i =...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n int maxPossibleScore(vector<int>& start, int d) {\n \n sort(start.begin(),start.end());\n long long n=(long long)start.size();\n map<int,int>mp;\n for(int i=0;i<n;i++)\n {\n mp[start[i]]++;\n }\n\n long long r...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "#define ll long long\nclass Solution {\npublic:\n bool ispos(vector<int>&start,int d,ll diff)\n {\n ll prev=start[0];\n bool ha=false;\n //if(diff==3) cout<<\":\"<<prev<<endl;\n for(int i=1;i<start.size();i++)\n {\n //if(diff==3) {cout<<\":\"<<prev<<endl;...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n int check(vector<int> start, int ans, int n, int d) {\n for(int i = 1; i < n - 1; i++) {\n if(start[i - 1] + ans > start[i] + d)\n return 1;\n start[i] = max(start[i - 1] + ans, start[i]);\n if(start[i] + ans > start[i + 1] +...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n int f(long long ans,vector<pair<long long,long long>> v){\n long long low=0,high=ans;\n while(low<=high){\n long long mid=low+((high-low)>>1);\n long long t=v[0].first,flag=0;\n for(int i=1;i<v.size();i++){\n t=t+m...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n int maxPossibleScore(vector<int>& start, int d) {\n int n=start.size();\n if(n==1) return start[0];\n map<pair<int,int>,int>mp;\n for(auto it:start){\n mp[{it,it+d}]=1;\n }\n auto it=mp.begin();\n auto it1=mp.end();\...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "/*\n[2,6,13,13]\n 2,6,13,18\n*/\n\nclass Solution {\npublic:\n int maxPossibleScore(vector<int>& start, int d) {\n sort(start.begin(), start.end());\n int lo = 0, hi = (start.back() + d - start[0]) / (start.size() - 1) + 2;\n while (lo < hi) {\n int mid = lo + (hi - lo) /...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n int n;\n bool solve(vector<int> start,int mid,int d){\n for(int i=1;i<n-1;i++){\n if(start[i]-start[i-1]<mid){\n if(start[i-1]+mid>=start[i] && start[i-1]+mid<=start[i]+d){\n start[i]=start[i-1]+mid;\n }\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n bool check(vector<int> start, int mid,int d){\n int sz = start.size();\n for(int i = 1;i<sz;i++){\n if(start[i]-start[i-1]>=mid)continue;\n else{\n int diff = start[i]-start[i-1];\n if(diff+d>=mid &&i!=sz-1)sta...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "#include <vector>\n#include <algorithm>\n\nusing namespace std;\n\n#define ll long long\n\nclass Solution {\npublic:\n // Function to check if we can achieve a minimum difference of x\n bool check(ll x, const vector<int>& original_start, ll d) {\n vector<int> start = original_start; // Use a c...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "#define ll long long\nclass Solution {\npublic:\n bool check(ll x, vector<int> start, ll d) {\n ll mn = x;\n for (int i = 1; i < start.size(); i++) {\n ll next = start[i - 1] + x;\n if (1ll*start[i] <= next && next <= 1ll*(start[i] + d)) {\n start[i] = ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n\n bool check(vector<int> start, int step, int d){\n for(int i=1; i<start.size(); i++){\n if( (start[i]-start[i-1]) >= step) continue;\n int step1 = step - (start[i]-start[i-1]);\n if(step1 > d) return false;\n start[i] = star...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\nprivate:\n vector<int> start;\n int d;\n vector<pair<long long, long long>> intervals;\npublic:\n int maxPossibleScore(vector<int>& start, int d) {\n this->start = start;\n this->d = d;\n constructIntervals();\n return findValueWithBinarySearch();\n...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n\n bool helper(vector<int> v, long long test, int d)\n {\n long long a = 0;\n for(int i=0;i<v.size();i++)\n {\n long long goalVal = (v[0] + test * i) + a;\n //cout<<test<<\" \"<<goalVal<<\" \"<<v[i]<<\" \"<<goalVal-v[i]<<\" \"<<d<<...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n int maxPossibleScore(vector<int>& start, int d) {\n vector<vector<long long > > intervals;\n intervals.resize(start.size());\n sort(start.begin(),start.end());\n for(int i = 0;i<start.size();i++) {\n intervals[i].resize(2);\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n int maxPossibleScore(vector<int>& start, int d) {\n int n = start.size(); vector<vector<int>> a(n, vector<int> (2));\n for (int i = 0; i < n; i++) a[i][0] = start[i], a[i][1] = a[i][0] + d;\n sort (a.begin(), a.end());\n \n auto checker = [&...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "#define ll long long\n\nclass Solution {\npublic:\n\n bool isPoss(vector<vector<ll>>& a, int n, int mid){\n ll curr = a[0][0];\n\n for(int i = 1; i < n; i++){\n if(a[i][1]-curr < mid) return false;\n\n curr = max(curr+mid, a[i][0]);\n }\n\n return true;\...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "#define ll long long\n\nclass Solution {\npublic:\n\n bool isPoss(vector<vector<ll>>& a, int n, int mid){\n ll curr = a[0][0];\n\n for(int i = 1; i < n; i++){\n if(a[i][1]-curr < mid) return false;\n\n curr = max(curr+mid, a[i][0]);\n }\n\n return true;\...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n bool test(vector<int> start, int d, int k) {\n for (int i = 1; i < start.size() -1 ; ++i) {\n if (start[i] - start[i - 1] >= k) {\n // do nothing\n } else if (start[i] + d - start[i - 1] >= k) {\n start[i] = start[i -...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n bool isPos(int mid, vector<int> &start, int d){\n int n = start.size();\n long long int prev = start[0];\n\n for (int i = 1; i < n; ++i) {\n long long int next = max(prev + (long long int)mid, (long long int)start[i]);\n if (next > s...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n #define ff first\n #define ss second\n #define ll long long\n vector<pair<ll,ll>>p;\n int n;\n int solve(int d,int mid){\n ll x=p[0].ff,y=p[0].ss;\n for(int i=1;i<n;i++){\n if(p[i].ss<x+mid){\n return false;\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\n #define ll long long\n bool solve(const vector<vector<ll>> &arr, ll mid) {\n ll low = arr[0][0];\n for (int i = 1; i < arr.size(); i++) {\n low += mid;\n if (low > arr[i][1] ) return false;\n low = max(low, arr[i][0]);\n }\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "typedef long long int ll;\nclass Solution {\npublic:\n bool isPossible(vector<vector<int>>&intervals,int num)\n {\n int n = intervals.size();\n \n // first number of first interval\n ll lastPicked = intervals[0][0];\n \n for (int i = 1; i < n; ++i) {\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "#define ll long long \n\nclass Solution {\npublic:\n vector<vector<ll>> v;\n\n\n bool solve(int mid) {\n ll prev = v[0][0];\n \n for (int i = 0; i < v.size(); i++) {\n ll start = v[i][0];\n ll end = v[i][1];\n \n if (prev > end) {\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "#define ll long long\nclass Solution {\npublic:\n bool isValid(vector< vector<ll> >&ar, ll dis){\n ll idx=ar[0][0],n=ar.size();\n for(int i=1;i<n;i++){\n ll req = idx+dis;\n if(req>=ar[i][0] && req<=ar[i][1]){\n idx = req;\n }else if(req<ar[i...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n\n bool checkPossibility(vector<int> &start, int val, int d) {\n int n = start.size();\n vector<int> dstart(n);\n for(int i=0;i<n;i++)\n dstart[i] = start[i];\n\n for(int i=1;i<n;i++) {\n int diff = (dstart[i]-dstart[i-1]);\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\nprivate:\nbool check(vector<int>start,int d,long long mid){\n for(int i=0;i<start.size()-1;i++){\n if(start[i+1]-start[i]<mid && start[i]+mid-start[i+1]<=d){\n start[i+1]=start[i]+mid;\n }\n else if(start[i+1]-start[i]<mid && start[i]+mid-start[i+1]>d) r...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\nbool possible(int mid,vector<int>start,int d)\n{\n for(int i=1;i<start.size();i++)\n {\n if(start[i]-start[i-1]<mid)\n {\n int diff=mid-(start[i]-start[i-1]);\n if(diff<=d)\n {\n start[i]=start[i]+diff;\n }\n else\n return false;...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "#pragma GCC optimize(\"Ofast\")\n#pragma GCC target(\"avx,avx2,fma\")\n#pragma GCC optimization (\"unroll-loops\")\n#include<bits/stdc++.h>\n#include <bits/stdc++.h>\n#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\nusing namespace std;\n\n#define pb push_back\n#define loop(i...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n int maxPossibleScore(vector<int>& nums, int d) {\n sort(nums.begin(), nums.end());\n int n = nums.size();\n int mini = INT_MAX;\n\n // Find the minimum difference between adjacent elements\n for (int i = 0; i < n - 1; i++) {\n min...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n int maxPossibleScore(vector<int>& start, int d) {\n std::sort(start.begin(), start.end());\n long r = start[1] - start[0];\n int n = start.size();\n for(int i=1; i<n-1; i++)\n {\n r = std::min(r, long(start[i+1] - start[i]));\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\nprivate:\n bool check_possi(vector<int> arr, int d, int interval) {\n int N = arr.size();\n for (int i = 1; i < N; i++) {\n int diff = arr[i] - arr[i - 1];\n if (diff >= interval) {\n continue;\n } else {\n if...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n bool checkPossibleScore(int score, vector<int> start, int d) {\n for(int i = 1; i < start.size(); i++) {\n int currScore = start[i] - start[i - 1];\n if(currScore >= score) continue;\n else {\n if(currScore + d < score) r...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n int maxPossibleScore(vector<int>& start, int d) {\n sort(start.begin(),start.end());\n int n=start.size();\n long long r=start[n-1]+d-start[n-2];\n long long l=0;\n long long ans=0;\n while(l<=r)\n {\n long long mid=(l+r)/2;\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\nprivate: \n bool feasible(int x, vector<int> a, int d){\n int n = a.size();\n long long prev = a[0]; // 0\n for(int i=1;i<n;i++){\n \n if(prev+x > a[i]+d){\n return false;\n } else {\n prev = max((long ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "// #define int long long int\n\nclass Solution {\npublic:\n bool midIsAchievable(vector<int> start,long long int midValue,long long int extraBand,long long int size){\n for(int i=1; i<size-1; i++){\n if(((long long int)start[i-1])+midValue > ((long long int)start[i])+extraBand) return ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n int maxPossibleScore(vector<int>& start, int d) {\n sort(start.begin(), start.end());\n start.back() += d;\n int n = start.size();\n \n int l = 0, r = 0;\n \n for (int i = 1; i < n; i++) {\n r = max(start[i] - start[...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n\n bool possible(long long mid, vector<int>& start, int d){\n // is it possible to attain a min difference of mid among all elements of start or not\n\n vector<int> nums=start;\n\n for(int i=0;i<start.size()-1;i++){\n int diff=nums[i+1]-nums[i];...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n bool isPossible(int x,vector<int> start,int d){\n\n for(int i = 1;i<start.size();i++){\n if(start[i]-start[i-1]<x) {\n if(x-(start[i]-start[i-1])>d) return false;\n start[i] = start[i-1]+x;\n }\n }\n\n return true;\n\n } \n\n i...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n\n bool solve(long long diff, vector<int> start,int d){\n int s=start[0];\n int i=1;\n while(i<start.size()){\n if(s+diff>=start[i] && s+diff<=start[i]+d){\n s=s+diff;\n }\n else if(s+diff<start[i]){\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n#define ll long long int\n int maxPossibleScore(vector<int>& v, int d) {\n ll n = v.size();\n sort(v.begin(), v.end());\n int mx = 0;\n for(ll i=0; i<n-1; i++) mx = max(mx, v[i+1]-v[i]);\n ll l = 0, h = mx+d;\n while(l<=h){\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n bool isPossible(int x,vector<int> start,int d){\n\n for(int i = 1;i<start.size();i++){\n if(start[i]-start[i-1]<x) {\n if(x-(start[i]-start[i-1])>d) return false;\n start[i] = start[i-1]+x;\n }\n }\n\n return true;\n\n } \n\n i...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\n bool check(int x,vector<int> start, int d){\n int n=start.size();\n for(int i=1;i<n;i++){\n if(start[i]+d-start[i-1]<x){\n return false;\n }\n else{\n start[i]=max(start[i-1]+x,start[i]);\n }\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\n // Helper function to check if the minimum possible score x can be achieved\n bool check(int x, vector<int> start, int d) {\n int n = start.size(); // Get the number of elements in the start vector\n for (int i = 1; i < n; i++) {\n // If the difference betw...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\n typedef long long ll;\n bool good(vector<int>& start, ll mid, int d) {\n vector<int> temp = start;\n int n = size(temp);\n for(int i = 1; i < n; i++) {\n if(temp[i]+d-temp[i-1] < mid) return false;\n temp[i] = max(temp[i-1]+mid,1LL*temp[i]...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\nprivate:\n \n bool check(int m, vector<int> start, int d){\n long long s=start[0];\n long long e=start[0]+d;\n for(int i=1; i<start.size(); i++){\n long long ns=start[i];\n long long ne=start[i]+d;\n\n if((ne-s) < m) return 0;\n\...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\nbool feasible(vector<int> start, long long no, long long d)\n{\n \n for(int i = 1 ;i<start.size(); i++)\n {\n \n if((start[i]-start[i-1]+d )>= no && (start[i]-start[i-1])< no)\n {\n start[i]+= no-(start[i]-start[i-1]);\n }\n\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n bool feasible(vector<int> start, long long no, long long d) {\n for (int i = 1; i < start.size(); i++) {\n if ((start[i] - start[i-1] + d) >= no && (start[i] - start[i-1]) < no) {\n start[i] += no - (start[i] - start[i-1]);\n } else...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n\n bool check(long long mid, vector<int> start, int n, int d){\n long long s = start[0];\n for(int i=1; i<n; i++){\n long long next = max(s + mid, static_cast<long long>(start[i]));\n if(start[i] + d < next) return false;\n s = ne...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n bool possible(vector<int>v, long long d, long long ans){\n long long prev=v[0];\n for(int i=1; i<v.size(); i++){\n if(v[i]-prev >= ans){\n prev = v[i];\n }\n else if(prev+ans <= v[i]+d){\n prev = pre...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "using ll = long long;\nclass Solution {\npublic:\n \n bool diff(vector<int>nums, ll gap, int d){\n int start = nums[0];\n for(int i=1; i<nums.size(); i++){\n if(start+gap<=nums[i]+d){\n if(start+gap<nums[i]) start = nums[i];\n else start+=gap;\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n int maxPossibleScore(vector<int>& start, int d) {\n int l = 0;\n sort(start.begin(), start.end());\n int r = start[1] - start[0] + d;\n while (l < r) {\n int m = l + (r - l) / 2;\n if (check(start, d, m)) {\n l ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n bool check(vector<int> start,int d,int mid){\n long long prev=start[0];\n for(int i=1;i<start.size();i++){\n long long next=max(prev+mid,(long long)start[i]);\n if(next>start[i]+d){\n return false;\n }\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\n bool isposs(long long diff,vector<int>start,long long d){\n for(int i = 1;i<start.size();i++){\n if((start[i]-start[i-1])>=diff){\n continue;\n }\n else if((start[i]+d-start[i-1])>=diff){\n start[i] += (diff-(start[i...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n int check(vector<int> a, int x, int d, int n) {\n int prev = a[0];\n for (int i=1; i<n; i++) {\n if (a[i] - prev < x) {\n if (a[i] + d - prev < x) {\n return false;\n }\n a[i] += (x - (a[...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n bool solve(vector<int> nums,int d,int mid){\n long long prev=nums[0];\n for(int i=1;i<nums.size();i++){\n long long next=max(static_cast<long long>(nums[i]),prev+mid);\n if(next>nums[i]+d){\n return 0;\n }\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n bool solve(vector<int> nums,int d,int mid){\n long long prev=nums[0];\n for(int i=1;i<nums.size();i++){\n long long next=max(static_cast<long long>(nums[i]),prev+mid);\n if(next>nums[i]+d){\n return 0;\n }\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n int maxPossibleScore(vector<int>& nums, int d) {\n int n = nums.size();\n sort(nums.begin(), nums.end());\n int max_score = INT_MIN;\n long long start = 0, end = nums[n-1]+d;\n while(start <= end) {\n int mid = (start+end)>>1;\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n \n \n bool check(vector<int>& v, int d,int mid)\n {\n vector<int> temp = v; \n for(int i=1;i<temp.size();i++)\n {\n int x = temp[i] - temp[i-1];\n if(x >= mid)\n {\n continue;\n }\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n bool f(vector<int>arr,int mid,int d)\n {\n int n = arr.size();\n for(int i=1; i<n; i++)\n {\n int diff = arr[i] - arr[i-1];\n if(diff >= mid) continue;\n\n int need = mid - diff;\n if(d >= need)\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "#include <bits/stdc++.h>\n#define ll long long int\n#define pb push_back\n#define cy cout << \"YES\" << endl\n#define cn cout << \"NO\" << endl\n#define all(a) a.begin(), a.end()\n#define endl '\\n'\nusing namespace std;\n\nbool f(ll x, int d, vector<int>& a) {\n int n = a.size();\n for (int i = 1; i...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n # define ll long long\n bool canAchieveMid(vector<int> start, int d, long long mid) {\n int n = start.size();\n ll prev = start[0]; \n for (int i = 1; i < n; i++) \n { \n ll lB = prev + mid;\n if (lB>(ll)start[i]+d) \n {\n retu...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n # define ll long long\n bool canAchieveMid(vector<int> start, int d, long long mid) {\n int n = start.size();\n ll prev = start[0]; \n int i=1;\n while(i<n) \n { \n ll lB = prev + mid;\n if (lB>(ll)start[i]+d) \n {\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n bool check(vector<int> start,int d,int mid){\n for(int i=1;i<start.size();i++){\n if(start[i]-start[i-1]>=mid) continue;\n else{\n if(start[i]+d-start[i-1]<mid) return false;\n start[i] = mid+start[i-1];\n ...
3,485
<p>You are given an array of integers <code>start</code> and an integer <code>d</code>, representing <code>n</code> intervals <code>[start[i], start[i] + d]</code>.</p> <p>You are asked to choose <code>n</code> integers where the <code>i<sup>th</sup></code> integer must belong to the <code>i<sup>th</sup></code> interv...
3
{ "code": "class Solution {\npublic:\n bool check(int m, vector<int>start, int d){\n int n = start.size();\n for(int i = 1; i<n; i++){\n if((start[i] + d - start[i-1]) < m) return false;\n int c = m - (start[i] - start[i-1]);\n start[i] += max(c,0);\n }\n ...
3,528
<p>You are given an integer array <code>nums</code> of length <code>n</code>.</p> <p>Your goal is to start at index <code>0</code> and reach index <code>n - 1</code>. You can only jump to indices <strong>greater</strong> than your current index.</p> <p>The score for a jump from index <code>i</code> to index <code>j</...
0
{ "code": "class Solution {\npublic:\n long long findMaximumScore(vector<int>& nums) {\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n int n=nums.size();\n /*long long sum=0,maxsum=0;\n for(int i=0;i<n-1;i++){\n for(int j=i+1;j<n;j++){\n ...
3,528
<p>You are given an integer array <code>nums</code> of length <code>n</code>.</p> <p>Your goal is to start at index <code>0</code> and reach index <code>n - 1</code>. You can only jump to indices <strong>greater</strong> than your current index.</p> <p>The score for a jump from index <code>i</code> to index <code>j</...
0
{ "code": "/*\n#pragma GCC optimize(\"O3\")\n#pragma GCC optimize(3, \"Ofast\", \"inline\")\n#pragma GCC optimize(\"Ofast\")\n#pragma GCC optimize(\"unroll-loops\")\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt\")\n*/\n\nauto init = []() \n{\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nu...
3,528
<p>You are given an integer array <code>nums</code> of length <code>n</code>.</p> <p>Your goal is to start at index <code>0</code> and reach index <code>n - 1</code>. You can only jump to indices <strong>greater</strong> than your current index.</p> <p>The score for a jump from index <code>i</code> to index <code>j</...
0
{ "code": "#pragma GCC optimize(\"O3\")\n#pragma GCC optimize(3, \"Ofast\", \"inline\")\n#pragma GCC optimize(\"Ofast\")\n#pragma GCC optimize(\"unroll-loops\")\n#pragma GCC target(\"avx2,bmi,bmi2,lzcnt,popcnt\")\n\nauto init = []() \n{\n ios::sync_with_stdio(false);\n cin.tie(nullptr);\n cout.tie(nullptr);\...
3,528
<p>You are given an integer array <code>nums</code> of length <code>n</code>.</p> <p>Your goal is to start at index <code>0</code> and reach index <code>n - 1</code>. You can only jump to indices <strong>greater</strong> than your current index.</p> <p>The score for a jump from index <code>i</code> to index <code>j</...
0
{ "code": "class Solution {\npublic:\n long long findMaximumScore(vector<int>& nums) {\n int n=nums.size();\n long long ans=0;\n int i=0,j=0;\n while(j<n-1){\n while(j<n-1 && nums[j]<=nums[i]){\n j++;\n }\n ans+=(long long) (j-i)*nums[i];\...
3,528
<p>You are given an integer array <code>nums</code> of length <code>n</code>.</p> <p>Your goal is to start at index <code>0</code> and reach index <code>n - 1</code>. You can only jump to indices <strong>greater</strong> than your current index.</p> <p>The score for a jump from index <code>i</code> to index <code>j</...
0
{ "code": "class Solution {\npublic:\n long long findMaximumScore(vector<int>& nums) {\n \n long long res=0;\n int n=nums.size();\n long long ma=nums[0],ind=0;\n for(int i=1;i<n;i++)\n {\n if(ma<nums[i]){\n res=res+(ma)*(i-ind);\n m...