QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#532192 | #5080. Folding Stick | xuanbac05 | AC ✓ | 11ms | 8344kb | C++14 | 1.8kb | 2024-08-25 01:14:28 | 2024-08-25 01:14:28 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define endl '\n'
#define MASK(i) (1LL << (i))
#define ull unsigned long long
#define ld long double
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define BIT(x , i) ((x >> (i)) & 1)
#define TASK "task"
#define sz(s) (int) (s).size()
using namespace std;
const int mxN = 5e5 + 227;
const int inf = 1e9 + 277;
const int mod = 1e9 + 7;
const ll infll = 1e18 + 7;
const int base = 307;
const int LOG = 20;
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
int n;
int a[mxN];
int pre[mxN];
int dp[mxN];
void solve()
{
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++) pre[i] = pre[i - 1] + a[i];
memset(dp, 0x3f, sizeof(dp));
dp[0] = 0;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
pq.push({dp[0] + pre[0], 0});
int cur = 0;
for(int i = 1; i < n; i++) {
while(sz(pq) > 0 && pq.top().fi <= pre[i]) {
maximize(cur, pq.top().se);
pq.pop();
}
dp[i] = pre[i] - pre[cur];
pq.push({dp[i] + pre[i], i});
}
int res = pre[n];
for(int i = 1; i < n; i++) {
minimize(res, max(dp[i], pre[n] - pre[i]));
}
cout << res;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen(TASK".inp" , "r" , stdin);
// freopen(TASK".out" , "w" , stdout);
int tc = 1;
//cin >> tc;
while(tc--) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 7560kb
input:
4 3 2 2 3
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5780kb
input:
5 1 1 1 1 1
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 1ms
memory: 7616kb
input:
7 1 3 2 3 4 2 2
output:
6
result:
ok single line: '6'
Test #4:
score: 0
Accepted
time: 0ms
memory: 7616kb
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: 7852kb
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: 2ms
memory: 7616kb
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: 1ms
memory: 7788kb
input:
3 4 2 1
output:
4
result:
ok single line: '4'
Test #8:
score: 0
Accepted
time: 1ms
memory: 5744kb
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: 1ms
memory: 7592kb
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: 7864kb
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: 1ms
memory: 7556kb
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: 2ms
memory: 7636kb
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: 3ms
memory: 7744kb
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: 7624kb
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: 7ms
memory: 8020kb
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: 10ms
memory: 8084kb
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: 1ms
memory: 7556kb
input:
4 10 11 11 1
output:
11
result:
ok single line: '11'
Test #18:
score: 0
Accepted
time: 9ms
memory: 8080kb
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: 1ms
memory: 7820kb
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: 11ms
memory: 8248kb
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: 2ms
memory: 7556kb
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: 11ms
memory: 8248kb
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: 11ms
memory: 8056kb
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: 11ms
memory: 8080kb
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: 10ms
memory: 8136kb
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: 10ms
memory: 6364kb
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: 11ms
memory: 7892kb
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: 0ms
memory: 7844kb
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: 2ms
memory: 7568kb
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: 1ms
memory: 5512kb
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: 7820kb
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: 11ms
memory: 8076kb
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: 11ms
memory: 8344kb
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'