It’s All In The Mind
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 385 Accepted Submission(s): 174
Problem Description
Professor Zhang has a number sequence a1,a2,…,an. However, the sequence is not complete and some elements are missing. Fortunately, Professor Zhang remembers some properties of the sequence:
- For every i∈{1,2,…,n}, 0≤ai≤100.
- The sequence is non-increasing, i.e. a1≥a2≥…≥an.
- The sum of all elements in the sequence is not zero.
Professor Zhang wants to know the maximum value of a1+a2∑ni=1ai among all the possible sequences.
Input
There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
The first contains two integers n and m (2≤n≤100,0≤m≤n) – the length of the sequence and the number of known elements.
In the next m lines, each contains two integers xi and yi (1≤xi≤n,0≤yi≤100,xi
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int gcd(int a,int b)
{
while(a^=b^=a^=b%=a);
return b;
}
int a[110];
int main()
{
int nn;
scanf("%d",&nn);
while(nn--)
{
memset(a,0,sizeof(a));
int n,m,fenzi=0,i,fenmu=0,x=0,y,maxx=0,temp;
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
a[i]=-1;
for(i=1; i<=m; i++)
scanf("%d%d",&x,&y),a[x]=y,maxx=max(maxx,x);
for(i=maxx; i>=3; i--)
{
if(a[i]!=-1)
temp=a[i];
fenmu+=temp;
}
if(a[1]!=-1)
fenmu+=a[1],fenzi+=a[1];
else
fenmu+=100,fenzi+=100;
if(a[2]!=-1)
fenmu+=a[2],fenzi+=a[2];
else
{
if(a[1]!=-1)
fenmu+=a[1],fenzi+=a[1];
else
fenmu+=100,fenzi+=100;
}
int gcd_n=gcd(fenzi,fenmu);
printf("%d/%d\n",fenzi/gcd_n,fenmu/gcd_n);
}
}