Cod sursa(job #2896709)

Utilizator andrew91beteringhe andrei andrew91 Data 30 aprilie 2022 12:24:40
Problema Transport Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <bitset>
#include <math.h>
#include <string.h>
#include <string>
#include <cctype>
#include <stack>
using namespace std; 

int main ()
{	
#ifndef ONLINE_JUDGE
	freopen("input.txt" , "r" , stdin);
	freopen("output.txt" , "w" , stdout);
#endif
	
 	stack<int> stiva;
 	int n , zile;
 	cin >> n >> zile;

 	short cp = n;
 	while ( cp --)
 	{
 		int x ;
 		cin >> x;
 		stiva.push(x);
 	}

 	int maxx = 0;
 	while ( zile --)
 	{
 		int	 sum = 0;
 		int cp = zile + 1;
 		while ( cp--)
 		{
 			sum+=stiva.top();
 			stiva.pop();
 		}
 		maxx = max (maxx , sum);
 	}
 	cout << maxx;
}