Codeforces Round 955 C - Boring Day | Detailed Video Editorial
Ғылым және технология
Codeforces Round 955 C : Boring Day Detailed Video Editorial | English Language | Two Pointers + Greedy
Subscribe and never miss a tutorial !!
/ @formidablechief27
0:00 - Question Explanation
0:45 - Testcase Explanation
1:30 - Conditions for Succesfull Answer
2:09 - Operation for sum greater than r
2:45 - Two Pointer Technique for Trimming
6:27 - Code Explanation
Пікірлер: 7
One Important Thing Missed Out The complexity of the code is O(2n) and not O(n2) because the inner while loop executes at most n times in all loop iterations combined we are not starting from 0 everytime again and again we are continuing from where we ended in last operation hence the loop executes at most n times making total complexity = O(2n) Sub Link : codeforces.com/contest/1982/submission/267418199
Very nice explanation sir, Thank you!
Thank you for explaining I was waiting for your solution !
#include using namespace std; int main(){ long long int t; cin>>t; for(long long int j=0;j>n>>l>>r; long long int a[n]; for(long long int i=0;i>a[i]; } long long int s=0; long long int m=0; for(long long int i=0;ir){s=0; if(a[i]
@formidablechief27
2 күн бұрын
The problem is in s > r condition There you are not taking care of the situation u can get a suitable subarray if u trim your starting elements. Example counter case n = 5 l = 10 r = 10 a = [1, 1, 1, 1 10] In this case the suitable ans is just [10] but ur code will work right upto [1 1 1 1] and then it doesnt trim the start, instead u are directly making sum = 0 and hence not getting correct ans Another mistake i encountered, u are performing i--, wont that add the same element twice ?
@madhursharma7200
2 күн бұрын
@@formidablechief27 yeah after [1111] ,s become 4 and when i encounter 10, s become 14 and after it s>r that's why s=0 and i again add 10 in next loop so s become 10 and ans will come 1. My code also gives output 1.
@formidablechief27
2 күн бұрын
@madhursharma7200 Ok then this case might just do it n = 4, l = 10, r = 10 a = [1, 1, 1, 8] Ur code gives what for this case ?