The shortest time for Question statistics, you only need to determine the size of t + a1 + a2 + t * b1 + t * b2 + a1 * b2 and t + a1 + a2 + t * b1 + t * b2 + a2 * b1. arrange;
The score is sorted by a1 * b2 <a2 * b1.
[Cpp]
// File Name: hdu4442.cpp
// Author: bo_jwolf
// Created Time: Friday, January 1, May 24, 2013 11:42:02
# Include <iostream>
# Include <cstdio>
# Include <algorithm>
Using namespace std;
Const int maxn = 100005;
Const int MOD = 365*24*60*60;
Struct node
{
Int a, B;
} Edge [maxn];
Int cmp (node x, node y)
{
Return (long) x. a * y. B <(long) x. B * y.;
}
Int main ()
{
Int n;
Int I;
While (~ Scanf ("% d", & n)
{
For (I = 0; I <n; I ++)
{
Scanf ("% d", & edge [I]. a, & edge [I]. B );
}
Sort (edge, edge + n, cmp );
Long ans = 0;
Long t = 0;
For (I = 0; I <n; I ++)
{
Ans + = (edge [I]. a + t * edge [I]. B) % MOD;
Ans % = MOD;
T + = (edge [I]. a + t * edge [I]. B) % MOD;
T % = MOD;
}
Printf ("% I64d \ n", ans );
}
Return 0;
}
// File Name: hdu4442.cpp
// Author: bo_jwolf
// Created Time: Friday, January 1, May 24, 2013 11:42:02
# Include <iostream>
# Include <cstdio>
# Include <algorithm>
Using namespace std;
Const int maxn = 100005;
Const int MOD = 365*24*60*60;
Struct node
{
Int a, B;
} Edge [maxn];
Int cmp (node x, node y)
{
Return (long) x. a * y. B <(long) x. B * y.;
}
Int main ()
{
Int n;
Int I;
While (~ Scanf ("% d", & n)
{
For (I = 0; I <n; I ++)
{
Scanf ("% d", & edge [I]. a, & edge [I]. B );
}
Sort (edge, edge + n, cmp );
Long ans = 0;
Long t = 0;
For (I = 0; I <n; I ++)
{
Ans + = (edge [I]. a + t * edge [I]. B) % MOD;
Ans % = MOD;
T + = (edge [I]. a + t * edge [I]. B) % MOD;
T % = MOD;
}
Printf ("% I64d \ n", ans );
}
Return 0;
}