QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#51640 | #4585. Greedy Knapsack | eyiigjkn | TL | 213ms | 166136kb | C++14 | 1.4kb | 2022-10-03 10:04:03 | 2022-10-03 10:04:05 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
char buf[1<<21],*p1=buf,*p2=buf,obuf[1<<21],*o=obuf;
#define g()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline ll read(){
ll s=0; int f=1;char c=g();
for(;c<'0'||c>'9';c=g())
if(c=='-')f=-1;
for(;c>='0'&&c<='9';c=g())
s=s*10+c-'0';
return s*f;
}
inline void write(ll x,char c){
static char buf[16];
static int len=-1;
if(x<0)putchar('-'),x=-x;
do buf[++len]=x%10,x/=10;while(x);
while(len>=0)putchar(buf[len--]+'0');
putchar(c);
}
pair<int,int> t[500010];
ll hs[500010],th[500010];
map<int,ll> dp[500010];
int n;
ll solve(int id,ll l){
if(id==n+1) return 0;
if(l>=hs[id]) return th[id];
//cout<<id<<" "<<l<<endl;
if(l<0) return -hs[1];
if(l==0) return 0;
if(dp[id][l]) return dp[id][l];
ll t1=min(l,(ll)t[id].first-1),t2=l-t[id].first;
//cout<<id<<" "<<l<<" "<<t1<<" "<<t2<<endl;
if(t2<0) return dp[id][l]=solve(id+1,t1);
if(t2>=t1) return dp[id][l]=solve(id+1,t2)+t[id].second;
return dp[id][l]=max(solve(id+1,t2)+t[id].second,solve(id+1,t1));
}
int main(){
ll l;
n=read(); l=read();
for(int i=1;i<=n;++i) t[i].first=read();
for(int i=1;i<=n;++i) t[i].second=read();
for(int i=n;i>=1;--i) hs[i]=hs[i+1]+t[i].first,th[i]=th[i+1]+t[i].second;
write(solve(1,l),'\n');
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 7ms
memory: 26972kb
input:
5 10 10 1 2 3 4 1 1 1 1 1
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 6ms
memory: 27184kb
input:
5 10000000000 10 1 2 3 4 30 2 15 7 11
output:
65
result:
ok single line: '65'
Test #3:
score: 0
Accepted
time: 2ms
memory: 27188kb
input:
5 20 4 9 5 1 3 203 175 131 218 304
output:
900
result:
ok single line: '900'
Test #4:
score: 0
Accepted
time: 4ms
memory: 27112kb
input:
1 1 1 1
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 24ms
memory: 44724kb
input:
100000 200000 100000 99998 99996 99994 99992 99990 99988 99986 99984 99982 99980 99978 99976 99974 99972 99970 99968 99966 99964 99962 99960 99958 99956 99954 99952 99950 99948 99946 99944 99942 99940 99938 99936 99934 99932 99930 99928 99926 99924 99922 99920 99918 99916 99914 99912 99910 99908 999...
output:
100002
result:
ok single line: '100002'
Test #6:
score: 0
Accepted
time: 58ms
memory: 73472kb
input:
92455 883403359 82193 96168 42737 25557 5699 8922 41136 82789 26249 74241 57030 29989 41743 78491 37281 60598 23165 51802 13911 88911 55220 25398 60154 2879 14519 61138 16806 15952 83710 44076 43551 41425 11055 3321 59105 34722 60133 13735 36785 73444 92250 3613 35787 10798 35612 9564 42531 49012 83...
output:
881743221
result:
ok single line: '881743221'
Test #7:
score: 0
Accepted
time: 42ms
memory: 74440kb
input:
95787 282807627 71790 93372 34507 85540 25871 70820 42496 67633 50879 43192 861 57228 54094 91534 94590 24032 52665 82236 52010 45017 15045 76804 39159 72380 28162 89590 31125 21390 37395 34002 26585 2985 90847 12060 63128 73061 34524 61847 69734 53329 39554 90867 13357 18202 63266 44796 64191 40066...
output:
287223570
result:
ok single line: '287223570'
Test #8:
score: 0
Accepted
time: 7ms
memory: 41772kb
input:
100000 100001 100000 99998 99996 99994 99992 99990 99988 99986 99984 99982 99980 99978 99976 99974 99972 99970 99968 99966 99964 99962 99960 99958 99956 99954 99952 99950 99948 99946 99944 99942 99940 99938 99936 99934 99932 99930 99928 99926 99924 99922 99920 99918 99916 99914 99912 99910 99908 999...
output:
100001
result:
ok single line: '100001'
Test #9:
score: 0
Accepted
time: 19ms
memory: 44328kb
input:
100000 200000 100000 99998 99996 99994 99992 99990 99988 99986 99984 99982 99980 99978 99976 99974 99972 99970 99968 99966 99964 99962 99960 99958 99956 99954 99952 99950 99948 99946 99944 99942 99940 99938 99936 99934 99932 99930 99928 99926 99924 99922 99920 99918 99916 99914 99912 99910 99908 999...
output:
100002
result:
ok single line: '100002'
Test #10:
score: 0
Accepted
time: 18ms
memory: 44364kb
input:
100000 101603 100000 99998 99996 99994 99992 99990 99988 99986 99984 99982 99980 99978 99976 99974 99972 99970 99968 99966 99964 99962 99960 99958 99956 99954 99952 99950 99948 99946 99944 99942 99940 99938 99936 99934 99932 99930 99928 99926 99924 99922 99920 99918 99916 99914 99912 99910 99908 999...
output:
100001
result:
ok single line: '100001'
Test #11:
score: 0
Accepted
time: 18ms
memory: 43096kb
input:
100000 200000 100000 99998 99996 99994 99992 99990 99988 99986 99984 99982 99980 99978 99976 99974 99972 99970 99968 99966 99964 99962 99960 99958 99956 99954 99952 99950 99948 99946 99944 99942 99940 99938 99936 99934 99932 99930 99928 99926 99924 99922 99920 99918 99916 99914 99912 99910 99908 999...
output:
100002
result:
ok single line: '100002'
Test #12:
score: 0
Accepted
time: 18ms
memory: 43244kb
input:
100000 109258 100000 99998 99996 99994 99992 99990 99988 99986 99984 99982 99980 99978 99976 99974 99972 99970 99968 99966 99964 99962 99960 99958 99956 99954 99952 99950 99948 99946 99944 99942 99940 99938 99936 99934 99932 99930 99928 99926 99924 99922 99920 99918 99916 99914 99912 99910 99908 999...
output:
100001
result:
ok single line: '100001'
Test #13:
score: 0
Accepted
time: 14ms
memory: 43508kb
input:
100000 200000 100000 99997 99994 99991 99988 99985 99983 99980 99977 99974 99972 99969 99966 99963 99961 99958 99955 99952 99950 99947 99944 99942 99939 99936 99933 99930 99928 99926 99923 99920 99917 99914 99912 99909 99906 99904 99901 99899 99897 99894 99891 99889 99886 99883 99881 99879 99876 998...
output:
100003
result:
ok single line: '100003'
Test #14:
score: 0
Accepted
time: 10ms
memory: 43572kb
input:
100000 104441 100000 99997 99994 99991 99988 99985 99983 99980 99977 99974 99972 99969 99966 99963 99961 99958 99955 99952 99950 99947 99944 99942 99939 99936 99933 99930 99928 99926 99923 99920 99917 99914 99912 99909 99906 99904 99901 99899 99897 99894 99891 99889 99886 99883 99881 99879 99876 998...
output:
100002
result:
ok single line: '100002'
Test #15:
score: 0
Accepted
time: 93ms
memory: 103312kb
input:
100000 200000 100000 99993 99987 99978 99972 99965 99960 99954 99948 99944 99941 99931 99929 99919 99910 99904 99894 99888 99877 99871 99863 99858 99852 99850 99843 99839 99829 99823 99812 99807 99795 99791 99780 99774 99766 99755 99750 99742 99731 99725 99718 99711 99702 99696 99693 99689 99678 996...
output:
100002
result:
ok single line: '100002'
Test #16:
score: 0
Accepted
time: 109ms
memory: 108796kb
input:
100000 100220 100000 99993 99987 99978 99972 99965 99960 99954 99948 99944 99941 99931 99929 99919 99910 99904 99894 99888 99877 99871 99863 99858 99852 99850 99843 99839 99829 99823 99812 99807 99795 99791 99780 99774 99766 99755 99750 99742 99731 99725 99718 99711 99702 99696 99693 99689 99678 996...
output:
100001
result:
ok single line: '100001'
Test #17:
score: 0
Accepted
time: 14ms
memory: 27016kb
input:
1 1 2 100000
output:
0
result:
ok single line: '0'
Test #18:
score: 0
Accepted
time: 207ms
memory: 166100kb
input:
100000 200000 100000 99991 99969 99958 99945 99932 99930 99912 99899 99891 99875 99857 99845 99830 99814 99802 99783 99766 99754 99733 99729 99726 99713 99696 99675 99665 99646 99642 99625 99621 99612 99605 99590 99585 99569 99566 99559 99552 99543 99528 99513 99497 99485 99478 99476 99457 99435 994...
output:
100003
result:
ok single line: '100003'
Test #19:
score: 0
Accepted
time: 213ms
memory: 166136kb
input:
100000 100012 100000 99991 99969 99958 99945 99932 99930 99912 99899 99891 99875 99857 99845 99830 99814 99802 99783 99766 99754 99733 99729 99726 99713 99696 99675 99665 99646 99642 99625 99621 99612 99605 99590 99585 99569 99566 99559 99552 99543 99528 99513 99497 99485 99478 99476 99457 99435 994...
output:
100002
result:
ok single line: '100002'
Test #20:
score: 0
Accepted
time: 4ms
memory: 30244kb
input:
100000 104768 42198 63876 70289 97679 99129 99383 99678 99811 99998 99999 99999 99999 100000 100000 100000 12433 8169 3583 222 37 35 9 2 1 1 1 1 1 1 1 65163 81308 91468 93404 95453 99894 99909 99998 99999 99999 99999 99999 100000 100000 100000 23740 11045 4364 2504 1858 1225 1157 1071 505 76 5 2 2 2...
output:
45
result:
ok single line: '45'
Test #21:
score: 0
Accepted
time: 13ms
memory: 30628kb
input:
100000 104790 66799 77219 97947 99699 99727 99872 99924 99980 99989 99991 100000 100000 100000 100000 100000 37709 33873 24409 1661 1157 1097 410 252 224 122 94 14 7 4 4 58118 97059 99179 99309 99324 99815 99829 99932 99933 99942 99971 99972 99992 99995 99995 71139 43023 15781 14293 3416 975 325 163...
output:
104790
result:
ok single line: '104790'
Test #22:
score: 0
Accepted
time: 9ms
memory: 30696kb
input:
100000 200000 59927 72467 75688 92437 93614 94992 97911 98151 98487 98938 99612 99947 99956 99995 99999 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 ...
output:
632
result:
ok single line: '632'
Test #23:
score: 0
Accepted
time: 15ms
memory: 30816kb
input:
100000 200000 86758 94096 95161 96612 98162 98338 98548 99356 99854 99996 99999 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100...
output:
200000
result:
ok single line: '200000'
Test #24:
score: 0
Accepted
time: 4ms
memory: 32436kb
input:
100000 150000 3841 4238 30552 47243 50833 93202 96257 97547 98352 98668 99000 99932 99987 99991 99992 99997 99998 99998 99998 99999 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 ...
output:
3855
result:
ok single line: '3855'
Test #25:
score: 0
Accepted
time: 11ms
memory: 32980kb
input:
100000 150000 10723 22346 89189 97960 99966 99968 99969 99985 99994 99994 99997 99997 99997 99999 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000...
output:
150000
result:
ok single line: '150000'
Test #26:
score: 0
Accepted
time: 3ms
memory: 30052kb
input:
90108 9829673297 3 3 5 5 5 5 5 7 9 11 13 15 15 17 17 19 20 22 22 22 22 24 25 25 25 27 28 30 30 31 32 34 34 35 35 36 37 38 39 41 42 44 44 46 48 49 49 50 51 52 53 55 55 56 57 59 61 63 65 67 69 70 71 72 72 73 75 76 77 77 78 78 80 80 80 80 81 81 81 81 82 82 82 84 86 87 89 89 90 90 90 90 92 94 95 97 99 1...
output:
4514516167
result:
ok single line: '4514516167'
Test #27:
score: 0
Accepted
time: 32ms
memory: 48984kb
input:
98347 2610706974 3 3 3 5 5 6 6 8 9 9 10 10 12 14 14 15 15 16 16 16 16 18 19 19 21 22 24 25 25 26 27 28 29 29 29 29 31 32 33 35 37 39 40 42 42 43 45 47 48 49 51 52 52 52 52 52 53 55 57 58 59 60 61 62 64 66 66 68 70 71 73 73 73 75 75 75 77 79 79 79 79 79 80 80 82 84 85 85 86 88 90 92 93 94 94 96 97 98...
output:
3635495789
result:
ok single line: '3635495789'
Test #28:
score: 0
Accepted
time: 4ms
memory: 30788kb
input:
100000 10000000000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 1...
output:
10000000000
result:
ok single line: '10000000000'
Test #29:
score: 0
Accepted
time: 6ms
memory: 30492kb
input:
96019 5787043590 2 2 2 4 6 7 9 10 11 11 11 13 15 16 16 18 19 19 19 20 22 22 24 25 27 27 27 29 29 29 29 29 30 31 31 31 33 34 36 36 36 38 39 40 41 42 44 46 48 50 50 50 52 53 55 55 57 57 57 58 59 60 60 61 63 63 63 63 65 67 67 68 68 68 68 70 72 72 72 72 74 74 76 76 78 80 80 82 84 85 87 87 89 89 90 92 93...
output:
4809329210
result:
ok single line: '4809329210'
Test #30:
score: 0
Accepted
time: 11ms
memory: 48496kb
input:
98767 3349493383 3 4 5 6 8 8 8 9 11 13 14 15 15 16 17 18 18 18 20 22 22 22 23 23 23 24 24 24 25 25 25 26 26 28 28 28 30 31 31 31 31 32 33 35 37 39 40 42 44 45 47 47 48 49 51 51 53 54 56 56 57 58 59 61 62 64 66 68 69 71 71 72 74 75 77 79 79 81 83 85 87 87 87 87 87 87 89 90 91 91 92 93 95 95 95 95 97 ...
output:
4094678962
result:
ok single line: '4094678962'
Test #31:
score: 0
Accepted
time: 22ms
memory: 47792kb
input:
94867 3025683990 3 3 4 5 7 9 11 13 14 14 14 15 17 17 17 17 17 18 20 22 22 24 25 25 26 28 30 30 30 31 32 34 35 37 37 37 38 38 38 39 40 41 41 43 43 44 44 45 47 47 48 49 50 52 54 54 55 57 59 61 63 65 66 66 66 67 67 67 68 68 69 69 71 71 71 71 72 74 75 77 79 81 81 81 83 83 84 85 87 88 88 90 91 92 92 92 9...
output:
3908322163
result:
ok single line: '3908322163'
Test #32:
score: 0
Accepted
time: 20ms
memory: 50292kb
input:
91659 246378163 3 3 4 4 6 7 7 9 9 9 11 12 14 15 16 16 16 18 18 20 22 22 24 24 25 25 25 26 27 27 27 27 27 27 29 31 32 33 33 33 34 34 34 35 36 37 37 38 38 38 38 38 40 41 42 43 44 46 46 48 48 48 50 51 52 54 55 57 58 60 61 63 64 66 67 69 70 72 73 74 74 74 74 74 74 74 75 76 76 76 76 78 80 80 81 81 81 81 ...
output:
1111041938
result:
ok single line: '1111041938'
Test #33:
score: 0
Accepted
time: 35ms
memory: 50300kb
input:
99470 1569644496 1 2 4 6 7 7 7 7 8 9 9 11 11 13 14 14 14 16 17 18 19 19 21 21 21 23 23 23 24 25 27 29 29 29 29 31 33 35 36 36 38 39 40 42 43 43 43 43 44 46 47 48 49 50 52 53 54 54 56 56 56 57 58 60 61 63 63 64 65 66 67 68 68 70 71 72 74 75 76 78 78 79 79 81 81 81 82 84 86 87 87 87 89 91 91 92 93 94 ...
output:
2802418185
result:
ok single line: '2802418185'
Test #34:
score: 0
Accepted
time: 15ms
memory: 50700kb
input:
94544 441795869 2 4 5 6 7 7 9 10 11 13 13 15 15 16 16 16 17 18 20 20 20 21 23 24 26 27 29 30 31 32 32 32 34 35 35 35 36 36 37 37 37 37 38 40 42 42 44 45 45 47 48 50 50 51 52 53 53 53 54 55 55 57 59 59 59 61 63 64 66 68 68 70 71 71 73 74 76 78 79 81 81 81 81 81 81 81 83 84 84 86 88 89 91 91 91 93 95 ...
output:
1482081338
result:
ok single line: '1482081338'
Test #35:
score: 0
Accepted
time: 22ms
memory: 47684kb
input:
92132 6712168296 26 43 86 151 166 171 189 190 287 311 323 331 384 430 451 478 506 595 648 708 778 782 789 881 903 930 951 985 1032 1128 1131 1156 1223 1299 1362 1417 1491 1545 1605 1663 1679 1686 1697 1760 1798 1829 1897 1964 2040 2130 2167 2170 2171 2235 2293 2338 2407 2440 2451 2514 2530 2530 2600...
output:
3413719431
result:
ok single line: '3413719431'
Test #36:
score: 0
Accepted
time: 17ms
memory: 47920kb
input:
91775 6146936725 53 70 150 200 214 229 275 329 420 445 524 601 618 649 676 731 811 875 903 956 977 1012 1031 1099 1165 1194 1233 1293 1372 1390 1464 1504 1507 1542 1602 1643 1685 1769 1773 1800 1891 1949 1967 2042 2108 2145 2198 2234 2304 2400 2488 2564 2631 2727 2758 2797 2831 2871 2912 3011 3012 3...
output:
3121995868
result:
ok single line: '3121995868'
Test #37:
score: 0
Accepted
time: 30ms
memory: 52736kb
input:
98065 1361059647 2 92 94 118 123 153 242 307 329 402 478 500 549 643 701 719 774 775 832 864 921 1006 1070 1126 1128 1213 1230 1328 1385 1451 1515 1609 1617 1623 1698 1698 1768 1836 1882 1952 2015 2109 2141 2172 2228 2244 2284 2295 2374 2447 2500 2587 2626 2692 2694 2761 2765 2784 2799 2835 2880 292...
output:
731620721
result:
ok single line: '731620721'
Test #38:
score: 0
Accepted
time: 24ms
memory: 51800kb
input:
97972 2822108786 5 32 65 161 179 180 261 315 350 442 523 604 609 692 791 812 875 917 1001 1039 1082 1177 1195 1288 1317 1415 1499 1565 1573 1642 1661 1715 1803 1819 1828 1923 2002 2024 2101 2165 2215 2283 2334 2391 2466 2472 2476 2551 2561 2616 2627 2642 2735 2772 2867 2892 2913 3005 3044 3084 3102 ...
output:
1464498579
result:
ok single line: '1464498579'
Test #39:
score: 0
Accepted
time: 18ms
memory: 47916kb
input:
100000 9999999999 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 10...
output:
9999900000
result:
ok single line: '9999900000'
Test #40:
score: 0
Accepted
time: 10ms
memory: 30408kb
input:
98412 6566910933 100000 99999 99997 99997 99996 99995 99993 99992 99991 99990 99988 99987 99987 99987 99985 99984 99982 99980 99978 99978 99977 99977 99977 99977 99977 99975 99974 99972 99970 99970 99968 99968 99967 99966 99964 99964 99963 99961 99959 99958 99956 99954 99953 99951 99951 99949 99949 ...
output:
4913318740
result:
ok single line: '4913318740'
Test #41:
score: -100
Time Limit Exceeded
input:
97058 2418426525 99999 99997 99997 99997 99997 99996 99995 99993 99991 99990 99989 99989 99988 99986 99984 99983 99981 99981 99981 99980 99978 99977 99976 99975 99973 99972 99970 99970 99968 99966 99966 99965 99963 99963 99962 99961 99960 99959 99957 99955 99953 99953 99953 99951 99949 99947 99945 9...