Skip to content

Instantly share code, notes, and snippets.

@ArthurLoboLobo
Created April 10, 2023 14:48
Show Gist options
  • Save ArthurLoboLobo/c738db1d46967a8845688fafedc42dee to your computer and use it in GitHub Desktop.
Save ArthurLoboLobo/c738db1d46967a8845688fafedc42dee to your computer and use it in GitHub Desktop.
#include<bits/stdc++.h>
using namespace std;
int n, q, sk;
long long d[110000], p[110000];
int main() {
cin >> n;
sk = 0;
for(int i = 1; i <= n; i++) {
int k,p;
cin >> k >> p;
for(int j = sk+1; j <= sk+k; j++) {
d[j] = p;
}
sk+= k;
}
p[0] = 0;
for(int i = 1; i <= sk; i++) {
p[i] = p[i-1]+d[i];
}
cin >> q;
for(int i = 1; i <= q; i++) {
int x,y;
cin >> x >> y;
cout << p[y]-p[x-1] << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment