/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 332.0 KiB
#2 Accepted 2ms 332.0 KiB
#3 Accepted 2ms 556.0 KiB
#4 Accepted 2ms 328.0 KiB
#5 Accepted 2ms 332.0 KiB
#6 Accepted 2ms 332.0 KiB
#7 Accepted 2ms 420.0 KiB
#8 Accepted 2ms 332.0 KiB
#9 Accepted 2ms 328.0 KiB
#10 Accepted 2ms 328.0 KiB
#11 Accepted 13ms 644.0 KiB
#12 Accepted 3ms 604.0 KiB
#13 Accepted 4ms 608.0 KiB
#14 Accepted 3ms 588.0 KiB
#15 Accepted 5ms 644.0 KiB
#16 Accepted 19ms 640.0 KiB
#17 Accepted 19ms 648.0 KiB
#18 Accepted 193ms 1.32 MiB
#19 Accepted 173ms 1.32 MiB
#20 Accepted 15ms 1.332 MiB
#21 Accepted 167ms 1.398 MiB
#22 Accepted 158ms 1.684 MiB
#23 Accepted 37ms 1.316 MiB
#24 Accepted 20ms 1.27 MiB
#25 Accepted 16ms 1.309 MiB
#26 Accepted 19ms 1.18 MiB

Code

#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")
using namespace std;

void solve(int cs) {
  int n, k, x;
  cin >> n >> k >> x;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  int res = 0;
  for (int g = x + 1; g <= 100; g++) {
    auto b = a;
    for (int j = 0; j < n; j++) {
      b[j] = (g - (b[j] % g)) % g;
    }
    queue<int> Q;
    int sum = 0;
    for (int i = 0; i < n; i++) {
      sum += b[i];
      Q.push(b[i]);
      while (sum > k) {
        sum -= Q.front();
        Q.pop();
      } 
      if (sum <= k) {
        res = max(res, (int)Q.size());
      }
    }
  }
  cout << res << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc = 1;
  // cin >> tc;
  for (int cs = 1; cs <= tc; cs++) {
    solve(cs);
  }
  return 0;
}

Information

Submit By
Type
Submission
Problem
P1043 Longest subarray
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-04 15:44:20
Judged At
2024-11-11 02:42:40
Judged By
Score
100
Total Time
193ms
Peak Memory
1.684 MiB