#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define all(s) s.begin(), s.end()
#define ok puts("ok")
#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define pi pair < int, int >
#define pii pair < int, pi >
#define next next123
#define left left123
const int N = 3e5 + 7;
const ll INF = 2e18 + 7;
ll t[8 * N], lz[8 * N];
ll cons;
int lf[8 * N], rf[8 * N], tim = 1;
int a[N], b[N], md[N];
int s, m, d, c, n;
void push (int v, int l, int r){
if (l != r){
if (!lf[v]){
lf[v] = ++tim;
rf[v] = ++tim;
}
lz[lf[v]] = min(lz[lf[v]], lz[v]);
lz[rf[v]] = min(lz[rf[v]], lz[v]);
}
t[v] = min(t[v], lz[v]);
lz[v] = INF;
}
void upd (int v, int l, int r, int ql, int qr, ll val){
push(v, l, r);
if (ql <= l && r <= qr){
lz[v] = val;
push(v, l, r);
return;
}
if (r < ql || qr < l)
return;
int mid = (l + r) >> 1;
if (!lf[v]){
lf[v] = ++tim;
rf[v] = ++tim;
}
upd(lf[v], l, mid, ql, qr, val);
upd(rf[v], mid + 1, r, ql, qr, val);
t[v] = min(t[lf[v]], t[rf[v]]);
}
ll get (int v, int l, int r, int ql, int qr){
push(v, l, r);
if (ql <= l && r <= qr)
return t[v];
if (r < ql || qr < l)
return INF;
int mid = (l + r) >> 1;
if (!lf[v]){
lf[v] = ++tim;
rf[v] = ++tim;
}
return min(get(lf[v], l, mid, ql, qr), get(rf[v], mid + 1, r, ql, qr));
}
main(){
cin >> s >> m >> d >> c >> n;
memset(lz, 0x3f3f3f3f, sizeof(lz));
memset(t, 0x3f3f3f3f, sizeof(t));
for (int i = 1; i <= n; i++){
scanf("%d%d", &a[i], &b[i]);
md[i] = (m - a[i]) % d;
md[i] = (d - md[i]) % d;
}
md[0] = (m - s) % d;
md[0] = (d - md[0]) % d;
cons = 1LL * ((m - s + d - 1) / d) * 1LL * c;
upd(1, 0, d, 0, md[0], cons);
upd(1, 0, d, md[0] + 1, d, cons + c);
for (int i = 1; i <= n; i++){
ll v1 = get(1, 0, d, 0, max(0, md[i] - 1)) + c - b[i];
ll v2 = get(1, 0, d, md[i], d) - b[i];
upd(1, 0, d, md[i], md[i], min(v1, v2));
}
cout << -get(1, 0, d, 0, d);
}
Compilation message
koala.cpp:75:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
koala.cpp: In function 'int main()':
koala.cpp:80:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &a[i], &b[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
38400 KB |
Output is correct |
2 |
Correct |
27 ms |
38400 KB |
Output is correct |
3 |
Correct |
27 ms |
38396 KB |
Output is correct |
4 |
Correct |
24 ms |
37884 KB |
Output is correct |
5 |
Correct |
24 ms |
37888 KB |
Output is correct |
6 |
Correct |
24 ms |
37888 KB |
Output is correct |
7 |
Correct |
24 ms |
37888 KB |
Output is correct |
8 |
Correct |
25 ms |
37888 KB |
Output is correct |
9 |
Correct |
27 ms |
38520 KB |
Output is correct |
10 |
Correct |
26 ms |
38272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
94 ms |
41080 KB |
Output is correct |
2 |
Correct |
87 ms |
40824 KB |
Output is correct |
3 |
Correct |
47 ms |
39928 KB |
Output is correct |
4 |
Correct |
83 ms |
40952 KB |
Output is correct |
5 |
Correct |
61 ms |
39800 KB |
Output is correct |
6 |
Correct |
47 ms |
39160 KB |
Output is correct |
7 |
Correct |
82 ms |
40056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
160 ms |
42616 KB |
Output is correct |
2 |
Correct |
235 ms |
49244 KB |
Output is correct |
3 |
Correct |
234 ms |
59096 KB |
Output is correct |
4 |
Runtime error |
237 ms |
118904 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Halted |
0 ms |
0 KB |
- |