제출 #1160250

#제출 시각아이디문제언어결과실행 시간메모리
1160250sl1pzzBigger segments (IZhO19_segments)C++20
0 / 100
0 ms328 KiB
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;

// #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
// #pragma GCC target("avx2")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,abm,mmx,avx,tune=native")

//-------------------------------------------------------------------------------------------------------------

#define int long long
#define pb push_back
#define ew "\n"
#define all(x) (x).begin(), (x).end()
#define st first
#define nd second
#define len(x) (int)x.size()
#define eb emplace_back
#define turbo                       \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0);

const int maxn = 2e5 + 12;
const int mxx = 100100;
const int MOD = 1e9 + 7;
const int inf = 1e18 + 7;
const int HH = 1e2 + 70;

int n;
int a[maxn], pref[maxn];

void code()
{
  cin >> n;
  for (int i = 1; i <= n; i++)
  {
    cin >> a[i];
    pref[i] = pref[i - 1] + a[i];
  }
  int rs = 0;
  for (int i = 1; i <= n; i++)
  {
    int lst = pref[i];
    int ans = 1;
    for (int j = i + 1; j <= n; j++)
    {
      int l = j, r = n;
      int x = -1;
      while (l <= r)
      {
        int md = (l + r) >> 1;
        if (pref[md] - pref[j - 1] >= lst)
        {
          r = md - 1;
          x = md;
        }
        else
        {
          l = md + 1;
        }
      }
      // cout << x << " ";
      if (x == -1)
      {
        break;
      }
      // cout << pref[x] - pref[j - 1];
      ans++;
      lst = pref[x] - pref[j - 1];
      j = x;
    }
    // cout << ew;
    rs = max(rs, ans);
  }
  cout << rs;
}

int32_t main()
{
  // freopen("248.in", "r", stdin);
  // freopen("248.out", "w", stdout);
  // turbo;
  int tt = 1, j = 1;
  // cin >> tt;
  while (tt--)
  {
    // cout << "Case " << j << ":" << ew;
    code();
    // j++;
  }
}
// by sl1pzz
// going to respa silver/goldz
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...