QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#304171#5080. Folding Stickwarner1129#AC ✓9ms6952kbC++202.1kb2024-01-13 15:55:142024-01-13 15:55:15

Judging History

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

  • [2024-01-13 15:55:15]
  • 评测
  • 测评结果:AC
  • 用时:9ms
  • 内存:6952kb
  • [2024-01-13 15:55:14]
  • 提交

answer

#include <bits/stdc++.h>
 
using namespace std;

template<ranges::range T, class = enable_if_t<!is_convertible_v<T, string_view>>>
istream& operator>>(istream &s, T &&v) { for (auto &&x : v) s >> x; return s; }
template<ranges::range T, class = enable_if_t<!is_convertible_v<T, string_view>>>
ostream& operator<<(ostream &s, T &&v) { for (auto &&x : v) s << x << ' '; return s; }
 
#ifdef LOCAL
template<class... T> void dbg(T... x) { char e{}; ((cerr << e << x, e = ' '), ...); }
#define debug(x...) dbg(#x, '=', x, '\n')
#else
#define debug(...) ((void)0)
#endif
 
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define ff first
#define ss second
 
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using Pt = pair<double, double>;
 
template<class T> inline constexpr T inf = numeric_limits<T>::max() / 2;
constexpr int mod = 1e9 + 7, inv2 = (mod + 1) / 2;
constexpr double eps = 1e-9;
 
template<class T> bool chmin(T &a, T b) { return (b < a and (a = b, true)); }
template<class T> bool chmax(T &a, T b) { return (a < b and (a = b, true)); }

void solve() {
    int n;
    cin >> n;

    vector<i64> A(n);
    cin >> A;

    vector<i64> dp(n);
    dp[0] = A[0];
    
    partial_sum(all(A), A.begin());

    vector<pair<i64, int>> stk{pair(dp[0] + A[0], 0)};
    for (int i = 1; i < n; i++) {
        dp[i] = A[i];
        
        auto it = upper_bound(all(stk), pair{A[i], inf<int>});
        if (it != stk.begin()) {
            it--;
            chmin(dp[i], A[i] - A[it->ss]);
        }

        while (stk.size() and stk.back().ff >= dp[i] + A[i]) {
            stk.pop_back();
        }
        stk.emplace_back(dp[i] + A[i], i);
    }
    debug(dp);

    i64 ans = dp[n - 1];
    for (int i = 0; i < n; i++) {
        chmin(ans, max(dp[i], A[n - 1] - A[i]));
    }

    cout << ans << '\n';
}
 
