[ create a new paste ] login | about

Link: http://codepad.org/VxeC9FGh    [ raw code | fork ]

hoaithu.melody - C++, pasted on May 28:
//minimal big sum
#include <iostream>
 using namespace std;

 int main()
 {
	 freopen("testcase.txt", "r", stdin);
	 int T, k, n, num[100000], i;
	 cin >> T;
	 for(int testcase = 1; testcase <= T; testcase++)
	 {
		 cin >> k;
		 cin >> n;
		 int max = 0;
		 for(i= 0; i < n; i++)
		 {
			 cin >> num[i];
			 if(max < num[i])
				 max = num[i];
		 }
		 while(true)
		 {
			 int sum = 0;
			 int b = 1;
			 for(i = 0; i < n; i++)
			 {
				sum += num[i];
				if(sum > max)
				{
					b++;
					sum = num[i];
				}
			 }
			 if(b <= k)
				 break;
			 max++;
		 }
		 cout << "#" << testcase << " " << max << endl;
	 }
	 return 0;
 }


Output:
No errors or program output.


Create a new paste based on this one


Comments: