This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "ricehub.h"
#include <bits/stdc++.h>
#define ii pair<int,int>
#define fi first
#define se second
#define ll long long
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
int ans=0;
for (int i = 0; i < R; ++i)
{
int idx=i,comp=1;
ll rem=B;
priority_queue<pair<ii,int>,vector<pair<ii,int>>,greater<pair<ii,int> > > q;
if(idx-1>=0)q.push({{X[idx]-X[idx-1],idx-1},0});
if(idx+1<R)q.push({{X[idx+1]-X[idx],idx+1},1});
while(!q.empty()){
pair<ii,int> front =q.top();
q.pop();
if(front.fi.fi>rem)break;
rem-=front.fi.fi,comp++;
if(front.se&&front.fi.se+1<R)
q.push({{X[front.fi.se+1]-X[front.fi.se],front.fi.se+1},1});
if(!front.se&&front.fi.se-1>=0)
q.push({{X[front.fi.se]-X[front.fi.se-1],front.fi.se-1},0});
}
//cerr<<i<<" "<<comp<<"\n";
ans=max(ans,comp);
}
return ans;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |