# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1007834 | christinelynn | Lasers (NOI19_lasers) | C++17 | 69 ms | 12160 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define piii pair<pair<int,int>,pair<int,int>>
#define pip pair<int,pair<int,int>>
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int ans = 0;
int n, q; cin >> n >> q;
vector<pair<int,int>>v;
for(int i = 1; i <= q; i++){
int x; cin >> x;
int a[x+5];
int tmp = 0;
for(int i = 1; i <= x; i++){
cin >> a[i]; tmp += a[i];
}
int rem = n - tmp;
int cnt = 0;
int last = 0;
for(int i = 1; i <= x; i++){
last += a[i];
int val = a[i] - rem;
if(val <= 0)continue;
v.pb({last-val+1,last});
}
}
sort(v.begin(),v.end());
int last = 0;
for(int i = 0; i < v.size(); i++){
//cout << "here >> " << v[i].fi << " " << v[i].se << endl;
if(v[i].fi > last){
ans += (v[i].se - v[i].fi + 1);
last = v[i].se;
}
else if(v[i].se > last){
ans += (v[i].se - last);
last = v[i].se;
}
}
cout << ans << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |