Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## Re:为什么总是wa,帮帮忙看下

Posted by abc78560 at 2012-05-23 22:33:45 on Problem 2431
In Reply To:为什么总是wa,帮帮忙看下 Posted by:zhangyiviva at 2012-05-23 17:34:43
```> //
> //  main.cpp
> //  poj2431
> //
> //  Created by zhangyi zhang on 12-5-23.
> //
>
> #include <iostream>
> #include <queue>
> #include <algorithm>
>
> using namespace std;
>
> int a[10001];
> int b[10001];
>
> bool cmp(int a, int b)
> {
>     return a>b;
> }
>
>
>
> int main(int argc, const char * argv[])
> {
>     int n,l,p,dis;
>     int ans = 0;
>     int index = 0;
>     priority_queue<int> queue;
>
>     cin>>n;
>     for(int i=0; i<n; i++)
>         cin>>a[i]>>b[i];
>     cin>>l>>p;
>     sort(a,a+n,cmp);
>     sort(b,b+n,cmp);
>     dis = l;
>     queue.push(p);
>
>     while(index<n)
>     {
>         if(b[index]<=l)
>             break;
>         index++;
>     }
>
>     while(dis > 0)
>     {
>         for(; a[index]>=dis && index <n; index++)
>             queue.push(b[index]);
>         if(queue.empty())
>         {
>             cout<<-1<<endl;
>             return 1;
>         }
>         dis -= queue.top();
>         queue.pop();
>         ans++;
>     }
>
>     cout<<ans-1<<endl;
>     return 0;
> }
```

Followed by: