Untitled

 avatar
unknown
plain_text
2 years ago
1.5 kB
4
Indexable
// In Practice, You should use the statndard input/output
// in order to receive a score properly.
// Do not use file input and output. Please be very careful. 

#include<iostream>

using namespace std;
int arr[10000];
int N, K;



int main(int argc, char** argv)
{
	int test_case;
	int T;
	int Answer;
	
	ios::sync_with_stdio(false);
	
	/* 
	The freopen function below opens input.txt in read only mode and 
	sets your standard input to work with the opened file. 
	When you test your code with the sample data, you can use the function
	below to read in from the sample data file instead of the standard input.
	So. you can uncomment the following line for your local test. But you
	have to comment the following line when you submit for your scores.
	*/

	freopen("text.txt", "r", stdin);
	cin >> T;

	/*
	   Read each test case from standard input.
	*/
	for(test_case = 1; test_case <= T; ++test_case)
	{
		cin>>K>>N;
		int tong =0;
		int lon=0;
		for(int i=0; i<N; i++){
			cin>>arr[i];
			tong+=arr[i];
			if(lon<arr[i]) lon=arr[i];
		}
		int dem=0;
		int sum=0;
		int ans=0;
		for(int i= lon ; i<= tong; i++){
			dem=1;
			sum=0;
			for(int j=0; j<N; j++){
				if(sum+ arr[j] > i) {
					sum=arr[j];
					dem++;
				}
				else sum += arr[j];
			}
			if(dem<=K){
				ans=i;
				break;
			}


		}


		cout << "#" << test_case << " " << ans << endl;
	}
	return 0;//Your program should return 0 on normal termination.
}