-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path200-geometry-horse.cpp
More file actions
47 lines (45 loc) · 1.06 KB
/
Copy path200-geometry-horse.cpp
File metadata and controls
47 lines (45 loc) · 1.06 KB
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
39
40
41
42
43
44
45
46
47
/*
* Geometry Horse [175C]
* Problem: https://codeforces.com/problemset/problem/175/C
* Verdict: ACCEPTED Solved: 2023-08-11
* Language: C++17 (GCC 7-32)
* Runtime: 30 ms Memory: 0 KB
* Tags: greedy, implementation, sortings, two pointers
* Author: BidoTeima
* Source: https://codeforces.com/contest/175/submission/218288499
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
int n;
cin>>n;
pair<int,int>a[n];
for(int i = 0; i < n; i++){
cin>>a[i].second>>a[i].first;
}
sort(a,a+n);
int t;
cin>>t;
ll p[t];
for(int i = 0; i < t; i++){
cin>>p[i];
}
int f = 1;
ll k = 0, ans = 0;
for(int i = 0; i < n; i++){
while(a[i].second > 0 && f<=t){
ll mn = min(p[f - 1] - k, (ll)a[i].second);
k += mn;
a[i].second -= mn;
ans += mn * a[i].first * f;
if(k >= p[f - 1])++f;
}
if(f==t+1){
ans+=(ll)a[i].second*a[i].first*f;
}
}
cout<<ans;
return 0;
}