/*
#include<iostream>
#include <string>
#include <vector>
using namespace std;
int solution(vector<int> priorities, int location)
{
int answer = 0;
int first=0,count1=0,count2=1;
int k=priorities.size();
vector<int> check;
for(int i=0;i<k;i++)
{
check.push_back(i);
}
for(;;)
{
for(int i=first+1; i<priorities.size(); i++)
{
if(priorities[i]>priorities[first]){
priorities.push_back(priorities[first]);
check.push_back(check[first]);
first++;
count1=1;
}
}
if(count1==0){
if(check[first]==location){
answer=count2;
return answer;
}
first++;
count2++;
}
count1=0;
}
}
int main()
{
vector<int> priorities;
int location=0;
priorities.push_back(1);
priorities.push_back(1);
priorities.push_back(9);
priorities.push_back(1);
priorities.push_back(1);
priorities.push_back(1);
int result=solution(priorities,location);
cout<<result<<endl;
}
*/
#include<iostream>
#include <string>
#include <vector>
using namespace std;
int solution(int bridge_length, int weight, vector<int> truck_weights) {
int answer = 0;
int now_weight=0,number=0,first=0;
int arr[10002]={};
for(;;)
{
answer++;
if(number<truck_weights.size()&&now_weight+truck_weights[number]<=weight){
now_weight+=truck_weights[number];
number++;
if(number!=1) arr[number]=1;
}
for(int i=0;i<number;i++)
{
arr[i]++;
if(arr[i]==bridge_length+1){
now_weight-=truck_weights[i];
}
}
cout<<answer<<endl;
cout<<now_weight<<endl;
if(number==truck_weights.size()&&now_weight==0) break;
}
return answer;
}
int main()
{
vector<int> truck_weights;
/*
int bridge=100,weight=100;
truck_weights.push_back(10);
truck_weights.push_back(10);
truck_weights.push_back(10);
truck_weights.push_back(10);
truck_weights.push_back(10);
truck_weights.push_back(10);
truck_weights.push_back(10);
truck_weights.push_back(10);
truck_weights.push_back(10);
truck_weights.push_back(10);
*/
int bridge=2,weight=10;
truck_weights.push_back(7);
truck_weights.push_back(4);
truck_weights.push_back(5);
truck_weights.push_back(6);
int result=solution(bridge,weight,truck_weights);
cout<<result<<endl;
}