1<=p2<p3<…<pt<=10^12
#include<cstdio> #include<algorithm> using namespace std; typedef long long LL; const int N=110; LL n, T, F=1; struct node{ LL m, d; }Z[N]; LL p[N], sum, t; void Getin( LL &shu ) { char c; LL f=1; shu=0; for( c=getchar(); c<'0' || c>'9'; c=getchar() ) if( c=='-' ) f=-1; for( ; c>='0' && c<='9'; c=getchar() ) shu=shu*10+c-'0'; shu*=f; } bool cmp( node a, node b ) { return a.d<b.d; } int main() { Getin(n); for( LL i=1; i<=n; i++ ) Getin(Z[i].m), Getin(Z[i].d ); Getin(T); for( LL i=1; i<=T; i++ ) Getin(p[i] ); sort( Z+1, Z+n+1, cmp ); for( LL i=1; i<=n; i++ ) { while( p[F] && Z[i].m+t>p[F] ) { sum+=(p[F]-t)*Z[i].d*F; Z[i].m-=(p[F]-t); t=p[F++]; } sum+=Z[i].m*Z[i].d*F; t+=Z[i].m; } printf( "%lld\n", sum ); return 0; }