# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
477286 | Tsiannis | Traffic (IOI10_traffic) | C++17 | 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<bits/stdc++.h>
using namespace std;
#define INF 100000000000
typedef long long ll;
#define MAXN 1000000
ll P[MAXN],D[MAXN],S[MAXN],pre[MAXN];
ll sum=0;
int LocateCentre(ll N,ll P[],ll S[],ll D[])
{
ll mn=INF;
ll index;
for (int i=0;i<N;i++)
{
ll d=(sum-P[i])/2;
if (abs(pre[i]-d-P[i])<mn)
{
mn=abs(pre[i]-d-P[i]);
index=i;
}
}
return index;
}
int main()
{
ll N;
cin>>N;
for (int i=0;i<N;i++)
{
cin>>P[i];
sum+=P[i];
pre[i]=sum;
}
for (int i=0;i<N-1;i++)
{
cin>>S[i]>>D[i];
}
cout<<LocateCentre(N,P,S,D)<<endl;
return 0;
}