#include #define rep(i,a,b) for(int i=a;i<(b);++i) #define erep(i,a,b) for(int i=a;i<=(int)(b);++i) #define per(i,a,b) for(int i=(a);i>(b);--i) #define eper(i,a,b) for(int i=(a);i>=b;--i) #define pb push_back #define mp make_pair #define INF 100100100100 #define MOD 1000000007 #define all(x) (x).begin(),(x).end() #define vii vector #define vll vector using namespace std; typedef long long ll; typedef pair Pii; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> n; vii a(n-1), b(n), c(n); rep(i, 0, n-1) cin >> a[i]; rep(i, 0, n) { cin >> b[i] >> c[i]; } int ans = 0; rep(i, 0, n) { if (b[i] > 0) { rep(j, 0, n) { if (c[j] > 0) { int x = 0; rep(k, j, i) x += a[k]; if (c[j] - b[i] >= 0) { ans += b[i] * x; c[j] -= b[i]; break; } else { ans += c[j] * x; c[j] = 0; continue; } } } } } cout << ans << endl; return 0; }