Mai intai trebuie sa te autentifici.
Cod sursa(job #2401288)
| Utilizator | Data | 9 aprilie 2019 16:20:38 | |
|---|---|---|---|
| Problema | Lupul Urias si Rau | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 1.04 kb |
#include <fstream>
#include <algorithm>
#include <queue>
using namespace std;
ifstream fin("lupu.in");
ofstream fout("lupu.out");
struct oaie
{
int dist, lana;
bool operator<(oaie rhs) const
{
return lana>rhs.lana;
}
} p[100002];
bool comp_d(oaie s, oaie dr)
{
return s.dist>dr.dist;
}
priority_queue<oaie> q;
long long N, X, L, ans, dmax;
int main()
{
fin>>N>>X>>L;
for (int i=1; i<=N; i++)
{
fin>>p[i].dist;
fin>>p[i].lana;
if (p[i].dist>dmax)
dmax = p[i].dist;
}
sort(p+1,p+N+1, comp_d);
for (int i=1; i<=N; i++)
fout<<p[i].dist<<" "<<p[i].lana<<endl;
long long pos = 1;
for (long long d=dmax; d>=1; d--)
{
while (pos<=N && p[pos].dist<=d)
{
q.push(p[pos]);
pos++;
}
if (!q.empty())
{
fout<<"am pus "<<q.top().lana<<endl;
ans+=q.top().lana;
q.pop();
}
}
fout<<ans;
}
