hanhainebula's picture
Use descriptive task names for Search-SWE data
6713b1e verified
Raw History Blame Contribute Delete
21.4 kB
{"_id":"5898","text":"You are playing the following game. There are n points on a plane. They are the vertices of a regular n-polygon. Points are labeled with integer numbers from 1 to n. Each pair of distinct points is connected by a diagonal, which is colored in one of 26 colors. Points are denoted by lowercase English letters. There are three stones positioned on three distinct vertices. All stones are the same. With one move you can move the stone to another free vertex along some diagonal. The color of this diagonal must be the same as the color of the diagonal, connecting another two stones. \n\nYour goal is to move stones in such way that the only vertices occupied by stones are 1, 2 and 3. You must achieve such position using minimal number of moves. Write a program which plays this game in an optimal way.\n\n\n-----Input-----\n\nIn the first line there is one integer n (3 ≤ n ≤ 70) — the number of points. In the second line there are three space-separated integer from 1 to n — numbers of vertices, where stones are initially located.\n\nEach of the following n lines contains n symbols — the matrix denoting the colors of the diagonals. Colors are denoted by lowercase English letters. The symbol j of line i denotes the color of diagonal between points i and j. Matrix is symmetric, so j-th symbol of i-th line is equal to i-th symbol of j-th line. Main diagonal is filled with '*' symbols because there is no diagonal, connecting point to itself.\n\n\n-----Output-----\n\nIf there is no way to put stones on vertices 1, 2 and 3, print -1 on a single line. Otherwise, on the first line print minimal required number of moves and in the next lines print the description of each move, one move per line. To describe a move print two integers. The point from which to remove the stone, and the point to which move the stone. If there are several optimal solutions, print any of them.\n\n\n-----Examples-----\nInput\n4\n2 3 4\n*aba\na*ab\nba*b\nabb*\n\nOutput\n1\n4 1\n\nInput\n4\n2 3 4\n*abc\na*ab\nba*b\ncbb*\n\nOutput\n-1\n\n\n\n-----Note-----\n\nIn the first example we can move stone from point 4 to point 1 because this points are connected by the diagonal of color 'a' and the diagonal connection point 2 and 3, where the other stones are located, are connected by the diagonal of the same color. After that stones will be on the points 1, 2 and 3."}
{"_id":"2070","text":"Takahashi will take part in an eating contest. Teams of N members will compete in this contest, and Takahashi's team consists of N players numbered 1 through N from youngest to oldest. The consumption coefficient of Member i is A_i.\nIn the contest, N foods numbered 1 through N will be presented, and the difficulty of Food i is F_i. The details of the contest are as follows:\n - A team should assign one member to each food, and should not assign the same member to multiple foods.\n - It will take x \\times y seconds for a member to finish the food, where x is the consumption coefficient of the member and y is the difficulty of the dish.\n - The score of a team is the longest time it takes for an individual member to finish the food.\nBefore the contest, Takahashi's team decided to do some training. In one set of training, a member can reduce his/her consumption coefficient by 1, as long as it does not go below 0. However, for financial reasons, the N members can do at most K sets of training in total.\nWhat is the minimum possible score of the team, achieved by choosing the amounts of members' training and allocating the dishes optimally?\n\n-----Constraints-----\n - All values in input are integers.\n - 1 \\leq N \\leq 2 \\times 10^5\n - 0 \\leq K \\leq 10^{18}\n - 1 \\leq A_i \\leq 10^6\\ (1 \\leq i \\leq N)\n - 1 \\leq F_i \\leq 10^6\\ (1 \\leq i \\leq N)\n\n-----Input-----\nInput is given from Standard Input in the following format:\nN K\nA_1 A_2 ... A_N\nF_1 F_2 ... F_N\n\n-----Output-----\nPrint the minimum possible score of the team.\n\n-----Sample Input-----\n3 5\n4 2 1\n2 3 1\n\n-----Sample Output-----\n2\n\nThey can achieve the score of 2, as follows:\n - Member 1 does 4 sets of training and eats Food 2 in (4-4) \\times 3 = 0 seconds.\n - Member 2 does 1 set of training and eats Food 3 in (2-1) \\times 1 = 1 second.\n - Member 3 does 0 sets of training and eats Food 1 in (1-0) \\times 2 = 2 seconds.\nThey cannot achieve a score of less than 2, so the answer is 2."}
{"_id":"2901","text":"Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has n apartments that are numbered from 1 to n and are arranged in a row. Two apartments are adjacent if their indices differ by 1. Some of the apartments can already be inhabited, others are available for sale.\n\nMaxim often visits his neighbors, so apartment is good for him if it is available for sale and there is at least one already inhabited apartment adjacent to it. Maxim knows that there are exactly k already inhabited apartments, but he doesn't know their indices yet.\n\nFind out what could be the minimum possible and the maximum possible number of apartments that are good for Maxim.\n\n\n-----Input-----\n\nThe only line of the input contains two integers: n and k (1 ≤ n ≤ 10^9, 0 ≤ k ≤ n).\n\n\n-----Output-----\n\nPrint the minimum possible and the maximum possible number of apartments good for Maxim.\n\n\n-----Example-----\nInput\n6 3\n\nOutput\n1 3\n\n\n\n-----Note-----\n\nIn the sample test, the number of good apartments could be minimum possible if, for example, apartments with indices 1, 2 and 3 were inhabited. In this case only apartment 4 is good. The maximum possible number could be, for example, if apartments with indices 1, 3 and 5 were inhabited. In this case all other apartments: 2, 4 and 6 are good."}
{"_id":"1421","text":"Maksim walks on a Cartesian plane. Initially, he stands at the point $(0, 0)$ and in one move he can go to any of four adjacent points (left, right, up, down). For example, if Maksim is currently at the point $(0, 0)$, he can go to any of the following points in one move: $(1, 0)$; $(0, 1)$; $(-1, 0)$; $(0, -1)$. \n\nThere are also $n$ distinct key points at this plane. The $i$-th point is $p_i = (x_i, y_i)$. It is guaranteed that $0 \\le x_i$ and $0 \\le y_i$ and there is no key point $(0, 0)$.\n\nLet the first level points be such points that $max(x_i, y_i) = 1$, the second level points be such points that $max(x_i, y_i) = 2$ and so on. Maksim wants to visit all the key points. But he shouldn't visit points of level $i + 1$ if he does not visit all the points of level $i$. He starts visiting the points from the minimum level of point from the given set.\n\nThe distance between two points $(x_1, y_1)$ and $(x_2, y_2)$ is $|x_1 - x_2| + |y_1 - y_2|$ where $|v|$ is the absolute value of $v$.\n\nMaksim wants to visit all the key points in such a way that the total distance he walks will be minimum possible. Your task is to find this distance.\n\nIf you are Python programmer, consider using PyPy instead of Python when you submit your code.\n\n\n-----Input-----\n\nThe first line of the input contains one integer $n$ ($1 \\le n \\le 2 \\cdot 10^5$) — the number of key points.\n\nEach of the next $n$ lines contains two integers $x_i$, $y_i$ ($0 \\le x_i, y_i \\le 10^9$) — $x$-coordinate of the key point $p_i$ and $y$-coordinate of the key point $p_i$. It is guaranteed that all the points are distinct and the point $(0, 0)$ is not in this set.\n\n\n-----Output-----\n\nPrint one integer — the minimum possible total distance Maksim has to travel if he needs to visit all key points in a way described above.\n\n\n-----Examples-----\nInput\n8\n2 2\n1 4\n2 3\n3 1\n3 4\n1 1\n4 3\n1 2\n\nOutput\n15\n\nInput\n5\n2 1\n1 0\n2 0\n3 2\n0 3\n\nOutput\n9\n\n\n\n-----Note-----\n\nThe picture corresponding to the first example: [Image]\n\nThere is one of the possible answers of length $15$.\n\nThe picture corresponding to the second example: [Image]\n\nThere is one of the possible answers of length $9$."}
{"_id":"15901","text":"You are given an array $a$ consisting of $n$ integers.\n\nIn one move, you can choose two indices $1 \\le i, j \\le n$ such that $i \\ne j$ and set $a_i := a_j$. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose $i$ and $j$ and replace $a_i$ with $a_j$).\n\nYour task is to say if it is possible to obtain an array with an odd (not divisible by $2$) sum of elements.\n\nYou have to answer $t$ independent test cases.\n\n\n-----Input-----\n\nThe first line of the input contains one integer $t$ ($1 \\le t \\le 2000$) — the number of test cases.\n\nThe next $2t$ lines describe test cases. The first line of the test case contains one integer $n$ ($1 \\le n \\le 2000$) — the number of elements in $a$. The second line of the test case contains $n$ integers $a_1, a_2, \\dots, a_n$ ($1 \\le a_i \\le 2000$), where $a_i$ is the $i$-th element of $a$.\n\nIt is guaranteed that the sum of $n$ over all test cases does not exceed $2000$ ($\\sum n \\le 2000$).\n\n\n-----Output-----\n\nFor each test case, print the answer on it — \"YES\" (without quotes) if it is possible to obtain the array with an odd sum of elements, and \"NO\" otherwise.\n\n\n-----Example-----\nInput\n5\n2\n2 3\n4\n2 2 8 8\n3\n3 3 3\n4\n5 5 5 5\n4\n1 1 1 1\n\nOutput\nYES\nNO\nYES\nNO\nNO"}
{"_id":"7181","text":"Devu being a small kid, likes to play a lot, but he only likes to play with arrays. While playing he came up with an interesting question which he could not solve, can you please solve it for him?\n\nGiven an array consisting of distinct integers. Is it possible to partition the whole array into k disjoint non-empty parts such that p of the parts have even sum (each of them must have even sum) and remaining k - p have odd sum? (note that parts need not to be continuous).\n\nIf it is possible to partition the array, also give any possible way of valid partitioning.\n\n\n-----Input-----\n\nThe first line will contain three space separated integers n, k, p (1 ≤ k ≤ n ≤ 10^5; 0 ≤ p ≤ k). The next line will contain n space-separated distinct integers representing the content of array a: a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).\n\n\n-----Output-----\n\nIn the first line print \"YES\" (without the quotes) if it is possible to partition the array in the required way. Otherwise print \"NO\" (without the quotes).\n\nIf the required partition exists, print k lines after the first line. The i^{th} of them should contain the content of the i^{th} part. Print the content of the part in the line in the following way: firstly print the number of elements of the part, then print all the elements of the part in arbitrary order. There must be exactly p parts with even sum, each of the remaining k - p parts must have odd sum.\n\nAs there can be multiple partitions, you are allowed to print any valid partition.\n\n\n-----Examples-----\nInput\n5 5 3\n2 6 10 5 9\n\nOutput\nYES\n1 9\n1 5\n1 10\n1 6\n1 2\n\nInput\n5 5 3\n7 14 2 9 5\n\nOutput\nNO\n\nInput\n5 3 1\n1 2 3 7 5\n\nOutput\nYES\n3 5 1 3\n1 7\n1 2"}
{"_id":"8251","text":"Not so long ago the Codecraft-17 contest was held on Codeforces. The top 25 participants, and additionally random 25 participants out of those who got into top 500, will receive a Codeforces T-shirt.\n\nUnfortunately, you didn't manage to get into top 25, but you got into top 500, taking place p.\n\nNow the elimination round of 8VC Venture Cup 2017 is being held. It has been announced that the Codecraft-17 T-shirt winners will be chosen as follows. Let s be the number of points of the winner of the elimination round of 8VC Venture Cup 2017. Then the following pseudocode will be executed: \n\ni := (s div 50) mod 475\n\nrepeat 25 times:\n\n i := (i * 96 + 42) mod 475\n\n print (26 + i)\n\n\n\nHere \"div\" is the integer division operator, \"mod\" is the modulo (the remainder of division) operator.\n\nAs the result of pseudocode execution, 25 integers between 26 and 500, inclusive, will be printed. These will be the numbers of places of the participants who get the Codecraft-17 T-shirts. It is guaranteed that the 25 printed integers will be pairwise distinct for any value of s.\n\nYou're in the lead of the elimination round of 8VC Venture Cup 2017, having x points. You believe that having at least y points in the current round will be enough for victory.\n\nTo change your final score, you can make any number of successful and unsuccessful hacks. A successful hack brings you 100 points, an unsuccessful one takes 50 points from you. It's difficult to do successful hacks, though.\n\nYou want to win the current round and, at the same time, ensure getting a Codecraft-17 T-shirt. What is the smallest number of successful hacks you have to do to achieve that?\n\n\n-----Input-----\n\nThe only line contains three integers p, x and y (26 ≤ p ≤ 500; 1 ≤ y ≤ x ≤ 20000) — your place in Codecraft-17, your current score in the elimination round of 8VC Venture Cup 2017, and the smallest number of points you consider sufficient for winning the current round.\n\n\n-----Output-----\n\nOutput a single integer — the smallest number of successful hacks you have to do in order to both win the elimination round of 8VC Venture Cup 2017 and ensure getting a Codecraft-17 T-shirt.\n\nIt's guaranteed that your goal is achievable for any valid input data.\n\n\n-----Examples-----\nInput\n239 10880 9889\n\nOutput\n0\n\nInput\n26 7258 6123\n\nOutput\n2\n\nInput\n493 8000 8000\n\nOutput\n24\n\nInput\n101 6800 6500\n\nOutput\n0\n\nInput\n329 19913 19900\n\nOutput\n8\n\n\n\n-----Note-----\n\nIn the first example, there is no need to do any hacks since 10880 points already bring the T-shirt to the 239-th place of Codecraft-17 (that is, you). In this case, according to the pseudocode, the T-shirts will be given to the participants at the following places: \n\n475 422 84 411 453 210 157 294 146 188 420 367 29 356 398 155 102 239 91 133 365 312 449 301 343\n\n\n\nIn the second example, you have to do two successful and one unsuccessful hack to make your score equal to 7408.\n\nIn the third example, you need to do as many as 24 successful hacks to make your score equal to 10400.\n\nIn the fourth example, it's sufficient to do 6 unsuccessful hacks (and no successful ones) to make your score equal to 6500, which is just enough for winning the current round and also getting the T-shirt."}
{"_id":"7643","text":"An array $b$ is called to be a subarray of $a$ if it forms a continuous subsequence of $a$, that is, if it is equal to $a_l$, $a_{l + 1}$, $\\ldots$, $a_r$ for some $l, r$.\n\nSuppose $m$ is some known constant. For any array, having $m$ or more elements, let's define it's beauty as the sum of $m$ largest elements of that array. For example: For array $x = [4, 3, 1, 5, 2]$ and $m = 3$, the $3$ largest elements of $x$ are $5$, $4$ and $3$, so the beauty of $x$ is $5 + 4 + 3 = 12$.\n\n For array $x = [10, 10, 10]$ and $m = 2$, the beauty of $x$ is $10 + 10 = 20$.\n\nYou are given an array $a_1, a_2, \\ldots, a_n$, the value of the said constant $m$ and an integer $k$. Your need to split the array $a$ into exactly $k$ subarrays such that:\n\n Each element from $a$ belongs to exactly one subarray.\n\n Each subarray has at least $m$ elements.\n\n The sum of all beauties of $k$ subarrays is maximum possible.\n\n\n-----Input-----\n\nThe first line contains three integers $n$, $m$ and $k$ ($2 \\le n \\le 2 \\cdot 10^5$, $1 \\le m$, $2 \\le k$, $m \\cdot k \\le n$) — the number of elements in $a$, the constant $m$ in the definition of beauty and the number of subarrays to split to.\n\nThe second line contains $n$ integers $a_1, a_2, \\ldots, a_n$ ($-10^9 \\le a_i \\le 10^9$).\n\n\n-----Output-----\n\nIn the first line, print the maximum possible sum of the beauties of the subarrays in the optimal partition.\n\nIn the second line, print $k-1$ integers $p_1, p_2, \\ldots, p_{k-1}$ ($1 \\le p_1 < p_2 < \\ldots < p_{k-1} < n$) representing the partition of the array, in which:\n\n\n\n All elements with indices from $1$ to $p_1$ belong to the first subarray.\n\n All elements with indices from $p_1 + 1$ to $p_2$ belong to the second subarray.\n\n $\\ldots$.\n\n All elements with indices from $p_{k-1} + 1$ to $n$ belong to the last, $k$-th subarray.\n\nIf there are several optimal partitions, print any of them.\n\n\n-----Examples-----\nInput\n9 2 3\n5 2 5 2 4 1 1 3 2\n\nOutput\n21\n3 5 \nInput\n6 1 4\n4 1 3 2 2 3\n\nOutput\n12\n1 3 5 \nInput\n2 1 2\n-1000000000 1000000000\n\nOutput\n0\n1 \n\n\n-----Note-----\n\nIn the first example, one of the optimal partitions is $[5, 2, 5]$, $[2, 4]$, $[1, 1, 3, 2]$.\n\n The beauty of the subarray $[5, 2, 5]$ is $5 + 5 = 10$. The beauty of the subarray $[2, 4]$ is $2 + 4 = 6$. The beauty of the subarray $[1, 1, 3, 2]$ is $3 + 2 = 5$. \n\nThe sum of their beauties is $10 + 6 + 5 = 21$.\n\nIn the second example, one optimal partition is $[4]$, $[1, 3]$, $[2, 2]$, $[3]$."}
{"_id":"6128","text":"There are N infants registered in AtCoder, numbered 1 to N, and 2\\times 10^5 kindergartens, numbered 1 to 2\\times 10^5.\nInfant i has a rating of A_i and initially belongs to Kindergarten B_i.\nFrom now on, Q transfers will happen.\nAfter the j-th transfer, Infant C_j will belong to Kindergarten D_j.\nHere, we define the evenness as follows. For each kindergarten with one or more infants registered in AtCoder, let us find the highest rating of an infant in the kindergarten. The evenness is then defined as the lowest among those ratings.\nFor each of the Q transfers, find the evenness just after the transfer.\n\n-----Constraints-----\n - 1 \\leq N,Q \\leq 2 \\times 10^5\n - 1 \\leq A_i \\leq 10^9\n - 1 \\leq C_j \\leq N\n - 1 \\leq B_i,D_j \\leq 2 \\times 10^5\n - All values in input are integers.\n - In the j-th transfer, Infant C_j changes the kindergarten it belongs to.\n\n-----Input-----\nInput is given from Standard Input in the following format:\nN Q\nA_1 B_1\nA_2 B_2\n:\nA_N B_N\nC_1 D_1\nC_2 D_2\n:\nC_Q D_Q\n\n-----Output-----\nPrint Q lines.\nThe j-th line should contain the evenness just after the j-th transfer.\n\n-----Sample Input-----\n6 3\n8 1\n6 2\n9 3\n1 1\n2 2\n1 3\n4 3\n2 1\n1 2\n\n-----Sample Output-----\n6\n2\n6\n\nInitially, Infant 1, 4 belongs to Kindergarten 1, Infant 2, 5 belongs to Kindergarten 2, and Infant 3, 6 belongs to Kindergarten 3.\nAfter the 1-st transfer that makes Infant 4 belong to Kindergarten 3, Infant 1 belongs to Kindergarten 1, Infant 2, 5 belong to Kindergarten 2, and Infant 3, 4, 6 belong to Kindergarten 3. The highest ratings of an infant in Kindergarten 1, 2, 3 are 8, 6, 9, respectively. The lowest among them is 6, so the 1-st line in the output should contain 6.\nAfter the 2-nd transfer that makes Infant 2 belong to Kindergarten 1, Infant 1, 2 belong to Kindergarten 1, Infant 5 belongs to Kindergarten 2, and Infant 3, 4, 6 belong to Kindergarten 3. The highest ratings of an infant in Kindergarten 1, 2, 3 are 8, 2, 9, respectively. The lowest among them is 2, so the 2-nd line in the output should contain 2.\nAfter the 3-rd transfer that makes Infant 1 belong to Kindergarten 2, Infant 2 belongs to Kindergarten 1, Infant 1, 5 belong to Kindergarten 2, and Infant 3, 4, 6 belong to Kindergarten 3. The highest ratings of an infant in Kindergarten 1, 2, 3 are 6, 8, 9, respectively. The lowest among them is 6, so the 3-rd line in the output should contain 6."}
{"_id":"3139","text":"Petya has a simple graph (that is, a graph without loops or multiple edges) consisting of $n$ vertices and $m$ edges.\n\nThe weight of the $i$-th vertex is $a_i$.\n\nThe weight of the $i$-th edge is $w_i$.\n\nA subgraph of a graph is some set of the graph vertices and some set of the graph edges. The set of edges must meet the condition: both ends of each edge from the set must belong to the chosen set of vertices. \n\nThe weight of a subgraph is the sum of the weights of its edges, minus the sum of the weights of its vertices. You need to find the maximum weight of subgraph of given graph. The given graph does not contain loops and multiple edges.\n\n\n-----Input-----\n\nThe first line contains two numbers $n$ and $m$ ($1 \\le n \\le 10^3, 0 \\le m \\le 10^3$) - the number of vertices and edges in the graph, respectively.\n\nThe next line contains $n$ integers $a_1, a_2, \\dots, a_n$ ($1 \\le a_i \\le 10^9$) - the weights of the vertices of the graph.\n\nThe following $m$ lines contain edges: the $i$-e edge is defined by a triple of integers $v_i, u_i, w_i$ ($1 \\le v_i, u_i \\le n, 1 \\le w_i \\le 10^9, v_i \\neq u_i$). This triple means that between the vertices $v_i$ and $u_i$ there is an edge of weight $w_i$. It is guaranteed that the graph does not contain loops and multiple edges.\n\n\n-----Output-----\n\nPrint one integer — the maximum weight of the subgraph of the given graph.\n\n\n-----Examples-----\nInput\n4 5\n1 5 2 2\n1 3 4\n1 4 4\n3 4 5\n3 2 2\n4 2 2\n\nOutput\n8\n\nInput\n3 3\n9 7 8\n1 2 1\n2 3 2\n1 3 3\n\nOutput\n0\n\n\n\n-----Note-----\n\nIn the first test example, the optimal subgraph consists of the vertices ${1, 3, 4}$ and has weight $4 + 4 + 5 - (1 + 2 + 2) = 8$. In the second test case, the optimal subgraph is empty."}