QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#738569#7646. 优惠购物SkyMaths15 49ms7808kbC++142.4kb2024-11-12 19:24:242024-11-12 19:24:32

Judging History

你现在查看的是最新测评结果

  • [2024-11-12 19:24:32]
  • 评测
  • 测评结果:15
  • 用时:49ms
  • 内存:7808kb
  • [2024-11-12 19:24:24]
  • 提交

answer

// #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define rep(i,l,r) for (int i(l), i##end(r); i <= i##end; ++i)
#define per(i,r,l) for (int i(r), i##end(l); i >= i##end; --i)
#define ll long long
#define fi first
#define se second
#define eb emplace_back
#define File(filename) freopen(filename".in", "r", stdin), freopen(filename".out", "w", stdout)
#define clr(arr) memset(arr, 0, sizeof(arr))
using namespace std;
template <typename Tx> inline void read(Tx &x) {x = 0; bool f = 0; char ch = getchar(); while (ch < '0' || ch > '9') f ^= ch == '-', ch = getchar(); while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar(); if (f) x = -x;}
template <typename Tx, typename ...Ty> inline void read(Tx &x, Ty &...y) {read(x); read(y...);}
template <typename Tx> inline void O_write(Tx x) {if (x > 9) O_write(x / 10); putchar('0' + x % 10);}
template <typename Tx> inline void write(Tx x, char ch = '\n') {O_write(x < 0 ? (putchar('-'), -x) : x); putchar(ch);}
template <typename T> inline void cmax(T &x, T y) {if (x < y) x = y;}
template <typename T> inline void cmin(T &x, T y) {if (x > y) x = y;}
namespace Main {

const int N = 1e6 + 9;

int n, m, c;
ll a[N], b[N], x[N], s[N];

inline void skymaths() {
    read(n, m, c);

    rep (i, 1, n) read(a[i]);
    rep (i, 1, n) read(b[i]);
    s[0] = m;
    rep (i, 1, n) {
        s[i] = s[i - 1] + a[i] / c;
    }
    // s'[i] = s[i] - x[i + 1]
    per (i, n, 1) {
        ll t = min(b[i], a[i] % c);
        rep (j, i - 1, n) cmin(t, s[j]);
        x[i] += t;
        rep (j, i - 1, n) s[j] -= t;
    }
    per (i, n, 1) {
        ll t = min((b[i] - x[i]) / c, s[i - 1] / c);
        rep (j, i, n) cmin(t, s[j] / (c + 1));
        x[i] += t * c;
        s[i - 1] -= t * c;
        rep (j, i, n) s[j] -= t * (c + 1);
    }

    rep (_, 1, n) {
        ll p = 0;
        ll z = -1;
        rep (i, 1, n) {
            ll t = min(b[i] - x[i], s[i - 1]);
            rep (j, i, n) cmin(t, s[j] - 1);
            if (t > z) p = i, z = t;
        }
        if (z <= 0) break;
        x[p] += z;
        s[p - 1] -= z;
        rep (i, p, n) s[i] -= (z + 1);
    }

    ll ans(0);
    rep (i, 1, n) ans += a[i] - x[i];
    
    rep (i, 1, n) x[i] = 0;

    write(ans);
}

signed main() {
    // freopen("a.in", "r", stdin);
    int T = 1;
    read(T);
    rep (Tid, 1, T) {
        skymaths();
    }
    return 0;
} } signed main() { Main::main(); return 0;}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 1ms
memory: 7732kb

input:

5
10 9 8
10 5 1 2 10 9 2 9 8 8
5 3 1 1 7 2 2 1 3 0
10 1 5
3 2 6 10 5 10 1 4 8 1
1 2 5 6 2 3 1 3 6 1
10 6 10
5 4 9 5 4 10 8 5 2 4
2 4 2 5 1 1 7 5 0 0
10 5 10
6 2 7 4 3 8 10 5 5 4
1 0 6 3 3 5 4 5 0 0
10 6 12
6 8 7 3 1 4 10 2 9 10
0 3 1 3 1 3 1 0 4 7

output:

51
42
49
48
54

result:

ok 5 lines

Test #2:

score: 5
Accepted
time: 1ms
memory: 7728kb

input:

