/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 540.0 KiB
#2 Accepted 6ms 596.0 KiB
#3 Accepted 6ms 596.0 KiB
#4 Accepted 6ms 600.0 KiB
#5 Accepted 6ms 600.0 KiB
#6 Accepted 6ms 600.0 KiB
#7 Accepted 3ms 608.0 KiB
#8 Accepted 3ms 484.0 KiB
#9 Accepted 3ms 492.0 KiB
#10 Accepted 3ms 580.0 KiB
#11 Accepted 3ms 332.0 KiB
#12 Accepted 3ms 580.0 KiB
#13 Accepted 2ms 492.0 KiB
#14 Accepted 2ms 492.0 KiB
#15 Accepted 3ms 512.0 KiB

Code

#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
  int t;
  cin >> t;
  while (t--){
    ll n, k, mx = 0;
    cin >> n >> k;
    string ans = "";
    string a[n + 1];
   // vector<string> a(n + 1);
    vector<ll> b(n + 1);
    for (int i = 1; i <= n; i++){
      cin >> a[i]; //cout<<a[i]<<' ';
      b[i] = a[i].size();
      b[i] += b[i - 1];
    } //for(auto i:b)cout<<i<<' ';
    for (int i = k + 1; i <= n; i++){
      mx = max(mx, b[i] - b[i - k - 1]);
    }
    for (int i = k + 1; i <= n; i++){
      ll x = b[i] - b[i - k - 1];
      if (mx == x){
        string tmp;
        for (int j = i - k; j <= i; j++){
          tmp += a[j];
        }
        if (tmp > ans) ans = tmp;
      }
    }
    cout << ans << endl;
  }
}

Information

Submit By
Type
Submission
Problem
P1083 Number concatenation
Contest
Bangladesh 2.0
Language
C++17 (G++ 13.2.0)
Submit At
2024-08-16 16:05:57
Judged At
2024-11-11 03:16:09
Judged By
Score
100
Total Time
6ms
Peak Memory
608.0 KiB