Greedy, just like King NOIP2012 game, consider the location of the two adjacent problems, the other questions are not affected, and then look at the two questions order which is more excellent. Sort.
WA took one reason: although ans opened a long long, but in this sentence: ANS+=TIME*A[I].K, you still need to precede the time (int type) with (LL) for type casting.
1 /**************************************************************2 problem:38503 User:programmingape4 language:c++5 result:accepted6 time:64 Ms7 memory:2052 KB8 ****************************************************************/9 Ten //Bzoj 3850 One#include <cstdio> A#include <cstring> -#include <cstdlib> -#include <iostream> the#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) - #defineF (i,j,n) for (int i=j;i<=n;++i) - #defineD (i,j,n) for (int i=j;i>=n;--i) + using namespacestd; - Const intn=100086; +typedefLong LongLL; A structnode{ at intt,k; - BOOL operator< (Constnode& b)Const { - returnt*k+ (t+b.t) *B.K < b.t*b.k+ (t+b.t) *K; - } - }a[n]; - in intMain () { - //freopen ("Input.txt", "R", stdin); to intN; +scanf"%d",&n); -F (I,1, N) scanf ("%d",&a[i].t); theF (I,1, N) scanf ("%d",&a[i].k); *Sort (A +1, a+n+1); $LL time=0;Panax NotoginsengLL ans=0; -F (I,1, N) { thetime+=a[i].t; +ans+= (LL) a[i].k*Time ; A } theprintf"%lld\n", ans); + return 0; -}
View Code
"Bzoj" "3850" ZCC Loves codefires