733B Parade codeforces(水题)

#include<bits/stdc++.h>
using namespace std;
struct node
{
    int l;
    int r;
    int x;
    int num;
}arr[100005];
bool cmp(node x,node y)
{
    if(x.x<y.x)
        return true;
    return false;
}
int main()
{
    int n,a1=0,a2=0,num1=0,num2=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i].l>>arr[i].r;
        arr[i].x=arr[i].l-arr[i].r;
        arr[i].num=i;
        if(arr[i].x>=0)
        {
            a1+=arr[i].x;
            num1++;
        }
        else
        {
            a2+=arr[i].x;
            num2++;
        }
    }
    sort(arr+1,arr+n+1,cmp);
    if(num1==1||num2==1)
    {
        if(arr[1].x>=0)
        cout<<0<<endl;
        else if(num1==1)
        cout<<arr[n].num<<endl;
        else
        cout<<arr[1].num<<endl;
    }
    else if(a1>=abs(a2))
    {
        if(arr[1].x>=0)
            cout<<0<<endl;
        else
            cout<<arr[1].num<<endl;
    }
    else
    {
        node temp=arr[1];
        if(arr[n].x<=0)
            cout<<0<<endl;
        else
        {
            for(int i=2;i<=n;i++)
                if(arr[i].x>temp.x)
                temp=arr[i];
            cout<<temp.num<<endl;
        }
    }
    return 0;


}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值