///*** Sown_Vipro ***///
/// ->TUYEN QUOC GIA<- ///
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("popcnt")
#define F first
#define S second
#define pb push_back
#define pi pair<int, int>
#define pii pair<int, pair<int, int> >
#define all(a) a.begin(), a.end()
#define FOR(i, a, b) for(int i = a; i <= b; ++i)
#define REP(i, a, b) for(int i = a; i >= b; --i)
#define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
#define out(name) if(fopen(name, "w")) freopen(name, "w", stdout);
#define int long long
const int N = 1e6 + 5, MAX = 1e6, oo = 1e9 + 5, MOD = 1e9 + 7;
int L, R, l, res;
int n[N], t[N];
vector<int> s[N];
priority_queue<pair<long long, int> > A, B;
void solve(){
cin >> L >> R;
l = L;
FOR(i, 1, R){
cin >> n[i];
s[i].pb(0);
FOR(j, 1, n[i]){
s[i].pb(0);
cin >> s[i][j];
s[i][j] += s[i][j - 1];
}
A.push({s[i][n[i]], i});
t[i] = n[i];
}
do{
int x = A.top().F, i = A.top().S;
if(l > x) res += l - x;
--t[i];
// cout << l << " " << x << " " << s[i][n[i]] << " " << res << "\n";
l = min({l, x, L - s[i][n[i]] + s[i][t[i]]});
A.pop();
A.push({s[i][t[i]], i});
}while(A.top().F > 0);
if(l > 0) res += l;
cout << L - res;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
inp("in.txt");
int t = 1;
// cin >> t;
while(t--){
solve();
}
}
Compilation message (stderr)
lasers.cpp: In function 'int main()':
lasers.cpp:17:47: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | #define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~
lasers.cpp:58:5: note: in expansion of macro 'inp'
58 | inp("in.txt");
| ^~~
# | 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... |