5
10 8 16
2 4 3 3 10 1 8 7 1 10
2 1 1 2 9 0 2 2 1 0
10 6 5
1 8 7 1 5 1 2 5 5 2
1 6 0 0 4 1 0 0 0 0
10 9 9
10 5 3 1 2 1 9 3 1 10
3 0 2 0 2 1 8 2 1 9
10 4 8
1 4 7 9 2 4 7 9 4 6
1 3 2 4 1 0 4 0 4 2
10 10 7
5 1 6 4 7 5 10 6 2 7
2 0 3 4 5 4 7 4 2 1

output:

41
29
34
47
41

result:

ok 5 lines

Test #3:

score: 5
Accepted
time: 0ms
memory: 7792kb

input:

5
10 2 18
2 7 3 1 2 2 10 3 10 9
1 7 2 0 1 1 8 2 8 8
10 6 17
10 7 9 6 8 2 9 5 5 4
10 1 5 5 3 0 4 1 2 2
10 5 10
1 6 3 8 7 7 7 9 7 4
0 3 2 4 1 0 5 5 4 2
10 2 7
6 2 9 9 3 8 7 8 10 10
1 0 8 3 2 2 0 2 1 2
10 6 12
7 10 8 1 2 4 7 8 3 7
6 10 1 0 0 4 0 8 1 0

output:

47
59
54
64
51

result:

ok 5 lines

Subtask #2:

score: 0
Time Limit Exceeded

Test #4:

score: 0
Time Limit Exceeded

input:

1
1000000 75424149 4
15519624 393474467 66570532 20552964 884794646 633920424 885627436 891022137 207531470 263467015 853563838 909020263 225156643 843397191 555130236 28501962 70380880 400094075 351542363 118716292 772000502 495729611 777038576 845271464 346378405 179347308 90713310 683636539 92786...

output:


result:


Subtask #3:

score: 10
Accepted

Dependency #1:

100%
Accepted

Test #7:

score: 10
Accepted
time: 5ms
memory: 7792kb

input:

1
500 225 2
0 0 2 1 2 1 4 0 0 0 0 0 2 1 2 0 0 1 0 0 1 1 2 0 2 2 3 1 0 0 2 2 0 1 1 2 1 3 1 3 2 0 0 1 2 0 2 0 0 1 1 0 1 1 1 0 1 0 2 3 0 0 1 3 1 0 2 2 1 1 4 1 1 2 1 1 0 3 2 0 0 0 1 3 0 1 0 1 2 1 0 0 2 1 1 1 2 3 2 2 2 1 1 2 2 0 0 1 1 0 0 1 0 1 1 0 1 3 1 2 0 2 2 1 1 2 0 1 0 4 2 0 0 0 0 1 4 1 0 1 0 1 0 0 ...

output:

231

result:

ok single line: '231'

Test #8:

score: 10
Accepted
time: 2ms
memory: 7800kb

input:

1
500 253 10
1 2 1 1 0 0 1 3 3 1 0 0 0 0 0 0 0 2 1 0 0 2 1 0 0 0 2 0 0 1 2 1 0 2 2 1 1 2 1 0 2 1 0 0 0 1 0 2 2 0 1 0 0 1 0 0 1 1 1 0 1 1 0 1 2 0 1 0 0 1 1 1 0 0 0 1 2 2 1 1 1 0 3 1 0 0 0 1 0 1 1 4 3 1 0 0 0 1 0 1 3 1 1 1 1 4 1 0 0 0 1 1 1 2 2 0 0 3 0 0 1 0 2 2 1 0 2 0 1 0 2 0 0 1 1 0 2 1 0 1 1 1 0 0...

output:

278

result:

ok single line: '278'

Test #9:

score: 10
Accepted
time: 1ms
memory: 7664kb

input:

100
5 3 11
0 1 3 0 1
0 0 0 0 0
5 3 11
0 0 2 2 1
0 0 0 1 1
5 3 10
2 1 0 1 1
2 1 0 0 1
5 3 11
2 2 0 0 1
0 0 0 0 1
5 2 11
0 0 4 0 1
0 0 3 0 1
5 5 10
2 0 0 0 3
1 0 0 0 1
5 5 11
3 1 1 0 0
3 0 1 0 0
5 2 11
0 1 2 0 2
0 1 2 0 0
5 4 10
2 1 1 1 0
0 1 0 1 0
5 4 10
1 1 1 2 0
1 0 1 2 0
5 2 11
2 0 3 0 0
1 0 3 0 0...

output:

5
3
2
4
3
3
1
3
3
1
3
3
4
1
3
3
1
4
3
4
2
5
3
4
4
2
4
2
2
3
4
4
3
3
2
3
0
2
3
4
4
3
3
2
2
4
5
2
4
4
3
3
4
3
4
2
3
3
3
2
4
4
5
2
4
2
4
2
3
4
4
4
4
2
2
1
2
4
1
3
4
3
3
0
3
5
5
2
4
3
2
3
4
3
3
4
2
3
5
3

