제출 #545650

#제출 시각아이디문제언어결과실행 시간메모리
545650balbitLasers (NOI19_lasers)C++14
100 / 100
172 ms13836 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define f first
#define s second
#define pii pair<int, int>

#define MX(a,b) a=max(a,b)
#define MN(a,b) a=min(a,b)
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()

#define REP(i,n) for (int i = 0; i<n; ++i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)
#define pb push_back

#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<"- ", _do(__VA_ARGS__)
template<typename T> void _do( T && x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do( T && x, S && ...y) {cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#define endl '\n'
#endif // BALBIT

const int maxn = 3e5+5;


signed main(){
    ios::sync_with_stdio(0), cin.tie(0);
    bug(1,2);

    int L,n; cin>>L>>n;

    vector<pii> seg;

    REP(rnd,n) {
        int k; cin>>k;
        vector<int> a(k);
        vector<int> ps(k+1);
        int tot = 0;
        REP(i,k) {
            cin>>a[i]; tot += a[i];
            ps[i+1] = ps[i] + a[i];
        }
        REP(i,k) {
            int l = L - (tot - ps[i]) + 1, r = ps[i+1];
            if (l <= r) {
                seg.pb({l,1}); seg.pb({r+1, -1}); bug(l,r);
            }
        }
    }

    sort(ALL(seg));
    int prv = 1;
    int cnt = 0;
    int re = 0;
    for (pii p : seg) {
        if (cnt) {
            re += p.f - prv;
        }
        cnt += p.s;
        prv = p.f;
    }
    cout<<re<<endl;
}
#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...