Physical Examination |
---|
题意: 关于体检,有很多个项目需要去完成,每个项目都有一个a和b,表示如果一开始就选择这个项目,需要a秒能够完成;如果之后选择这个项目,每过一秒钟,就需要多b秒的排队时间。求一个最小的完成所有体检项目的时间。
题解: 贪心呗,一开始以为按照b从大到小排,先把排队时间增长快的项目完成,再去完成增长速度相同下完成时间少的项目。结果样例就出不来。所以才想到了把完成时间与排队时间结合起来比较。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 31536000;
int n;
struct node{
ll a, b;
friend bool operator<(const node &A, const node &B) {
if(A.a * B.b == A.b * B.a) return A.b > B.b;
return A.a * B.b < A.b * B.a;
}
} a[100000 + 10];
void run() {
ll ans = 0;
for(int i = 0; i < n; i++) {
scanf("%lld%lld", &a[i].a, &a[i].b);
}
sort(a, a + n);
for(int i = 0; i < n; i++) {
if(a[i].a == 0) continue;
ans = (ans + ans * a[i].b + a[i].a) % mod;
}
printf("%lld\n", ans);
}
int main() {
while(~scanf("%d", &n) && n) run();
return 0;
}