zoukankan      html  css  js  c++  java
  • Sobytiynyy Proyekt Casino Gym

    传送门:

    http://codeforces.com/gym/102299/problem/I

    Sobytiynyy Proyekt Casino is located in San Petersburg, one of the most beautiful cities in Russia, known (besides being where ITMO is located) by its delightful Hermitage Museum. The casino's owner, a former ICPC contestant who never made it to the world finals, is creating a new game (as the traditional games are not appreciated there...) and he wants revenge on his fellow competitors, by punishing players who are trying to play his game optimally.

    In each round, the players get a pair of integers (p,f)(p,f), where p>0p>0. The player gets (p) rubles and he or she may decide to leave the game by paying (f) rubles (or receiving (-f) rubles, if (f) is negative). Depending on how they play, players may end the game while owing money...

    Note also that if the player reaches the last pair, he is forced to pay (f_N).

    Help the casino's owner by finding an ordering of the (N) pairs which minimize the gains from a player who plays optimally. Your code must print how much the player would earn if she played in the ordering of pairs that minimizes her gain.

    Input

    You should read the number (N) of pairs in the first line of input.

    After this (N) lines will follow, each with two numbers separated by a space, pp and ff.

    Constraints

    • 1N1051≤N≤105
    • 0pi1090≤pi≤109 for all ii
    • 109fi109−109≤fi≤109 for all ii

    Output

    Print a single integer: how much an optimal player would gain in an ordering of pairs that minimizes her gain.

    Examples

    Input
    3
    1 2
    3 3
    2 1
    
    Output
    3
    
    Input
    1
    1 -2
    
    Output
    3
    
    Input
    2
    0 1
    3 4
    
    Output
    -1
    

    Note

    Let us analyze the possible permutations of the sequence of pairs for the first case:

    Both permutations (1,2),(3,3),(2,1)(1,2),(3,3),(2,1) and (3,3),(1,2),(2,1)(3,3),(1,2),(2,1) award 5 to an optimal player. The permutations (2,1),(3,3),(1,2)(2,1),(3,3),(1,2) and (3,3),(2,1),(1,2)(3,3),(2,1),(1,2) award at most 4.

    Finally, the permutations (1,2),(2,1),(3,3)(1,2),(2,1),(3,3) and (2,1),(1,2),(3,3)(2,1),(1,2),(3,3) award at most 3 to a player. Thus, 3 is the smallest value that an optimal player can get in this game.

     1 #include <bits/stdc++.h>
     2 
     3 using namespace std;
     4 
     5 struct node
     6 {
     7     long long l ,r;
     8 }str[100005];
     9 
    10 bool cmp(node a, node b)
    11 {
    12     return a.r<b.r;
    13 }
    14 
    15 int main()
    16 {
    17     long long n;
    18     scanf("%lld", &n);
    19     for(long long i=0;i<n;i++)
    20     {
    21         scanf("%lld %lld", &str[i].l, &str[i].r);
    22     }
    23     sort(str, str+n, cmp);
    24     long long tot = str[0].l;
    25     long long maxx = tot - str[0].r;
    26     
    27     for(long long i=1;i<n;i++)
    28     {
    29         tot += str[i].l;
    30         maxx = max(maxx, tot-str[i].r);
    31     }
    32     printf("%lld
    ", maxx);
    33     return 0;
    34 }
  • 相关阅读:
    再学 GDI+[91]: TGPImage(11) 转灰度图像
    再学 GDI+[90]: TGPImage(10) 获取图像的调色板信息
    给 Memo 排序的函数
    再学 GDI+[97]: TGPImage(17) 获取 GDI+ 所支持的可编码、可解码的图像格式
    再学 GDI+[94]: TGPImage(14) 增减图像的红、绿、蓝三色的成分
    上周热点回顾(10.2611.1)
    博客园上海俱乐部Windows 7社区发布活动的奖品
    顶吧!顶出今日头条
    博客园电子期刊2009年10月刊发布啦
    对于近期社区问题的一点想法
  • 原文地址:https://www.cnblogs.com/0xiaoyu/p/11391102.html
Copyright © 2011-2022 走看看