-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode588A.cpp
More file actions
38 lines (29 loc) · 785 Bytes
/
Copy pathcode588A.cpp
File metadata and controls
38 lines (29 loc) · 785 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* Contest : Codeforces
* Problem : 588A - Duff and Meat
* Link : https://codeforces.com/problemset/problem/588/A
*/
#include <bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
int main() {
fastio
int n; cin >> n;
vector<int> pre(n + 1), p(n + 1), menoresId;
for (int i = 1; i <= n; i++) {
cin >> pre[i] >> p[i];
if (menoresId.empty()) menoresId.push_back(i);
if (p[i] < p[menoresId.back()]) menoresId.push_back(i);
pre[i] += pre[i - 1];
}
menoresId.push_back(n + 1);
int ans = 0;
for (int i = 1, j = 0; i <= n; ++j) {
int curr = menoresId[j], prox = menoresId[j + 1];
int qtde = pre[prox - 1] - pre[i - 1];
ans += p[curr] * qtde;
i = prox;
}
cout << ans << '\n';
return 0;
}