NC25142. [USACO 2006 Ope G]The Milk Queue
描述
输入描述
* Line 1: A single integer, N.
* Lines 2..1+N: Line i+1 contains two space-separated integers A(i) and B(i) for cow i.
输出描述
* Line 1: The minimum possible time it takes to milk all the cows, if we order them optimally.
示例1
输入:
3 2 2 7 4 3 5
输出:
16
C++ 解法, 执行用时: 11ms, 内存消耗: 628K, 提交时间: 2023-08-15 11:22:30
#include<bits/stdc++.h> using namespace std; int n, cnt, ans; struct cow { int a,b; }x[100001]; int cmp(cow o, cow p) { return min(o.a,p.b) < min(p.a,o.b); } int main() { scanf("%d", &n); for(int i=1,xx, yy;i<=n;i++) scanf("%d%d", &xx, &yy), x[i].a = xx, x[i].b = yy; sort(x+1, x+n+1, cmp); for(int i=1;i<=n;i++) cnt += x[i].a, ans = max(ans, cnt) + x[i].b; printf("%d", ans); }