Codeforces Round #299 (Div. 1) C. Tavas and Pashmaks
Tavas is a cheerleader in the new sports competition named "Pashmaks".
This competition consists of two part: swimming and then running. People will immediately start running R meters after they finished swimming exactly S meters. A winner is a such person that nobody else finishes running before him/her (there may be more than one winner).
Before the match starts, Tavas knows that there are n competitors registered for the match. Also, he knows that i-th person's swimming speed is si meters per second and his/her running speed is ri meters per second. Unfortunately, he doesn't know the values of R and S, but he knows that they are real numbers greater than 0.
As a cheerleader, Tavas wants to know who to cheer up. So, he wants to know all people that might win. We consider a competitor might win if and only if there are some values of R and S such that with these values, (s)he will be a winner.
Tavas isn't really familiar with programming, so he asked you to help him.
The first line of input contains a single integer n (1 ≤ n ≤ 2 × 105).
The next n lines contain the details of competitors. i-th line contains two integers si and ri (1 ≤ si, ri ≤ 104).
In the first and the only line of output, print a sequence of numbers of possible winners in increasing order.
3
1 3
2 2
3 1
1 2 3
3
1 2
1 1
2 1
1 3
#include <iostream> #include<stdio.h> #include<vector> #include<algorithm> using namespace std; struct node{ __int64 x,y,index; }; node a[300000],c[300000]; int b[300000],flg[300000],w[300000],f[300000]; vector<int> ans; bool cmp(node a,node b) { if (a.x<b.x) return true; if (a.x==b.x&&a.y<b.y) return true; return false; } bool dog(int index1,int index2,int index3) { if (index2==1) return true; if ((c[index1].x-c[index2].x)*(c[index3].y-c[index2].y)*c[index3].x*c[index1].y>= (c[index2].x-c[index3].x)*(c[index2].y-c[index1].y)*c[index1].x*c[index3].y) return true; return false; } int main() { int n,t1,t2; while(scanf("%d",&n)!=EOF) { for(int i=1;i<=n;i++) { scanf("%I64d%I64d",&a[i].x,&a[i].y); a[i].index=i; w[i]=flg[i]=0; } for(int i=1;i<=20000;i++) b[i]=0; sort(a+1,a+1+n,cmp); for(int i=n;i>=1;i--) { if (b[a[i].y]==0) { flg[a[i].index]=1; for(int j=a[i].y;j>=1;j--) if (b[j]==1) break; else b[j]=1; } } t1=1; c[1].x=a[n].x; c[1].y=a[n].y; c[1].index=1; //flg[n]=1; for(int i=n-1;i>=1;i--) { if (flg[a[i].index]==1) { flg[a[i].index]=++t1; c[t1].x=a[i].x; c[t1].y=a[i].y; c[t1].index=t1; } else if (flg[a[i+1].index]>=1&&a[i].x==a[i+1].x&&a[i].y==a[i+1].y) flg[a[i].index]=flg[a[i+1].index]; } if (t1>=2) { t2=2; f[1]=1; f[2]=2; } else { t2=1; f[1]=1; } for(int i=3;i<=t1;i++) { for(int j=t2;j>=1;j--) if (dog(i,f[j],f[j-1])) { f[t2=j+1]=i; break; } } for(int i=1;i<=t2;i++) w[c[f[i]].index]=1; ans.clear(); for(int i=1;i<=n;i++) if (w[flg[i]]==1) ans.push_back(i); for(int i=0;i<ans.size();i++) printf("%d ",ans[i]); printf("\n"); } return 0; } /* 3 1 3 2 2 3 1 18 82 38 33 69 33 69 33 69 33 69 33 69 82 38 33 69 33 69 33 69 82 38 33 69 33 69 82 38 82 38 33 69 33 69 33 69 */