Consider the case n=5 and k=12, so in the first iteration we are looking in the set for the value 6+1=7, which should return st.end() and dereferencing it should give a garbage value unless we handle this case. I don't understand how did it get accepted.
Not really, I have explained how I observed the observations in the problem, it was either by trying to find a pattern or trying to think in terms of how I have solved similar problems previously.
@@jeevanalexen yup I was able to understand your explanation, thanks a lot, but I am not able to make good observation and notice the pattern. is it improved by practice or is there technique to do this?
could you explain why this code is not getting accepted though I went with a similar approach #include using namespace std; #define ll long long int main() { int t; cin >> t; while (t--) { long long n, k; cin >> n >> k;
Because we are doing val - (i+1) below, there we subtract i+1 from val. So to negate that, we are taking remain + i + 1, so that the subtraction below wont affect it.
Consider the case n=5 and k=12, so in the first iteration we are looking in the set for the value 6+1=7, which should return st.end() and dereferencing it should give a garbage value unless we handle this case. I don't understand how did it get accepted.
Thanks for this explanation. Do you have any recommendations for improving observation skills?
Not really, I have explained how I observed the observations in the problem, it was either by trying to find a pattern or trying to think in terms of how I have solved similar problems previously.
We're you able to understand my explanation properly?
@@jeevanalexen yup I was able to understand your explanation, thanks a lot, but I am not able to make good observation and notice the pattern. is it improved by practice or is there technique to do this?
@@mennaselim409it can be improved only by practise.
could you explain why this code is not getting accepted though I went with a similar approach
#include
using namespace std;
#define ll long long
int main() {
int t;
cin >> t;
while (t--) {
long long n, k;
cin >> n >> k;
// Check if k is odd
if (k % 2 != 0) {
cout
why are u using remain + i + 1 why not just remain
Because we are doing val - (i+1) below, there we subtract i+1 from val. So to negate that, we are taking remain + i + 1, so that the subtraction below wont affect it.
Please let me know if you need further explanation