Solutions are presented as using the least memory and the fastest execution time. It also takes the top
10 most recent solutions from each language. If you want to limit to a specific index, click the
"Solved" button and go to that problem.
Problems
B"A known chef has prepared n dishes: the i -th dish consists of a_i grams of fish and b_i grams of meat. The banquet organizers estimate the balance of n dishes as follows. The balance is equal to the absolute value of the difference between the total mass of fish and the total mass of meat. Technically, the balance equals to <= ft| sum limits_{i=1}^n a_i - sum limits_{i=1}^n b_i right| . The smaller the balance, the better. In order to improve the balance, a taster was invited. He will eat exactly m grams of food from each dish. For each dish, the taster determines separately how much fish and how much meat he will eat. The only condition is that he should eat exactly m grams of each dish in total. Determine how much of what type of food the taster should eat from each dish so that the value of the balance is as minimal as possible. If there are several correct answers, you may choose any of them. The first line of input data contains an integer t ( 1 <= q t <= q 10^4 ) -- the number of the test cases. Each test case's description is preceded by a blank line. Next comes a line that contains integers n and m ( 1 <= q n <= q 2 cdot 10^5 ; 0 <= q m <= q 10^6 ). The next n lines describe dishes, the i -th of them contains a pair of integers a_i and b_i ( 0 <= q a_i, b_i <= 10^6 ) -- the masses of fish and meat in the i -th dish. It is guaranteed that it is possible to eat m grams of food from each dish. In other words, m <= q a_i+b_i for all i from 1 to n inclusive. The sum of all n values over all test cases in the test does not exceed 2 cdot 10^5 . For each test case, print on the first line the minimal balance value that can be achieved by eating exactly m grams of food from each dish. Then print n lines that describe a way to do this: the i -th line should contain two integers x_i"... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
134147985 |
Gassa |
G |
Nov. 2, 2021, 7:19 p.m. |
OK |
D |
TESTS |
10 |
218 |
12595200 |
|
|
134154355 |
Baraa_Armoush |
G |
Nov. 2, 2021, 9:06 p.m. |
OK |
GNU C++14 |
TESTS |
10 |
140 |
5120000 |
|
|
134153145 |
SampsonYW |
G |
Nov. 2, 2021, 8:43 p.m. |
OK |
GNU C++14 |
TESTS |
10 |
140 |
35225600 |
|
|
134177152 |
stoorz |
G |
Nov. 3, 2021, 5:36 a.m. |
OK |
GNU C++14 |
TESTS |
10 |
155 |
4300800 |
|
|
134161478 |
y0urs3lf |
G |
Nov. 3, 2021, 12:56 a.m. |
OK |
GNU C++14 |
TESTS |
10 |
155 |
5836800 |
|
|
134167402 |
AC-hunter |
G |
Nov. 3, 2021, 3:33 a.m. |
OK |
GNU C++14 |
TESTS |
10 |
156 |
9113600 |
|
|
134137792 |
Denisov |
G |
Nov. 2, 2021, 5:19 p.m. |
OK |
GNU C++14 |
TESTS |
10 |
171 |
4300800 |
|
|
134151406 |
Bedo_Sayed |
G |
Nov. 2, 2021, 8:14 p.m. |
OK |
GNU C++14 |
TESTS |
10 |
186 |
7475200 |
|
|
134145696 |
18o3 |
G |
Nov. 2, 2021, 6:47 p.m. |
OK |
GNU C++14 |
TESTS |
10 |
186 |
7475200 |
|
|
134141877 |
trungvthe130284 |
G |
Nov. 2, 2021, 6 p.m. |
OK |
GNU C++14 |
TESTS |
10 |
187 |
4608000 |
|
|
134133324 |
Fearless_cod |
G |
Nov. 2, 2021, 4:45 p.m. |
OK |
GNU C++14 |
TESTS |
10 |
187 |
5836800 |
|
|
134167711 |
spy20051623_2 |
G |
Nov. 3, 2021, 3:41 a.m. |
OK |
GNU C++17 |
TESTS |
10 |
139 |
2662400 |
|
|
134136887 |
acseekerwrj |
G |
Nov. 2, 2021, 5:11 p.m. |
OK |
GNU C++17 |
TESTS |
10 |
139 |
5120000 |
|
|
134133047 |
serotonin |
G |
Nov. 2, 2021, 4:43 p.m. |
OK |
GNU C++17 |
TESTS |
10 |
140 |
2662400 |
|
|
134162031 |
wxhzyr |
G |
Nov. 3, 2021, 1:12 a.m. |
OK |
GNU C++17 |
TESTS |
10 |
140 |
4300800 |
|
|
134136776 |
Ruki |
G |
Nov. 2, 2021, 5:10 p.m. |
OK |
GNU C++17 |
TESTS |
10 |
140 |
5836800 |
|
|
134127499 |
Penguin03 |
G |
Nov. 2, 2021, 4:28 p.m. |
OK |
GNU C++17 |
TESTS |
10 |
140 |
5836800 |
|
|
134160455 |
_Ruri_ |
G |
Nov. 3, 2021, 12:21 a.m. |
OK |
GNU C++17 |
TESTS |
10 |
140 |
7475200 |
|
|
134134083 |
luanfreitas5 |
G |
Nov. 2, 2021, 4:49 p.m. |
OK |
GNU C++17 |
TESTS |
10 |
140 |
9420800 |
|
|
134125194 |
Alchemist0 |
G |
Nov. 2, 2021, 4:23 p.m. |
OK |
GNU C++17 |
TESTS |
10 |
140 |
9420800 |
|
|
134135939 |
gumgood |
G |
Nov. 2, 2021, 5:02 p.m. |
OK |
GNU C++17 |
TESTS |
10 |
140 |
10649600 |
|
|
134172507 |
t3a |
G |
Nov. 3, 2021, 4:24 a.m. |
OK |
GNU C++17 (64) |
TESTS |
10 |
109 |
4403200 |
|
|
134142843 |
Blondie |
G |
Nov. 2, 2021, 6:10 p.m. |
OK |
GNU C++17 (64) |
TESTS |
10 |
109 |
5222400 |
|
|
134168737 |
sayan_244 |
G |
Nov. 3, 2021, 4:04 a.m. |
OK |
GNU C++17 (64) |
TESTS |
10 |
109 |
9216000 |
|
|
134126753 |
FedeNQ |
G |
Nov. 2, 2021, 4:27 p.m. |
OK |
GNU C++17 (64) |
TESTS |
10 |
109 |
9216000 |
|
|
134133239 |
ExplodingFreeze |
G |
Nov. 2, 2021, 4:44 p.m. |
OK |
GNU C++17 (64) |
TESTS |
10 |
109 |
13414400 |
|
|
134161727 |
I_francis |
G |
Nov. 3, 2021, 1:03 a.m. |
OK |
GNU C++17 (64) |
TESTS |
10 |
124 |
4403200 |
|
|
134127942 |
pikel_rik |
G |
Nov. 2, 2021, 4:29 p.m. |
OK |
GNU C++17 (64) |
TESTS |
10 |
124 |
4403200 |
|
|
134160788 |
froggyzhang |
G |
Nov. 3, 2021, 12:32 a.m. |
OK |
GNU C++17 (64) |
TESTS |
10 |
124 |
5222400 |
|
|
134176974 |
srinjoy_ray |
G |
Nov. 3, 2021, 5:34 a.m. |
OK |
GNU C++17 (64) |
TESTS |
10 |
124 |
6041600 |
|
|
134176983 |
mknayam |
G |
Nov. 3, 2021, 5:34 a.m. |
OK |
GNU C++17 (64) |
TESTS |
10 |
124 |
7577600 |
|
|
134132400 |
Brodicico |
G |
Nov. 2, 2021, 4:40 p.m. |
OK |
GNU C++20 (64) |
TESTS |
10 |
78 |
7680000 |
|
|
134164165 |
vanor |
G |
Nov. 3, 2021, 2:17 a.m. |
OK |
GNU C++20 (64) |
TESTS |
10 |
93 |
3686400 |
|
|
134139662 |
sserdoubleh |
G |
Nov. 2, 2021, 5:37 p.m. |
OK |
GNU C++20 (64) |
TESTS |
10 |
93 |
3686400 |
|
|
134175501 |
arnav2004 |
G |
Nov. 3, 2021, 5:13 a.m. |
OK |
GNU C++20 (64) |
TESTS |
10 |
93 |
4505600 |
|
|
134162513 |
ZENGJIE |
G |
Nov. 3, 2021, 1:28 a.m. |
OK |
GNU C++20 (64) |
TESTS |
10 |
93 |
4505600 |
|
|
134158257 |
definitelynotmee |
G |
Nov. 2, 2021, 10:57 p.m. |
OK |
GNU C++20 (64) |
TESTS |
10 |
93 |
4505600 |
|
|
134151366 |
Farhan132 |
G |
Nov. 2, 2021, 8:13 p.m. |
OK |
GNU C++20 (64) |
TESTS |
10 |
93 |
4505600 |
|
|
134147942 |
ivanzuki |
G |
Nov. 2, 2021, 7:18 p.m. |
OK |
GNU C++20 (64) |
TESTS |
10 |
93 |
4505600 |
|
|
134147909 |
ivanzuki |
G |
Nov. 2, 2021, 7:18 p.m. |
OK |
GNU C++20 (64) |
TESTS |
10 |
93 |
4505600 |
|
|
134139301 |
lost_boy20 |
G |
Nov. 2, 2021, 5:34 p.m. |
OK |
GNU C++20 (64) |
TESTS |
10 |
93 |
4505600 |
|
|
134173558 |
9.86960440109 |
G |
Nov. 3, 2021, 4:42 a.m. |
OK |
PyPy 3 |
TESTS |
10 |
514 |
50790400 |
|
|
134148891 |
hxu10 |
G |
Nov. 2, 2021, 7:33 p.m. |
OK |
PyPy 3 |
TESTS |
10 |
623 |
60620800 |
|
|
134130076 |
peakyfuckingblinder |
G |
Nov. 2, 2021, 4:33 p.m. |
OK |
PyPy 3 |
TESTS |
10 |
857 |
66764800 |
|
|
134167244 |
mkawa2 |
G |
Nov. 3, 2021, 3:29 a.m. |
OK |
PyPy 3 |
TESTS |
10 |
1107 |
48742400 |
|
|
134133338 |
giant-mammoth |
G |
Nov. 2, 2021, 4:45 p.m. |
OK |
PyPy 3-64 |
TESTS |
10 |
577 |
72499200 |
|
|
134144061 |
DanilaSysoev |
G |
Nov. 2, 2021, 6:26 p.m. |
OK |
PyPy 3-64 |
TESTS |
10 |
1934 |
81203200 |
|
|
remove filters
Back to search problems