Time Limit: 1 Sec Memory Limit: 128 MB
Description
As we all know, Jinixin has a very famous speech - "Keep some distance from me".
Jinixin is so rich that everyone want to contact him, and Mosu is one of them. One
day , Jinixin agreed with Mosu to contact him if Mosu could beat him. There are n
digits(lets give them indices from 1 to n and name them a1,a2...an) and some queries.
For each query:
1.Jinixin choose an index x from 1 to n.
2.For all indices y ( y < x) calculate the difference by=ax−ay.
3.Then Jinixin calculate B1 ,the sum of all by which are greater than 0 , and
Mosu calculate B2 , the sum of all by which are less than 0.
if B1>|B2| , Jinixin won and did not agree with Mosu to contact him; else if B1 is
equals to |B2| , Jinixin would ignore the result; else if B1< |B2| , Jinixin lost and
agreed with Mosu to contact him.
Input
The first line contains two integers n, m (1≤n,m≤100000) denoting the number
of digits and number of queries. The second line contains n digits (without spaces)
a1,a2,...,an.(0≤ai≤9) Each of next m lines contains single integer x (1≤x≤n)
denoting the index for current query.
Output
For each of m queries print "Keep some distance from me" if Jinixin won, else
print "Next time" if Jinixin ignored the result, else print "I agree" if Jinixin lost in a line -
answer of the query.
Sample Input
10 3
0324152397
1
4
7
Sample Output
Next time
Keep some distance from me
I agree
#include<stdio.h>
#include<string.h>
int main()
{
char a[100001];
long long m,n,i,j,x,b[100001];
long long sum;
while(scanf("%lld%lld",&n,&m)!=EOF)
{ memset(b,0,sizeof(b));
sum=0;
scanf("%s",&a);
for(j=0; j<n; j++)
{
b[j+1]=(a[j]-'0'+0)*j-sum;
sum=sum+(a[j]-'0'+0);
}
while(m--)
{
scanf("%lld",&x);
if(b[x]>0)
{
printf("Keep some distance from me\n");
}
else if(b[x]==0)
{
printf("Next time\n");
}
else
{
printf("I agree\n");
}
}
}
return 0;
}