SMARKET SOLUTION
2 posters
Page 1 of 1
SMARKET SOLUTION
It ran only of 10 points.please share better solutions
- Code:
import java.util.Scanner;
class smarket {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
int q=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
while(q-->0)
{
int l=sc.nextInt();
int r=sc.nextInt();
int k=sc.nextInt();
int count=0,c=0,copy;
for(int i=l-1;i<r;i++)
{
copy=a[i];
c=0;
while(copy==a[i])
{
c++;
i++;
if(i==r)
{
break;
}
else
{
if(copy==a[i])
{
c++;
i++;
if(i==r)
{
break;
}
}
}
}
if(c>=k)
{
count++;
}
i--;
}
System.out.println(count);
}
}
}
}
akarshsomani- Posts : 21
Join date : 2017-04-04
Re: SMARKET SOLUTION
#include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t>0)
{
long int n,q,i;
scanf("%ld %ld",&n,&q);
long int a[n];
for(i=0;i<n;i++)
scanf("%ld",&a[i]);
while(q>0)
{
long int l,r,m,j,c,c1=0,c2,k;
scanf("%ld %ld %ld",&l,&r,&k);
for(j=l-1;j<=r-1;j+=m-j)
{
c=0;
for(m=j;m<=r-1;m++)
{
if(a[m]==a[j])
c++;
else
break;
}
if(c>=k)
c1++;
}
printf("%ld\n",c1);
q--;
}
t--;
}
return 0;
}
int main()
{
int t;
scanf("%d",&t);
while(t>0)
{
long int n,q,i;
scanf("%ld %ld",&n,&q);
long int a[n];
for(i=0;i<n;i++)
scanf("%ld",&a[i]);
while(q>0)
{
long int l,r,m,j,c,c1=0,c2,k;
scanf("%ld %ld %ld",&l,&r,&k);
for(j=l-1;j<=r-1;j+=m-j)
{
c=0;
for(m=j;m<=r-1;m++)
{
if(a[m]==a[j])
c++;
else
break;
}
if(c>=k)
c1++;
}
printf("%ld\n",c1);
q--;
}
t--;
}
return 0;
}
iamdsc_0410- Posts : 14
Join date : 2017-04-11
Age : 26
Location : IIIT Kalyani
Similar topics
» ROWSOLD SOLUTION
» DISH OF LIFE SOLUTION
» CHEF AND DIGITS SOLUTION
» Similar Dishes Solution
» in ipl question.the test case 2nd is wrong.my solution is correct.
» DISH OF LIFE SOLUTION
» CHEF AND DIGITS SOLUTION
» Similar Dishes Solution
» in ipl question.the test case 2nd is wrong.my solution is correct.
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|