| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
没想明白这代码怎么会MLE?(附代码)#include <cstdio>
#include <cstdlib>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
struct po
{
int l,p;
}a;
bool cmp(po a,po b)
{
return a.l > b.l;
}
struct cmp1
{
bool operator()(po a,po b)
{
return a.p < b.p;
}
};
vector<po> V;
priority_queue<po,vector<po>,cmp1> q;
int main()
{
int n,ll,pp,c,flag,j,temp;
po k;
while (scanf("%d",&n) == 1)
{
flag = c = 0;
V.clear();
for (int i = 0;i < n;i++)
{
scanf("%d %d",&a.l,&a.p);
V.push_back(a);
}
scanf("%d%d",&ll,&pp);
sort(V.begin(),V.end(),cmp);
temp = ll;
j = 0;
temp -= pp;
while (temp > 0)
{
if (j == n)
break;
if (temp > V[j].l && q.empty())
break;
else
{
for (j = 0;j < n;j++)
{
if (V[j].l >= temp)
q.push(V[j]);
else
break;
}
k = q.top();
pp = k.p;
temp -= pp;
q.pop();
c++;
}
}
if (temp <= 0)
printf("%d\n",c);
else
printf("-1\n");
while (!q.empty())
q.pop();
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator