pku2497.java

来自「这是ACM 方面的资料 是PKU的 北京大学的出来的」· Java 代码 · 共 31 行

JAVA
31
字号
import java.io.*;
import java.util.*;
class Main
{
	public static void main(String args[]) throws Exception
	{
		Scanner cin=new Scanner(System.in);
		int T,allT,allN,i,k,s[],score,nowT;
		T=cin.nextInt();
		for(k=1;k<=T;k++)
		{
			allT=cin.nextInt();
			allN=cin.nextInt();
			s=new int[allN];
			for(i=0;i<allN;i++) s[i]=cin.nextInt();
			Arrays.sort(s);
			i=0;
			score=0;
			nowT=0;
			while(i<allN&&allT>=s[i])
			{
				allT-=s[i];
				nowT+=s[i];
				score+=nowT;
				i++;
			}
			System.out.printf("Scenario #%d:\nSteve wins with %d solved problems and a score of %d.\n\n",k,i,score);
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?