# Could anybody explain what is wrong with this code? It is running fine in a sample test, but...

#include <stdio.h>

int main(void) {
int T, N;
scanf("%d", &T);

``````while (T--) {
scanf("%d", &N);
int L[N], R[N];

for (int i=0; i<N; i++) scanf("%d", &L[i]);
for (int i=0; i<N; i++) scanf("%d", &R[i]);

int ans=0;
for (int i=0; i<N; i++)
if (i+1<N)
ans+= (R[i]>L[i+1]) ? L[i+1] : R[i];

printf("%d\n", ans);
}

return 0;
``````

}

Hey, could you mention the question name/link for which you have written the solution? Also, to get a faster response, you should try and write down your logic along with the implementation, which makes it is easier for users to understand your approach and find possible flaws in it.

Contest Page | CodeChef, thank you…

Hey, there can be cases where elements at either i or i+1 index may not pre present, because it has been removed in a previous operation, but in your code, you are still considering it.

Thank you, but could you tell how this can be fixed?
{"ft_lang_label":"__label__en","ft_lang_prob":0.8604673,"math_prob":0.87431425,"size":875,"snap":"2022-05-2022-21","text_gpt3_token_len":260,"char_repetition_ratio":0.10792193,"word_repetition_ratio":0.033333335,"special_character_ratio":0.33714285,"punctuation_ratio":0.1843318,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97274625,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-05-28T22:39:25Z\",\"WARC-Record-ID\":\"<urn:uuid:a880da98-9b9b-4b9b-81ad-8f89309ffaf0>\",\"Content-Length\":\"21122\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:13582a78-b149-4f6a-ba86-86df888743ca>\",\"WARC-Concurrent-To\":\"<urn:uuid:f9290143-bd00-4b1d-b5b7-640a97c14ad5>\",\"WARC-IP-Address\":\"50.19.228.217\",\"WARC-Target-URI\":\"https://discuss.codechef.com/t/could-anybody-explain-what-is-wrong-with-this-code-it-is-running-fine-in-a-sample-test-but/100403\",\"WARC-Payload-Digest\":\"sha1:7AKAK4F6AQJ4VIHULNT6DUX3DBFGJNZV\",\"WARC-Block-Digest\":\"sha1:37OXFR73FJNK3RSSUUJIDNT4BD4F4ZXM\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-21/CC-MAIN-2022-21_segments_1652663021405.92_warc_CC-MAIN-20220528220030-20220529010030-00339.warc.gz\"}"}