【瞎搞】 UVALive 6530 Football

题目地址

题意:

给出N 个 比分 左边是我队 右边是对手

现在可以买G 个球  问最大可能的积分是多少


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <cmath>
using namespace std;
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#define cler(arr, val)    memset(arr, val, sizeof(arr))
#define FOR(i,a,b)  for(int i=a;i<=b;i++)
#define IN   freopen ("in.txt" , "r" , stdin);
#define OUT  freopen ("out.txt" , "w" , stdout);
typedef long long  LL;
const int MAXN = 102000;
const int MAXM = 6000010;
const int INF = 0x3f3f3f3f;
const int mod = 1e9;
const double eps= 1e-8;
#define lson l,m, rt<<1
#define rson m+1,r,rt<<1|1
struct node
{
    int x,y,z;
}a[MAXN];
bool cmp(node a,node b)
{
    return a.z<b.z;
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#endif
    int n,m;
    while(cin>>n>>m)
    {
        for(int i=0;i<n;i++)
        {
            scanf("%d%d",&a[i].x,&a[i].y);
            a[i].z=a[i].y-a[i].x;
        }
        sort(a,a+n,cmp);
        int x=0,fen=0;
        for(int i=0;i<n;i++)
        {
            if(a[i].z<0)
                fen+=3;
            else if(a[i].z==0&&m>0)
                m--,fen+=3;
            else if(a[i].z>0&&m>=a[i].z+1)
                m-=a[i].z+1;fen+=3;
            else if(a[i].z>0&&m>=a[i].z)
                m-=a[i].z,fen+=1;
            else if(a[i].z==0)
                fen++;
        }
        cout<<fen<<endl;
    }
    return 0;
}


posted @ 2014-11-01 14:44  kewowlo  阅读(155)  评论(0编辑  收藏  举报