# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
666447 | 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 pre=arr[0],rest=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+=rem;
pre=arr[i];
continue;
}
if(now<=time)
{
count=1;
rest+=rem;
pre=arr[i];
continue;
}
ll toys=(arr[i]-pre)-count*(time-1);
toys-=count+rest;
if(toys<=0)
{
count=1;
rest=-toys;
pre=arr[i];
continue;
}
now=toys/(i+1);
if(toys%(i+1))
now++;
time=now;
rest=i+1-toys%(i+1);
pre=arr[i];
count=1;
}
return time;
}
#include <stdio.h>
#include <stdlib.h>
#include "robots.h"
#define fail(s, x...) do { \
fprintf(stderr, s "\n", ## x); \
exit(1); \
} while(0)
#define MAX_A 50000
#define MAX_B 50000
#define MAX_T 500000
static int X[MAX_A];
static int Y[MAX_B];
static int W[MAX_T];
static int S[MAX_T];
int main() {
int A, B, T, i;
int res;
cin>>A>>B>>T;
for(int j=0;j<A;j++)
cin>>X[j];
for(int j=0;j<B;j++)
cin>>Y[j];
for(int j=0;j<T;j++)
cin>>W[j]>>S[j];
int answer = putaway(A, B, T, X, Y, W, S);
printf("%d\n", answer);
return 0;
}