result:

ok 100 lines

Test #10:

score: 10
Accepted
time: 1ms
memory: 7716kb

input:

50
10 4 11
2 0 0 2 0 0 1 1 4 0
2 0 0 1 0 0 1 1 2 0
10 9 11
0 1 2 0 1 1 1 2 2 0
0 0 2 0 1 0 1 1 2 0
10 4 11
1 2 1 3 0 0 2 0 1 0
1 0 1 3 0 0 0 0 0 0
10 9 10
1 0 1 1 2 1 0 1 2 1
1 0 0 0 2 0 0 1 0 0
10 7 11
0 3 0 2 3 0 0 2 0 0
0 3 0 0 3 0 0 2 0 0
10 9 10
0 1 0 1 1 1 1 2 1 2
0 0 0 0 1 1 1 0 0 0
10 6 11
0...

output:

6
3
6
6
3
7
7
6
2
7
3
6
8
4
6
5
3
5
8
8
6
5
7
8
8
8
4
8
5
4
3
5
7
5
4
8
5
5
7
6
7
6
7
8
8
4
2
4
7
6

result:

ok 50 lines

Subtask #4:

score: 0
Time Limit Exceeded

Dependency #3:

100%
Accepted

Test #11:

score: 10
Accepted
time: 1ms
memory: 7744kb

input:

60
10 17 2
14 8 11 5 9 14 9 9 8 13
12 3 8 5 9 1 0 4 2 10
10 13 2
11 11 10 15 8 12 7 8 8 10
11 6 3 8 2 4 7 8 1 4
10 7 2
18 6 15 6 11 6 12 8 9 9
15 0 9 0 5 6 0 6 4 3
10 4 3
12 8 16 11 9 5 6 9 10 14
0 0 5 7 8 1 6 2 1 5
10 23 3
10 14 11 7 9 7 7 12 17 6
5 8 1 5 5 7 7 1 4 3
10 27 3
13 7 11 12 11 12 10 9 9...

output:

57
60
64
75
60
55
68
67
62
76
76
69
71
61
73
60
54
62
62
67
61
71
75
64
63
73
73
56
65
67
63
40
40
46
57
58
53
64
64
46
42
30
39
46
61
54
55
48
64
51
55
57
57
73
40
63
56
70
55
38

result:

ok 60 lines

Test #12:

score: 10
Accepted
time: 1ms
memory: 7680kb

input:

60
10 4 2
6 14 13 9 5 12 14 12 8 7
2 11 3 3 5 2 11 1 3 2
10 14 3
12 11 5 11 13 12 14 5 9 8
12 9 4 11 2 7 4 4 1 3
10 39 3
8 11 9 17 4 16 7 6 15 7
8 2 9 8 3 12 7 1 2 2
10 4 2
9 15 12 11 10 8 6 7 10 12
9 2 6 3 8 1 3 3 4 0
10 4 2
13 10 9 8 7 6 15 11 15 6
8 3 7 2 2 5 0 0 7 2
10 18 3
12 9 8 8 9 9 11 12 9 ...

output:

68
66
49
70
71
64
71
67
73
69
66
65
66
69
60
66
76
64
68
69
68
67
77
67
60
71
76
67
62
65
52
67
48
73
61
51
48
71
40
60
50
49
60
49
66
52
35
68
52
45
32
69
64
56
48
66
58
67
57
50

result:

ok 60 lines

Test #13:

score: 10
Accepted
time: 49ms
memory: 7808kb

input:

6
1000 129 2
0 1 1 0 3 2 0 0 3 0 0 1 0 1 1 0 0 0 0 3 0 1 2 1 3 1 2 2 1 1 1 0 1 1 0 0 1 1 2 1 2 0 1 0 0 1 1 2 1 1 0 0 1 0 1 0 1 0 0 1 2 1 2 2 0 0 0 0 1 1 1 1 0 0 1 0 3 1 0 1 1 2 2 1 0 1 1 3 0 1 1 2 0 0 1 1 0 1 1 2 2 0 1 0 1 1 1 0 1 1 1 1 1 1 0 0 1 0 1 0 1 0 0 1 2 1 1 2 2 1 0 1 1 0 2 1 0 0 2 0 0 4 1 1...

output:

648
569
721
517
613
515

result:

