{"problem":{"name":"A. Greed","description":{"content":"Jafar has _n_ cans of cola. Each can is described by two integers: remaining volume of cola _a__i_ and can's capacity _b__i_ (_a__i_  ≤  _b__i_). Jafar has decided to pour all remaining cola into jus","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF892A"},"statements":[{"statement_type":"Markdown","content":"Jafar has _n_ cans of cola. Each can is described by two integers: remaining volume of cola _a__i_ and can's capacity _b__i_ (_a__i_  ≤  _b__i_).\n\nJafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not!\n\n## Input\n\nThe first line of the input contains one integer _n_ (2 ≤ _n_ ≤ 100 000) — number of cola cans.\n\nThe second line contains _n_ space-separated integers _a_1, _a_2, ..., _a__n_ (0 ≤ _a__i_ ≤ 109) — volume of remaining cola in cans.\n\nThe third line contains _n_ space-separated integers that _b_1, _b_2, ..., _b__n_ (_a__i_ ≤ _b__i_ ≤ 109) — capacities of the cans.\n\n## Output\n\nPrint \"_YES_\" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print \"_NO_\" (without quotes).\n\nYou can print each letter in any case (upper or lower).\n\n[samples]\n\n## Note\n\nIn the first sample, there are already 2 cans, so the answer is \"_YES_\".","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"Jafar 有 #cf_span[n] 罐可乐。每罐可乐由两个整数描述：剩余可乐体积 #cf_span[ai] 和罐的容量 #cf_span[bi]（#cf_span[ai] #cf_span[ ≤ ] #cf_span[bi]）。\n\nJafar 决定将所有剩余可乐倒入恰好 #cf_span[2] 个罐中，请判断他是否能做到！\n\n输入的第一行包含一个整数 #cf_span[n]（#cf_span[2 ≤ n ≤ 100 000]）— 可乐罐的数量。\n\n第二行包含 #cf_span[n] 个用空格分隔的整数 #cf_span[a1, a2, ..., an]（#cf_span[0 ≤ ai ≤ 10^9]）— 每罐中剩余可乐的体积。\n\n第三行包含 #cf_span[n] 个用空格分隔的整数 #cf_span[b1, b2, ..., bn]（#cf_span[ai ≤ bi ≤ 10^9]）— 每罐的容量。\n\n如果可以将所有剩余可乐倒入 #cf_span[2] 个罐中，请输出 \"_YES_\"（不含引号）；否则输出 \"_NO_\"（不含引号）。\n\n你可以以任意大小写形式输出每个字母。\n\n在第一个样例中，已有 #cf_span[2] 个罐，因此答案为 \"_YES_\"。\n\n## Input\n\n输入的第一行包含一个整数 #cf_span[n]（#cf_span[2 ≤ n ≤ 100 000]）— 可乐罐的数量。第二行包含 #cf_span[n] 个用空格分隔的整数 #cf_span[a1, a2, ..., an]（#cf_span[0 ≤ ai ≤ 10^9]）— 每罐中剩余可乐的体积。第三行包含 #cf_span[n] 个用空格分隔的整数 #cf_span[b1, b2, ..., bn]（#cf_span[ai ≤ bi ≤ 10^9]）— 每罐的容量。\n\n## Output\n\n如果可以将所有剩余可乐倒入 #cf_span[2] 个罐中，请输出 \"_YES_\"（不含引号）；否则输出 \"_NO_\"（不含引号）。你可以以任意大小写形式输出每个字母。\n\n[samples]\n\n## Note\n\n在第一个样例中，已有 #cf_span[2] 个罐，因此答案为 \"_YES_\"。","is_translate":true,"language":"Chinese"},{"statement_type":"Markdown","content":"Let $ n $ be the number of cans.  \nLet $ a_i $ be the remaining volume of cola in can $ i $, and $ b_i $ be its capacity, for $ i = 1, 2, \\dots, n $, with $ 0 \\leq a_i \\leq b_i $.  \n\nLet $ S = \\sum_{i=1}^n a_i $ be the total remaining volume of cola.\n\nDetermine whether there exist two distinct cans $ j $ and $ k $ (with $ 1 \\leq j < k \\leq n $) such that:  \n$$\na_j + a_k + \\sum_{\\substack{i=1 \\\\ i \\neq j,k}}^n a_i \\leq b_j + b_k\n$$  \nEquivalently:  \n$$\nS \\leq b_j + b_k\n$$\n\nThat is, determine if there exist two cans whose combined capacity is at least the total volume of cola.\n\n**Objective:**  \nCheck whether $ \\max_{1 \\leq j < k \\leq n} (b_j + b_k) \\geq S $.\n\nEquivalently, let $ b_{(1)} \\geq b_{(2)} \\geq \\dots \\geq b_{(n)} $ be the capacities sorted in non-increasing order.  \nThen the maximum possible sum of two capacities is $ b_{(1)} + b_{(2)} $.  \n\nThus, the condition simplifies to:  \n$$\nb_{(1)} + b_{(2)} \\geq S\n$$\n\n**Answer:**  \nYES if $ b_{(1)} + b_{(2)} \\geq \\sum_{i=1}^n a_i $, otherwise NO.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF892A","tags":["greedy","implementation"],"sample_group":[["2\n3 5\n3 6","YES"],["3\n6 8 9\n6 10 12","NO"],["5\n0 0 5 0 0\n1 1 8 10 5","YES"],["4\n4 1 0 3\n5 2 2 3","YES"]],"created_at":"2026-03-03 11:00:39"}}