C++,codeforces,2050A,A. Line Breaks

//A. Line Breaks
#include <string>
#include <iostream>

void solve(){
    int n,left;
    std::cin>>n>>left;
    int count = 0;
    while(n--){
        std::string temp;
        std::cin>>temp;
        if(temp.size()<=left){
            left-=temp.size();
            count++;
        }else{
            while(n--){
                std::cin>>temp;
            }
            break;
        }
    }
    std::cout<<count<<std::endl;
}
int main(){
    int t;
    std::cin>>t;
    while(t--){
        solve();
    }
}










// #include <iostream>
// #include <set>
// #include <string>
// #include <vector>
// class MaxOnTop{
// public:
//     int index = 0;
//     std::vector<int> data = {0};
//     int top(){
//         if(index<=0){
//             std::cout<<"Empty heap\n"<<std::endl;
//             return -1;
//         }
//         return data[1];
//     }
//     void push(int x){
//         data.push_back(x);
//         index++;
//         int p = index;
//         while(p>1 && data[p]>data[p/2]){
//             std::swap(data[p],data[p/2]);
//             p/=2;
//         }
//     }
//     void pop(){
//         if(index<=0){
//             return;
//         }
//         std::swap(data[1],data[index]);
//         data.pop_back();
//         index--;
//         int p = 1;
//         while(2*p<=index){
//             int child = 2*p;
//             if(child+1<=index && data[child+1]>data[child]){
//                 child = child+1;
//             }
//             if(child<=index && data[child]>data[p]){
//                 std::swap(data[child],data[p]);
//                 p = child;    
//             }else{
//                 break;
//             }
//         }
//     }
// };
// void solve(){
//     int n,m;
//     std::cin>>n>>m;
//     int count = 0;
//     int currentLength = 0;
//     MaxOnTop strip;
//     while(n--){
//         std::string temp;
//         std::cin>>temp;
//         if(temp.size()<=m-currentLength){
//             currentLength+=temp.size();
//             strip.push(temp.size());
//             count++;
//         }else if(temp.size() < strip.top()){
//             currentLength-=strip.top();
//             strip.pop();
//             strip.push(temp.size());
//             currentLength+=temp.size();
//         }
//     }
//     std::cout<<count<<std::endl;
// }
// int main(){
//     int t;
//     std::cin>>t;
//     while(t--){
//         solve();
//     }
// }
posted @ 2025-03-07 20:29  Kazuma_124  阅读(18)  评论(0)    收藏  举报