# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
666484 | Trumling | Robots (IOI13_robots) | C++14 | 0 ms | 0 KiB |
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 "robots.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define F first
#define S second
#define enter cout<<'\n';
int putaway(int a, int b, int t, int x[], int y[], int w[], int s[])
{
sort(x,x+a,greater<ll>());
sort(w,w+t,greater<ll>());
if(x[0]<=w[0])
return -1;
ll idx=0;
ll arr[a+1];
for(int i=0;i<a;i++)
{
while(idx<t && w[idx]>=x[i])
{
idx++;
}
arr[i]=idx;
}
arr[a]=t;
ll rest[a+10]={ };
ll pre=arr[0],count=1;
ll time=0;
for(int i=1;i<=a;i++)
{
if(arr[i]==pre){
count++;
continue;
}
ll now=(arr[i]-pre)/count;
ll rem=(arr[i]-pre)%count;
if(rem){
now++;
rem=count-rem;
}
if(time==0)
{
count=1;
time=now;
rest[time]+=rem;
rest[time+1]+=count-rem;
pre=arr[i];
continue;
}
if(now<=time)
{
rest[now]+=rem;
rest[now+1]+=count-rem;
count=1;
pre=arr[i];
continue;
}
ll toys=(arr[i]-pre);
for(ll j=1;j<=time;j++)
{
toys-=count+rest[j];
if(toys<=0)
{
rest[j+1]+=count+rest[j];
rest[j]=-toys;
break;
}
rest[j+1]+=rest[j];
rest[j]=0;
}
if(toys<=0)
{
count=1;
pre=arr[i];
continue;
}
now=toys/(count+rest[time+1]);
rem=toys%(count+rest[time+1]);
if(toys%(count+rest[time+1]))
{
now++;
rem=count+rest[time+1]-rem;
}
rest[start+now]+=rem;
rest[start+now+1]+=count+rest[time+1]-rem;
time=time+now;
pre=arr[i];
count=1;
}
return time;
}