传送门

题目大意:

n头牛,上山时间为u(i),下山为d(i).

要求每一时刻最多只有一头牛上山,一头牛下山。

问每头牛都上下山后花费最少时间。

题解:贪心

推了推样例,发现上山时间一定,那找个下山最快

的当最后一头山上的牛。

 

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
#define N 25009
using namespace std;

int n;

LL ans;
int hh=12345677;

struct Cows{
    int u,d;
}c[N];

bool cmp(Cows a,Cows b){
    return a.u<b.u;
}

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&c[i].u,&c[i].d);
        ans+=c[i].u;hh=min(hh,c[i].d);
    }
    cout<<ans+hh;
    return 0;
}
70骗分

相关文章: