PLEASE Help this newbie with this problem (stuck for 4+ hours).

Правка en1, от StellarSpecter, 2024-07-01 18:05:05

I can't understand why this solution 268341805 is passing but this 268341778 is giving WA on testcase 2, both codes are 99% same.

TLDR: I am writing down the part of my code which I changed so that my code got AC.

Please all the help would be greatly appreciated. Thank you so much in advance.

auto it = upper_bound(v.begin(),v.end(),val);
                        if(it!=v.end()&&it!=v.begin()) {
                            ans=min(ans,min(abs(*(it)-val),abs(*(--it)-val))); // old
                        }
                        else if(it==v.end()) {
                            ans = min(ans,abs(*(--it)-val));  //old
                        }
                        else if(it==v.begin()) {
                            ans=min(ans,abs(*(it) - val));  //old
                        }
auto it = upper_bound(v.begin(),v.end(),val);
                        if(it!=v.end()&&it!=v.begin()) {
                            auto it2 = it; it--;                                   // new
                            ans=min(ans,min(abs(*it2-val),abs(*(it)-val)));
                        }
                        else if(it==v.end()) {
                            it--;
                            ans = min(ans,abs(*(it)-val));                        // new
                        }
                        else if(it==v.begin()) {
                            ans=min(ans,abs(*it - val));                         // new
                        }
Теги help, div2, newbie, problem c

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский StellarSpecter 2024-07-01 18:05:05 1613 Initial revision (published)