-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathempty.cpp
60 lines (56 loc) · 1.25 KB
/
empty.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <string>
#include <utility>
#include <sstream>
#include <algorithm>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <math.h>
#include <assert.h>
using namespace std;
#define INF 1000000000
#define LSOne(S) (S & (-S))
#define EPS 1e-9
#define A first
#define B second
#define mp make_pair
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int main() {
freopen("empty.in", "r", stdin);
freopen("empty.out", "w", stdout);
unsigned int n, k;
cin >> n >> k;
unsigned int x, y, a, b;
auto * stalls = new unsigned int[3000001];
memset(stalls, 0, sizeof stalls);
for (int i = 0; i < k; i++) {
cin >> x >> y >> a >> b;
for (int j = 1; j <= y; j++) {
unsigned int stall = ((a%n)*j+b)%n;
stalls[stall] += x;
}
}
unsigned int counter = 0;
for (int i = 0; i < n; i++) {
counter += stalls[i];
if (counter > 0) counter--;
}
for (int i = 0; i < n; i++) {
counter += stalls[i];
if (counter > 0) counter--;
else {
cout << i;
break;
}
}
return 0;
}