ok 6 lines

Test #14:

score: 10
Accepted
time: 42ms
memory: 7720kb

input:

1
4000 1097 3
4 0 2 3 1 0 2 3 0 3 2 2 1 0 1 3 3 1 0 3 3 0 0 0 0 1 1 1 3 1 1 3 1 3 0 0 5 2 3 3 2 1 2 3 3 1 2 0 0 0 1 2 2 2 2 3 4 1 0 0 1 1 1 0 0 2 0 2 0 2 0 1 3 2 1 1 3 1 4 1 2 1 1 1 0 3 1 1 1 0 1 1 1 1 0 1 1 1 0 2 2 4 1 1 1 2 3 1 1 0 2 1 1 2 2 0 1 1 1 1 3 2 1 0 2 2 4 3 2 1 2 2 0 0 0 3 0 4 1 3 3 0 1 ...

output:

4106

result:

ok single line: '4106'

Test #15:

score: 0
Time Limit Exceeded

input:

1
6000 3193 3
0 0 2 0 1 0 1 0 2 0 1 1 1 1 1 2 1 3 0 0 0 0 2 3 0 2 2 1 1 0 0 4 0 0 1 1 0 1 0 2 0 1 3 2 1 1 1 0 1 0 1 2 1 0 0 1 1 1 1 1 2 0 2 0 1 2 2 1 3 0 0 0 1 0 1 0 0 3 0 0 2 1 0 1 1 0 0 1 2 0 3 1 1 3 1 2 1 1 0 1 1 0 0 2 0 2 2 0 1 0 0 0 1 1 2 1 0 0 0 2 1 0 0 0 2 0 0 1 0 0 1 1 1 2 0 0 2 0 1 2 1 4 1 ...

output:


result:


Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Time Limit Exceeded

Test #24:

score: 15
Accepted
time: 0ms
memory: 7716kb

input:

600
10 21 2
1434256 1792820 8964100 10756920 6454152 717128 9681228 7529844 7171280 10398356
1075692 1075692 1434256 10039792 358564 717128 717128 5737024 3227076 1792820
10 5 4
5500368 6875460 4125274 687544 5500368 4469049 4125276 2750183 9969416 5156593
4469049 3781503 687546 0 1718865 343773 0 2...

output:

46254742
42284068
28465970
36815342
18797080
16608540
59809954
55963386
98157466
99455211
58990996
4474138
59994584
40677040
117326435
26562075
51644186
94269994
59007134
38720301
55628210
40921356
30237996
20727720
83424160
84045033
66629574
18910773
84890678
72094414
49832625
110722258
1360310
120...

result:

ok 600 lines

Test #25:

score: 15
Accepted
time: 47ms
memory: 7676kb

input:

2000
10 19 8
6876660 3438330 687664 11690316 2062992 2062992 2062992 687666 687666 1375330
6876660 2062998 0 5501328 0 0 0 687666 687666 687666
10 15 3
4087344 17371212 15327539 13283868 16349376 9196524 5109180 16349376 7152852 2043672
4087344 15327540 12262032 0 0 2043672 4087344 7152852 4087344 2...

output:

28194264
79703196
11089764
62810972
41503410
26040944
91781613
70998177
18207816
55013070
7566990
59042320
17974772
28271700
5677866
9725704
1225548
29982198
17802890
343025
45817818
73177656
86443886
15493720
79583772
32225792
56508512
62526146
37987857
105719026
44344500
16914540
65295200
2337432
...

result:

ok 2000 lines

Test #26:

score: 0
Time Limit Exceeded

input:

10
20000 5 2
7 8 3 4 8 6 4 4 10 3 7 10 9 5 10 10 2 4 1 9 3 5 5 4 5 10 2 7 4 5 8 5 5 6 8 0 6 10 7 4 8 10 9 4 4 8 2 9 1 10 9 6 10 6 0 0 3 9 7 8 9 7 2 6 0 2 6 10 2 3 8 7 4 2 4 3 1 4 10 8 9 9 0 6 6 6 9 6 9 3 5 7 2 10 4 7 4 0 1 4 6 8 10 0 2 4 8 3 9 7 1 6 2 3 0 10 4 10 7 6 2 6 2 1 3 4 6 6 6 5 0 7 9 4 6 4 ...

output:


result:


Subtask #7:

score: 0
Skipped

Dependency #6:

0%

Subtask #8:

score: 0
Skipped

Dependency #6:

0%

Subtask #9:

score: 0
Skipped

Dependency #2:

0%