#include "OJ.h"/* Input: Npapers represents the number of quiz papers (1≤papers≤20), Nremain indicates the remaining time (1≤nremain≤10000), paper[][2] is an array of papers*2, two of each row The elements in turn are the time required to complete the test paper, and the value of the test paper output: *pmaxvalue for the maximum value to be returned: 0: Exception 1: The calculation returned successfully */int getmaxvalue (int npapers, int nremain, int p
APER[][2], double* pmaxvalue) {if (npapers==0 | | nremain==0 | | pmaxvalue==0 | | paper[0]==0) return 0; int costversustime[21]={0}; Record price/performance int pos[21]={0};
Price/performance sorting, the original position is also sorted for (int i=0;i<npapers;i++) {costversustime[i]= (* (paper[i]+1))/(* (* (paper[i]));
} for (int i=0;i<npapers;i++) {pos[i]=i;
}//Use a bubbling sort, and also modify the location information for (int i=0;i<npapers;i++) {for (int j=npapers-1;j>i+1;j--) {
if (Costversustime[j]>costversustime[j-1]) {int temp=costversustime[j];
COSTVERSUSTIME[J]=COSTVERSUSTIME[J-1];
Costversustime[j-1]=temp;
Pos[j]=j-1;
Pos[j-1]=j;
}}} *pmaxvalue=0;
int m=0; while (nremain>0 && M<=NPapers) {int temp=pos[m];
if (Nremain>*paper[temp])//The remaining time can do a complete test paper {nremain-=*paper[temp];
*pmaxvalue+=* (paper[temp]+1);
else//the remaining time is insufficient to make a Test paper, to obtain part of the value of {*pmaxvalue+= (nremain/(*paper[temp)) * (* (paper[temp]+1));
nremain=0;
} m++;
} return 1;
}