Submission #642243

#TimeUsernameProblemLanguageResultExecution timeMemory
642243kebineLasers (NOI19_lasers)C++17
100 / 100
275 ms4916 KiB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef long long ll;
// const ll mod = 1e9 + 7;
const ll MAXN = 1e6 + 5;
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define sc second
#define endl '\n'
#define gl                        ios_base::sync_with_stdio(0);   cin.tie(0);                     cout.tie(0)

int main()
{
  int l, r;
  cin >> l >> r;

  vector<pii> v;
  for (int i = 0; i < r; i++)
  {
    int x;
    cin >> x;
    int a[x + 1], sum = 0;
    a[0] = 0;
    for (int j = 1; j <= x; j++)
    {
      cin >> a[j];
      sum += a[j];
      a[j] += a[j - 1];
    }

    for (int j = 0; j < x; j++)
    {
      if (l - a[j + 1] > sum - a[j])
        continue;
      int L = l - sum + a[j] + 1, R = a[j + 1];
      if (L <= R)
        v.pb({L, R});
    }
  }

  if (v.empty())
    cout << 0 << endl;
  else
  {
    sort(v.begin(), v.end());

    int ans = 0;
    int L = v[0].fi, R = v[0].sc;
    for (int i = 1; i < v.size(); i++)
    {
      if (v[i].fi > R)
      {
        ans += R - L + 1;
        L = v[i].fi;
        R = v[i].sc;
      }
      else
        R = max(R, v[i].sc);
    }

    ans += R - L + 1;

    cout << ans << endl;
  }
}

Compilation message (stderr)

lasers.cpp: In function 'int main()':
lasers.cpp:57:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     for (int i = 1; i < v.size(); i++)
      |                     ~~^~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...