time limit per test
1 second
memory limit per test
256 megabytes
Kostya has a text ss consisting of nn words made up of Latin alphabet letters. He also has two strips on which he must write the text. The first strip can hold mm characters, while the second can hold as many as needed.
Kostya must choose a number xx and write the first xx words from ss on the first strip, while all the remaining words are written on the second strip. To save space, the words are written without gaps, but each word must be entirely on one strip.
Since space on the second strip is very valuable, Kostya asks you to choose the maximum possible number xx such that all words s1,s2,…,sxs1,s2,…,sx fit on the first strip of length mm.
Input
The first line contains an integer tt (1≤t≤10001≤t≤1000) — the number of test cases.
The first line of each test case contains two integers nn and mm (1≤n≤501≤n≤50; 1≤m≤5001≤m≤500) — the number of words in the list and the maximum number of characters that can be on the first strip.
The next nn lines contain one word sisi of lowercase Latin letters, where the length of sisi does not exceed 1010.
Output
For each test case, output the maximum number of words xx such that the first xx words have a total length of no more than mm.
Example
Input
Copy
5
3 1
a
b
c
2 9
alpha
beta
4 12
hello
world
and
codeforces
3 2
ab
c
d
3 2
abc
ab
a
Output
Copy
1 2 2 1 0
解题说明:此题是一道模拟题,为了让前x个字母写在第一页上,遍历即可。
#include<bits/stdc++.h>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
int t;
int n, m;
string s[200005];int main()
{cin >> t;while (t--){cin >> n >> m;int cnt = 0;for (int i = 1; i <= n; i++){cin >> s[i];}for (int i = 1; i <= n; i++){if (m >= s[i].size()){m -= s[i].size();cnt++;}else{break;}}cout << cnt <<endl;}return 0;
}