Pagini recente » Cod sursa (job #1879159) | Cod sursa (job #1810583) | Cod sursa (job #1152499) | Cod sursa (job #1097797) | Cod sursa (job #1150917)
?
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
#include <fstream>
#include <algorithm>
#include <queue>
using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");
struct oaie{ int D, L; }a[100005];
struct cmp
{
bool operator()(const oaie &a, const oaie &b)const
{
return (a.D<b.D);
}
};
int N, Dmax, dist, i=1;
priority_queue < int > H;
long long sol;
int main()
{
f>>N>>Dmax>>dist;
for (int ii=1; ii<=N; ++ii)
f>>a[ii].D>>a[ii].L;
sort(a+1, a+N+1, cmp());
for (int d=0; i<=N && d<=Dmax; d+=dist)
{
while (i<=N && a[i].D<=d)
H.push(a[i].L), ++i;
if (H.size())
sol+=H.top(), H.pop();
}
g<<sol<<'\n';
return 0;
}