CF1841F.Monocarp and a Strategic Game

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Monocarp plays a strategic computer game in which he develops a city. The city is inhabited by creatures of four different races — humans, elves, orcs, and dwarves.

Each inhabitant of the city has a happiness value, which is an integer. It depends on how many creatures of different races inhabit the city. Specifically, the happiness of each inhabitant is 00 by default; it increases by 11 for each other creature of the same race and decreases by 11 for each creature of a hostile race. Humans are hostile to orcs (and vice versa), and elves are hostile to dwarves (and vice versa).

At the beginning of the game, Monocarp's city is not inhabited by anyone. During the game, nn groups of creatures will come to his city, wishing to settle there. The ii-th group consists of aia_i humans, bib_i orcs, cic_i elves, and did_i dwarves. Each time, Monocarp can either accept the entire group of creatures into the city, or reject the entire group.

The game calculates Monocarp's score according to the following formula: m+km + k, where mm is the number of inhabitants in the city, and kk is the sum of the happiness values of all creatures in the city.

Help Monocarp earn the maximum possible number of points by the end of the game!

Monocarp 正在玩一款策略类电脑游戏,他在游戏中建设一座城市。这座城市居住着四个不同种族的生物:人类(humans)、精灵(elves)、兽人(orcs)和矮人(dwarves)。

城市中每个居民都有一个幸福值(happiness value),该值为一个整数,其大小取决于城市中各种族生物的数量。具体而言,每位居民的幸福值默认为 00;对于每一名与其同种族的其他居民,其幸福值增加 11;而对于每一名属于敌对种族的居民,其幸福值减少 11。人类与兽人互为敌对(反之亦然),精灵与矮人互为敌对(反之亦然)。

游戏开始时,Monocarp 的城市中没有任何居民。在游戏过程中,将有 nn 批生物陆续来到他的城市,希望在此定居。第 ii 批生物包含 aia_i 名人类、bib_i 名兽人、cic_i 名精灵和 did_i 名矮人。每次,Monocarp 可以选择完全接纳整批生物进入城市,或完全拒绝整批生物。

游戏根据如下公式计算 Monocarp 的得分:m+km + k,其中 mm 是城市中居民的总人数,kk 是城市中所有生物幸福值的总和。

请帮助 Monocarp 在游戏结束时获得尽可能高的分数!

输入格式

The first line contains an integer nn (1≤n≤3⋅1051 \leq n \leq 3 \cdot 10^{5}) — the number of groups of creatures that come to Monocarp's city.

Then nn lines follow. The ii-th of them contains four integers aia_i, bib_i, cic_i, and did_i (0≤ai,bi,ci,di≤1090 \leq a_i, b_i, c_i, d_i \leq 10^{9}) — the number of humans, orcs, elves and dwarves (respectively) in the ii-th group.

第一行包含一个整数 nn(1≤n≤3⋅1051 \leq n \leq 3 \cdot 10^{5})—— 表示来到 Monocarp 城市的生物群体数量。

接下来是 nn 行。其中第 ii 行包含四个整数 aia_i、bib_i、cic_i 和 did_i(0≤ai,bi,ci,di≤1090 \leq a_i, b_i, c_i, d_i \leq 10^{9})—— 分别表示第 ii 组中人类、兽人、精灵和矮人的数量。

输出格式

Output a single number — the maximum score Monocarp can have by the end of the game. Your answer will be considered correct if its absolute or relative error does not exceed 10−910^{-9}. That is, if your answer is aa, and the jury's answer is bb, then the solution will be accepted if ∣a−b∣max⁡(1,∣b∣)≤10−9\frac{|a-b|}{\max(1,|b|)} \le 10^{-9}.

Note that the correct answer is always an integer, but sometimes it doesn't fit in 6464-bit integer types, so you are allowed to print it as a non-integer number.

输出一个整数——Monocarp 在游戏结束时所能获得的最高得分。若你的答案绝对误差或相对误差不超过 10−910^{-9},则视为正确。即:若你的答案为 aa,而评测机的答案为 bb,当且仅当 ∣a−b∣max⁡(1,∣b∣)≤10−9\frac{|a-b|}{\max(1,|b|)} \le 10^{-9} 时,该解法被接受。

注意:正确答案恒为整数,但有时其值无法用 64 位整数类型表示,因此允许你以非整数形式输出该答案。

输入输出样例

  • 输入#1

    5
    0 0 1 0
    1 3 4 2
    2 5 1 2
    4 5 4 3
    1 4 4 5

    输出#1

    85
  • 输入#2

    4
    3 3 1 5
    5 1 5 3
    4 4 4 1
    1 3 4 4

    输出#2

    41

说明/提示

In the first example, the best course of action is to accept all of the groups.

In the second example, the best course of action is to accept the groups 22 and 33, and decline the groups 11 and 44.

在第一个例子中,最优策略是接受所有组。

在第二个例子中,最优策略是接受第 22 组和第 33 组,拒绝第 11 组和第 44 组。

输入解题思路,AI测评打分。不知道怎么写?

首页