signed main() {
    cin.tie(0)->sync_with_stdio(false);
    cin.exceptions(cin.failbit);
    int T = 1;
    // cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3588kb

input:

4
3 2 2 3

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

5
1 1 1 1 1

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3484kb

input:

7
1 3 2 3 4 2 2

output:

6

result:

ok single line: '6'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3820kb

input:

9
5 6 3 4 8 8 2 2 5

output:

9

result:

ok single line: '9'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3748kb

input:

10
5 6 3 4 8 6 2 1 8 5

output:

9

result:

ok single line: '9'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3532kb

input:

10
5 8 1 2 6 8 4 3 6 5

output:

14

result:

ok single line: '14'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

3
4 2 1

output:

4

result:

ok single line: '4'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3748kb

input:

14
7 2 2 2 2 3 4 1 3 5 4 3 1 6

output:

8

result:

ok single line: '8'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3528kb

input:

35
46 93 64 27 72 55 77 11 17 17 79 83 74 26 32 101 54 112 92 111 77 60 51 19 105 11 68 7 100 49 88 54 106 80 57

output:

366

result:

ok single line: '366'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

150
87 121 113 120 23 32 107 92 107 40 61 29 100 120 30 62 61 53 103 40 110 56 16 38 12 55 11 71 109 26 60 72 19 121 74 97 11 87 117 32 58 40 104 91 101 118 19 59 79 21 40 111 100 36 105 58 122 61 33 75 66 11 65 97 84 28 90 18 76 68 70 58 112 100 95 28 61 25 24 110 93 117 80 119 105 52 66 66 101 77 ...

output:

765

result:

ok single line: '765'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3776kb

input:

200
52 59 17 69 83 28 76 102 79 67 66 19 14 114 28 50 68 88 92 23 84 38 71 51 77 76 30 82 67 18 34 41 92 23 72 35 27 94 96 74 12 92 32 60 56 42 123 38 14 99 20 83 16 111 47 101 33 34 81 111 123 108 53 45 73 59 11 26 65 59 111 86 81 73 86 106 101 37 109 56 91 91 26 77 122 99 118 42 43 103 118 19 116 ...

output:

842

result:

ok single line: '842'

Test #12:

score: 0
Accepted
time: 1ms
memory: 3828kb

input:

9999
96 57 105 94 47 39 95 44 103 98 84 99 94 109 65 83 113 102 57 67 13 81 113 31 123 55 27 76 74 94 12 40 88 91 52 78 60 76 118 43 92 102 13 118 76 47 64 99 80 83 108 14 120 16 12 105 82 24 102 99 52 121 81 72 14 74 108 58 117 24 72 14 56 58 122 50 70 114 87 60 61 21 54 58 103 56 75 51 112 27 23 5...

output:

6191

result:

ok single line: '6191'

Test #13:

score: 0
Accepted
time: 2ms
memory: 3948kb

input:

19999
364 153 315 275 342 148 43 15 31 494 383 145 452 419 49 244 487 500 394 168 130 300 285 420 304 437 302 515 88 318 13 18 169 156 151 162 259 487 360 63 143 251 245 330 175 429 145 62 158 195 268 33 88 399 134 373 463 510 402 15 244 498 200 82 185 314 360 75 187 327 291 383 67 492 175 298 394 4...

output:

35836

result:

ok single line: '35836'

Test #14:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

10
72 16900 3273 13695 13698 18297 6723 3013 11727 1900

output:

28033

result:

ok single line: '28033'

Test #15:

score: 0
Accepted
time: 9ms
memory: 6728kb

input:

100000
1511 6583 419 6978 9102 9356 1176 4709 2333 5984 4834 4643 2167 7795 2260 8768 7907 6309 7623 6207 2867 8219 7096 3982 3431 8783 6193 220 6832 9494 9386 9407 607 4057 54 4566 10171 8780 8632 1031 6272 3391 3605 5147 3625 1180 9275 9111 4943 4997 9918 2845 9728 4924 990 338 7311 4335 3658 2454...

output:

1566426

result:

ok single line: '1566426'

Test #16:

score: 0
Accepted
time: 3ms
memory: 6728kb

input:

100000
20000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

36000

result:

ok single line: '36000'

Test #17:

score: 0
Accepted
time: 0ms
memory: 3504kb

input:

4
10 11 11 1

output:

11

result:

ok single line: '11'

Test #18:

score: 0
Accepted
time: 8ms
memory: 6952kb

input:

100000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

36000

result:

ok single line: '36000'

Test #19:

score: 0
Accepted
time: 0ms
memory: 3540kb

input:

30
7 8 15 15 15 20 25 28 36 36 42 44 53 54 56 61 63 69 69 71 74 83 91 99 102 108 115 116 118 126

output:

126

result:

ok single line: '126'

Test #20:

score: 0
Accepted
time: 6ms
memory: 6764kb

input:

100000
3 5 6 15 23 30 38 44 51 59 64 73 78 82 89 97 97 103 110 115 121 126 135 140 149 151 151 160 163 167 176 180 182 187 191 196 199 202 205 210 214 223 227 232 239 244 245 254 260 263 267 268 276 285 293 296 301 310 318 327 331 335 343 343 344 347 350 356 359 364 370 378 384 386 390 392 396 396 4...

output:

3230521

result:

ok single line: '3230521'

Test #21:

score: 0
Accepted
time: 0ms
memory: 3764kb

input:

50
19799 18740 18718 17504 17208 16816 16668 15755 15006 14203 13902 13287 12522 11547 10358 9189 9018 8664 8118 7986 7296 6345 6167 6060 5564 5278 4684 4044 3509 3028 2636 2444 1839 1226 1106 346 18872 17974 17716 16674 16366 15548 15227 15187 14074 13671 13104 12354 11823 11572

output:

90073

result:

ok single line: '90073'

Test #22:

score: 0
Accepted
time: 9ms
memory: 6688kb

input:

100000
19989 19988 19986 19979 19975 19971 19959 19952 19949 19937 19931 19923 19918 19915 19914 19907 19903 19899 19891 19891 19888 19887 19879 19871 19863 19862 19860 19851 19840 19839 19828 19819 19817 19810 19805 19804 19799 19798 19798 19796 19793 19793 19785 19774 19769 19757 19752 19749 19743...

output:

3343362

result:

ok single line: '3343362'

Test #23:

score: 0
Accepted
time: 8ms
memory: 6876kb

input:

99999
1 1 3 1 2 3 1 3 2 2 1 1 1 2 2 3 3 2 3 3 3 3 1 1 2 3 1 2 3 1 1 2 3 2 2 2 2 2 2 1 1 1 3 3 2 2 1 1 3 1 2 3 3 3 1 2 1 2 3 3 2 2 2 1 1 3 1 2 1 3 2 2 2 2 2 3 1 2 1 1 1 3 1 2 2 2 3 1 3 3 2 3 2 3 3 2 1 3 1 2 3 3 2 3 2 2 2 2 1 2 1 2 3 1 3 3 2 1 2 3 2 3 3 2 3 3 1 1 2 3 2 3 2 2 2 1 1 3 2 2 2 2 3 2 1 2 1 ...

output:

38003

result:

ok single line: '38003'

Test #24:

score: 0
Accepted
time: 8ms
memory: 6720kb

input:

99998
1 1 3 1 3 1 1 2 2 2 2 2 2 2 1 3 1 3 2 2 3 3 2 3 1 1 2 2 1 3 1 1 1 2 2 1 1 1 1 3 1 2 3 2 2 3 3 3 1 2 3 1 1 1 2 3 3 1 2 1 3 1 1 2 2 2 3 2 3 2 2 3 1 2 1 3 2 2 1 3 3 2 1 3 1 2 1 2 3 2 1 2 2 1 2 1 1 3 1 1 3 1 1 1 1 3 1 3 2 3 2 1 3 2 2 2 3 3 2 2 3 2 2 3 2 1 1 1 2 3 3 3 2 3 1 2 2 3 1 2 3 2 3 3 2 3 1 ...

output:

37779

result:

ok single line: '37779'

Test #25:

score: 0
Accepted
time: 9ms
memory: 6724kb

input:

100000
1 1 3 1 3 3 1 2 3 2 3 3 3 1 1 2 1 1 3 3 2 2 2 1 3 3 2 2 1 1 2 3 3 1 3 2 1 2 1 2 2 2 2 1 3 1 1 3 3 3 1 3 1 2 1 1 2 1 3 2 2 1 1 3 3 2 1 1 1 1 1 2 1 1 2 3 3 3 1 2 1 1 2 3 1 1 2 1 3 3 3 2 2 3 1 1 3 2 1 3 3 1 2 2 1 1 2 1 2 2 3 2 3 2 3 1 1 2 3 1 1 3 2 3 1 1 2 1 2 3 2 3 2 2 3 1 1 2 2 2 1 3 3 1 2 2 2...

output:

36664

result:

ok single line: '36664'

Test #26:

score: 0
Accepted
time: 9ms
memory: 6828kb

input:

99889
11295 17088 17664 16236 15038 16260 17011 19396 10420 12902 14445 12290 14929 13624 12072 16414 11952 19340 19696 17710 15033 18276 12428 16782 14507 11881 17904 11155 13160 16208 10930 11772 13104 14506 17243 12858 18643 14235 15905 12866 15153 15133 19235 15809 12180 18949 15973 10528 14593 ...

output:

4144015

result:

ok single line: '4144015'

Test #27:

score: 0
Accepted
time: 9ms
memory: 6904kb

input:

99199
12958 15770 11023 19231 12276 16117 15616 13973 16212 16495 14697 11942 11425 14328 12922 16910 10822 16131 11260 18679 12821 10985 10031 15500 11852 14705 17747 18670 10538 14750 11082 12471 13344 18330 17886 16861 16442 11154 10096 10106 19008 15889 14177 14281 12936 19297 19780 17459 19327 ...

output:

4161319

result:

ok single line: '4161319'

Test #28:

score: 0
Accepted
time: 1ms
memory: 3644kb

input:

2901
10008 10001 10001 10010 10000 10001 10007 10005 10000 10004 10008 10007 10003 10010 10002 10004 10007 10001 10006 10007 10008 10007 10003 10001 10002 10001 10008 10002 10001 10006 10006 10008 10008 10004 10003 10001 10003 10006 10004 10008 10006 10004 10008 10000 10002 10004 10001 10001 10004 1...

output:

490229

result:

ok single line: '490229'

Test #29:

score: 0
Accepted
time: 1ms
memory: 3764kb

input:

3058
10004 10008 10006 10009 10003 10002 10010 10005 10003 10009 10003 10007 10008 10009 10010 10005 10001 10006 10000 10002 10004 10005 10000 10004 10006 10001 10002 10005 10004 10007 10000 10001 10009 10010 10004 10004 10001 10002 10001 10005 10007 10002 10003 10005 10008 10000 10005 10009 10000 1...

output:

500279

result:

ok single line: '500279'

Test #30:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

9
3 1 3 1 2 2 2 2 1

output:

4

result:

ok single line: '4'

Test #31:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

11
3 1 3 1 2 2 2 2 1 3 2

output:

4

result:

ok single line: '4'

Test #32:

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

input:

99999
2 2 3 3 3 1 4 2 2 4 3 1 3 1 1 3 2 3 3 3 3 4 1 1 1 3 3 1 1 4 4 4 3 3 4 4 2 2 3 2 2 2 2 3 1 4 2 2 3 4 2 3 3 1 2 1 1 2 2 3 2 4 3 2 4 2 4 2 2 2 3 1 3 1 2 4 2 4 1 3 3 3 1 4 4 2 3 3 2 2 2 1 4 3 1 3 4 4 4 1 1 2 4 1 2 4 4 4 1 2 3 3 2 1 4 3 4 3 1 4 4 3 3 2 1 3 1 1 4 4 3 1 1 2 1 1 1 4 4 4 2 2 3 4 3 2 2 ...

output:

38337

result:

ok single line: '38337'

Test #33:

score: 0
Accepted
time: 0ms
memory: 6776kb

input:

99998
4 4 3 3 4 3 1 2 1 4 3 1 3 2 2 2 4 1 2 4 2 4 4 2 3 4 4 4 1 3 3 3 2 4 1 2 3 2 2 3 3 3 1 3 3 3 2 1 3 1 4 1 3 1 2 4 3 3 4 1 4 3 4 4 4 2 2 2 4 4 3 4 4 2 1 1 2 1 3 1 3 3 2 3 2 1 1 1 2 3 1 3 2 4 4 1 3 1 3 1 3 4 1 4 3 3 1 3 2 3 3 1 3 2 4 4 3 4 4 1 4 1 3 4 1 2 2 3 3 2 3 2 3 3 3 2 2 1 3 2 1 2 1 3 4 3 4 ...

output:

38336

result:

ok single line: '38336'