/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 324.0 KiB
#2 Accepted 9ms 612.0 KiB
#3 Accepted 9ms 604.0 KiB
#4 Accepted 7ms 488.0 KiB
#5 Accepted 7ms 616.0 KiB
#6 Accepted 7ms 612.0 KiB
#7 Accepted 7ms 620.0 KiB
#8 Accepted 3ms 588.0 KiB
#9 Accepted 3ms 488.0 KiB
#10 Accepted 7ms 516.0 KiB
#11 Accepted 2ms 332.0 KiB
#12 Accepted 4ms 588.0 KiB
#13 Accepted 8ms 516.0 KiB
#14 Accepted 5ms 340.0 KiB
#15 Accepted 7ms 512.0 KiB

Code

/*
    BISMILLAHIR RAHMANIR RAHIM
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
void solve()
{
   int n,k;cin>>n>>k;
   vector<string> v(n);
   
   for(int i=0;i<n;i++)
   {
    int x;cin>>x;
    v[i]=to_string(x);
   }
   string ans=v[0];
   for(int i=0;i<n;i++)
   {
    string mk;
    int cnt=0;
    for(int j=i;j<n;j++)
    {
        if(cnt>k)
        {
            break;
        }
        mk+=v[j];cnt++;
    }
    // cout<<mk<<endl;
    if(mk.size()>ans.size())
    {
        ans=mk;
    }
    else if(mk.size()==ans.size())
    {
        bool cn=false;
        for(int l=0;l<mk.size();l++)
        {
            if(mk[l]>ans[l])
            {
                cn=true;break;
            }
            if(mk[l]<ans[l])
            {
                cn=false;break;
            }
        }
        if(cn)
        {

            ans=mk;
        }
    }
   }
   cout<<ans<<endl;
//    while(v.size()>1 and k)
//    {
//     string ks=v[0]+v[1];
//     int i1=0,i2=1;
//     for(int i=1;i<v.size();i++)
//     {
//         string kp=v[i]+v[i-1];
//         if(kp>=ks and kp.size()>=ks.size())
//         {
//             i1=i;
//             i2=i-1;
//             ks.clear();
//             ks=kp;
//         }
//     }
//     vector<string> tmp;
//     for(int i=0;i<v.size();)
//     {
//         if(i==i2)
//         {
//             tmp.push_back(ks);i+=2;
//         }
//         else
//         {
//             tmp.push_back(v[i]);i++;
//         }
//     }
//     // for(auto it:tmp)
//     // {
//     //     cout<<it<<" ";
//     // }
//     // cout<<endl;
//     v.clear();v=tmp;
//     k--;
//    }
//    string mx=v[0];
//    for(auto it:v)
//    {
//     if(it>mx and it.size()>=mx.size())
//     {
//         mx=it;
//     }
//    }
//    cout<<mx<<endl;

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1083 Number concatenation
Contest
Bangladesh 2.0
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-16 16:16:45
Judged At
2024-10-03 13:27:50
Judged By
Score
100
Total Time
9ms
Peak Memory
620.0 KiB