/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 4ms 532.0 KiB
#3 Accepted 4ms 536.0 KiB
#4 Accepted 4ms 536.0 KiB
#5 Accepted 5ms 532.0 KiB
#6 Accepted 6ms 592.0 KiB
#7 Accepted 4ms 532.0 KiB
#8 Accepted 6ms 324.0 KiB
#9 Accepted 6ms 532.0 KiB
#10 Accepted 5ms 584.0 KiB
#11 Accepted 6ms 532.0 KiB
#12 Accepted 5ms 532.0 KiB
#13 Accepted 5ms 532.0 KiB
#14 Accepted 5ms 532.0 KiB
#15 Accepted 6ms 344.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-08-16 16:05:57
Judged By
Score
100
Total Time
6ms
Peak Memory
592.0 KiB