Takahashi wants to buy the popular video game console called Play Snuke.
There are \(N\) shops that sell Play Snuke: Shop \(1, 2, \dots, N\). Shop \(i\) is \(A_i\) minutes' walk from where Takahashi is now, sells Play Snuke for \(P_i\) yen (Japanese currency), and currently has \(X_i\) Play Snukes in stock.
Now, Takahashi will go to one of those shops on foot and buy Play Snuke if it is still in stock when he gets there.
However, Play Snuke is so popular that the number of consoles in stock (if any) in every shop will decrease by \(1\) at the following moments: \(0.5, 1.5, 2.5, \dots\) minutes from now.
Determine whether Takahashi can buy Play Snuke. If he can, find the minimum amount of money needed to buy one.
#include<stdio.h>
#include<stdlib.h>
int main()
{
struct shop{
int s;
int w;
int n;
}*ps;
int a,i,x=0,j=0,*p,m;
scanf("%d",&a);
p=(int*)malloc(a*sizeof(int));
ps=(struct shop*)malloc(a*sizeof(struct shop));
for(i=0;i<a;i++)
{scanf("%d%d%d",(ps+i)->s,(ps+i)->w,(ps+i)->n);}
for(i=0;i<a;i++)
{
if((ps+i)->s<(ps+i)->n)
{x++;}
else{
*(p+j)=(ps+i)->w;
j++;
}
}free(ps);
if(x==a)
{printf("-1");}
else
{m=*p;
for(i=0;i<j;i++)
{
if(m<*(p+i))
m=*(p+i);
}
printf("%d",m);
}free(p);
}