CF730E.Award Ceremony

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

All-Berland programming contest comes to an end. In total, n teams participated in it. Like in ACM-ICPC, current results stopped refreshing one hour before the contest ends. So at the Award Ceremony, results are partially known. For each team the value a__i is given — the number of points the i-th team has earned before the last hour of the contest. Besides that, the Jury has evaluated all submissions sent during the last hour and knows values d__i — the number of points earned by the i-th team during the last hour (these values can be negative, which means that a team can lose points).

Before the contest, each team got unique id from 1 to n. According to the contest rules, a team with more points takes a higher place. If two or more teams have equal number of points, the team with lower id will take the higher place. So no two teams can share the same place.

The Award Ceremony proceeds in the following way. At the beginning of the ceremony, a large screen shows the results for the time moment "one hour before the end", which means that the i-th team has a__i points. Then the Jury unfreezes results of the teams one by one in some order. When result of the j-th team is unfrozen, its score changes from a__j to a__j + d__j. At this time the table of results is modified and the place of the team can change. The unfreezing of the j-th team is followed by the applause from the audience with duration of |x__j - y__j| seconds, where x__j is the place of the j-th team before unfreezing and y__j is the place right after the unfreezing. For example, if the team does not change the place, there is no applause from the audience. As you can see, during the Award Ceremony, each team will be unfrozen exactly once.

Your task is to find such an order to unfreeze all the teams that the total duration of applause is maximum possible.

全贝尔兰编程竞赛即将结束。总共有 nn 支队伍参赛。与 ACM-ICPC 类似,实时排行榜在比赛结束前一小时停止刷新。因此,在颁奖典礼上,结果仅部分已知。对每支队伍 ii,给定一个值 aia_i —— 即第 ii 支队伍在比赛最后 1 小时之前所获得的分数。此外,裁判组已评审完所有在最后 1 小时内提交的程序,并得知了各队在该时段内获得的分数 did_i(这些值可为负数,即某支队伍可能在此期间被扣分)。

比赛开始前,每支队伍被分配了一个从 11 到 nn 的唯一编号(ID)。根据比赛规则,总分更高的队伍名次更高;若两支或多支队伍总分相同,则 ID 较小的队伍名次更高。因此,不存在名次并列的情况。

颁奖典礼按如下方式进行:典礼开始时,大屏幕显示“距比赛结束还剩 1 小时”时刻的成绩,即第 ii 支队伍当前得分为 aia_i。随后,裁判组按某种顺序依次“解冻”各支队伍的成绩。当第 jj 支队伍的成绩被解冻时,其得分由 aja_j 变为 aj+dja_j + d_j。此时成绩榜随之更新,该队的名次也可能发生变化。第 jj 支队伍解冻后,观众将为其报以持续时间为 ∣xj−yj∣|x_j - y_j| 秒的掌声,其中 xjx_j 是该队解冻前的名次,yjy_j 是解冻后的名次。例如,若该队名次未发生变化,则观众不鼓掌。如你所见,在整个颁奖典礼中,每支队伍恰好被解冻一次。

你的任务是找出一种解冻所有队伍的顺序,使得观众总掌声持续时间最大化。

输入格式

The first line of the input file contains a single integer n (1 ≤ n ≤ 100) — the number of teams.

Each of the next n lines contains two integers a__i and d__i (1 ≤ a__i ≤ 100,  - 100 ≤ d__i ≤ 100) — the number of points the i-th team has earned before the last hour of the contest and the number of points earned by this team during the last hour. It is possible that after unfreezing a team will have a negative score.

输入文件的第一行包含一个整数 nn(1≤n≤1001 \leq n \leq 100)—— 表示队伍的数量。

接下来的 nn 行中,每行包含两个整数 aia_i 和 did_i(1≤ai≤1001 \leq a_i \leq 100,−100≤di≤100-100 \leq d_i \leq 100)—— 分别表示第 ii 支队伍在解冻前(即比赛最后一小时之前)所获得的分数,以及该队在最后一小时内获得的分数。解冻后,某支队伍的总分可能为负数。

输出格式

Print the only integer — maximal total applause duration in seconds if the Jury can choose any order of the teams to unfreeze.

输出唯一的整数——若裁判组可以任意选择队伍解冻顺序,所能获得的最大总鼓掌时长(单位:秒)。

输入输出样例

  • 输入#1

    4
    17 -14
    52 -5
    1 52
    6 0

    输出#1

    4
  • 输入#2

    5
    4 5
    3 2
    5 -3
    6 -2
    4 3

    输出#2

    14

说明/提示

In the first example the initial standings are:

  1. Team 2, 52 points
  2. Team 1, 17 points
  3. Team 4, 6 points
  4. Team 3, 1 point

Here any order of unfreezing the teams leads to 4 seconds of applause in total. For example, let's unfreeze teams in their order from the Team 1 to the Team 4.

After the Team 1 became unfrozen the standings are:

  1. Team 2, 52 points
  2. Team 4, 6 points
  3. Team 1, 3 points
  4. Team 3, 1 point

So there is 1 second of applause, because the difference between old and new places |2 - 3| = 1.

After the Team 2 became unfrozen the standings are:

  1. Team 2, 47 points
  2. Team 4, 6 points
  3. Team 1, 3 points
  4. Team 3, 1 point

The place of the Team 2 has not changed, so no applause during unfreezing.

After the Team 3 became unfrozen the standings are:

  1. Team 3, 53 point
  2. Team 2, 47 points
  3. Team 4, 6 points
  4. Team 1, 3 points

The place of the Team 3 has changed from 4 to 1, so the duration of applause is |4 - 1| = 3.

The unfreezing of the Team 4 has not changed any place because _d_4 = 0.

Therefore, the total duration of applause is 1 + 0 + 3 + 0 = 4 seconds.

在第一个例子中,初始排名如下:

  1. 队伍 2,52 分
  2. 队伍 1,17 分
  3. 队伍 4,6 分
  4. 队伍 3,1 分

此时,无论以何种顺序解冻队伍,总掌声持续时间为 4 秒。例如,我们按队伍 1 到队伍 4 的顺序依次解冻各支队伍。

队伍 1 解冻后,排名变为:

  1. 队伍 2,52 分
  2. 队伍 4,6 分
  3. 队伍 1,3 分
  4. 队伍 3,1 分

因此产生 1 秒掌声,因为其名次变化量为 ∣2 − 3∣ = 1|2 - 3| = 1。

队伍 2 解冻后,排名变为:

  1. 队伍 2,47 分
  2. 队伍 4,6 分
  3. 队伍 1,3 分
  4. 队伍 3,1 分

队伍 2 的名次未发生变化,因此解冻过程中无掌声。

队伍 3 解冻后,排名变为:

  1. 队伍 3,53 分
  2. 队伍 2,47 分
  3. 队伍 4,6 分
  4. 队伍 1,3 分

队伍 3 的名次由第 4 名变为第 1 名,因此掌声持续时间为 ∣4 − 1∣ = 3|4 - 1| = 3。

由于 d4 = 0d_4 = 0,队伍 4 解冻后未引起任何名次变化。

因此,总掌声持续时间为 1 + 0 + 3 + 0 = 41 + 0 + 3 + 0 = 4 秒。

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

首页