QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#35599#978. Maximum SubsequenceFroggyguaAC ✓75ms3928kbC++17834b2022-06-17 10:43:362022-06-17 10:43:37

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-06-17 10:43:37]
  • Judged
  • Verdict: AC
  • Time: 75ms
  • Memory: 3928kb
  • [2022-06-17 10:43:36]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define N 16
typedef long long ll;
inline void ckmin(int &x,int y){x=min(x,y);}
const int inf=0x3f3f3f3f;
int n,a[N];
int dp[1<<N];
bool check(int lim){
	memset(dp,0x3f,sizeof(dp));
	dp[0]=0;
	for(int i=0;i<(1<<n);++i){
		if(dp[i]==inf)continue;
		for(int j=0;j<n;++j){
			if(!(i>>j&1)){
				if(dp[i]+a[j]<=lim){
					ckmin(dp[i|(1<<j)],max(0,dp[i]+a[j]));
				}
			}
		}
	}
	return dp[(1<<n)-1]<inf;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	int mx=-inf;
	for(int i=0;i<n;++i){
		cin>>a[i];
		mx=max(mx,a[i]);
	}
	if(mx<=0){
		cout<<mx<<'\n';
		return 0;
	}
	int l=0,r=2e6,ans=r;
	while(l<r){
		int mid=(l+r)>>1;
		if(check(mid)){
			r=mid;
			ans=mid;
		}
		else{
			l=mid+1;
		}
	}
	cout<<ans<<'\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 3844kb

input:

4
1 -1 1 1

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

6
4 -4 5 -20 6 7

output:

9

result:

ok 1 number(s): "9"

Test #3:

score: 0
Accepted
time: 58ms
memory: 3904kb

input:

16
74685 37459 -1863 43873 69565 11753 -27428 57636 -80511 13844 -20908 69580 4289 -99806 -75028 30372

output:

107512

result:

ok 1 number(s): "107512"

Test #4:

score: 0
Accepted
time: 37ms
memory: 3928kb

input:

15
67994 74589 99849 97649 27926 26555 1194 -98123 4315 58602 67384 53308 59247 -17522 95188

output:

618155

result:

ok 1 number(s): "618155"

Test #5:

score: 0
Accepted
time: 13ms
memory: 3872kb

input:

14
-16144 -8970 -61906 -89752 -82770 52954 9044 85641 -78467 -71326 91206 -72168 -67481 58209

output:

91206

result:

ok 1 number(s): "91206"

Test #6:

score: 0
Accepted
time: 33ms
memory: 3908kb

input:

15
88967 1252 94890 70842 94379 -43780 -23585 52697 93720 33707 -79062 93850 98030 68193 -96410

output:

547690

result:

ok 1 number(s): "547690"

Test #7:

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

input:

16
-95394 27873 82707 -8091 22839 -22353 77819 17786 -20965 -17390 21878 2116 44799 -4573 16174 7845

output:

153070

result:

ok 1 number(s): "153070"

Test #8:

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

input:

16
73674 -66214 -39831 88784 42617 -75096 85579 1073 -55675 82743 -85078 -88198 12378 -14310 20005 33627

output:

88784

result:

ok 1 number(s): "88784"

Test #9:

score: 0
Accepted
time: 60ms
memory: 3904kb

input:

16
-83517 -65495 8945 31495 -30343 94018 14500 -13614 68884 -45706 -18744 -67271 93093 -14098 -3592 -58773

output:

94018

result:

ok 1 number(s): "94018"

Test #10:

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

input:

6
-15003 -28170 -30377 81020 -44906 -21965

output:

81020

result:

ok 1 number(s): "81020"

Test #11:

score: 0
Accepted
time: 54ms
memory: 3872kb

input:

16
-29848 4832 94117 -45241 1204 -99570 -10513 97070 48069 43198 -13260 41687 -57361 33422 -86646 -15135

output:

97070

result:

ok 1 number(s): "97070"

Test #12:

score: 0
Accepted
time: 34ms
memory: 3840kb

input:

15
-40154 98402 72394 -18077 89858 -8243 82205 85533 18703 99891 64337 -40784 82754 62837 78715

output:

728371

result:

ok 1 number(s): "728371"

Test #13:

score: 0
Accepted
time: 13ms
memory: 3824kb

input:

14
66250 -35079 -57181 19720 81648 35074 32470 58509 53389 -57108 -98486 10518 50384 -93648

output:

86765

result:

ok 1 number(s): "86765"

Test #14:

score: 0
Accepted
time: 74ms
memory: 3900kb

input:

16
40899 86787 42827 46271 50611 5024 18935 -29778 -63775 50497 71624 66733 58611 11007 3100 95197

output:

554570

result:

ok 1 number(s): "554570"

Test #15:

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

input:

5
-45688 73098 -92315 33790 -13955

output:

73098

result:

ok 1 number(s): "73098"

Test #16:

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

input:

3
98693 1701 31884

output:

132278

result:

ok 1 number(s): "132278"

Test #17:

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

input:

1
28298

output:

28298

result:

ok 1 number(s): "28298"

Test #18:

score: 0
Accepted
time: 33ms
memory: 3796kb

input:

15
11823 66662 -54420 37824 22297 92212 69303 -43475 29895 90424 46778 59451 -6719 73011 3205

output:

498271

result:

ok 1 number(s): "498271"

Test #19:

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

input:

15
10336 -51879 68382 87402 -30237 -62771 80927 -15568 -6831 38917 98576 -18210 20823 66361 -11231

output:

274997

result:

ok 1 number(s): "274997"

Test #20:

score: 0
Accepted
time: 75ms
memory: 3900kb

input:

16
-35603 19466 4413 -9913 48173 31103 35653 91725 -92984 73019 78100 38659 53651 53436 37700 17258

output:

443856

result:

ok 1 number(s): "443856"

Test #21:

score: 0
Accepted
time: 20ms
memory: 3924kb

input:

14
92942 63046 76091 19008 62272 27814 85894 -8202 28803 70386 29703 72309 -8672 -29761

output:

581633

result:

ok 1 number(s): "581633"

Test #22:

score: 0
Accepted
time: 73ms
memory: 3868kb

input:

16
-50703 -66984 48586 -6141 -15903 -27332 57733 90767 46085 69464 68558 33327 89292 95868 62116 -72578

output:

422155

result:

ok 1 number(s): "422155"

Test #23:

score: 0
Accepted
time: 16ms
memory: 3840kb

input:

14
60071 97848 59818 1834 -73085 38212 2556 80145 -36394 77438 38246 71294 29559 64975

output:

512517

result:

ok 1 number(s): "512517"

Test #24:

score: 0
Accepted
time: 26ms
memory: 3824kb

input:

15
-75702 61338 -62770 63958 31251 54962 -89816 -39497 37557 20958 9161 39979 9202 -41277 -6021

output:

63958

result:

ok 1 number(s): "63958"

Test #25:

score: 0
Accepted
time: 63ms
memory: 3852kb

input:

16
75665 79752 -99064 -8136 66639 87625 -98947 52015 -19537 77222 -72932 -32254 -29250 54691 18405 467

output:

152361

result:

ok 1 number(s): "152361"

Test #26:

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

input:

7
96173 16477 -51289 -67315 22620 -44673 -61658

output:

96173

result:

ok 1 number(s): "96173"

Test #27:

score: 0
Accepted
time: 65ms
memory: 3872kb

input:

16
87522 82712 40975 41046 24283 -37439 48363 40457 16597 24556 -36680 -62798 27824 -70211 -43518 31243

output:

214932

result:

ok 1 number(s): "214932"

Test #28:

score: 0
Accepted
time: 74ms
memory: 3872kb

input:

16
55572 71846 93230 -55096 97201 78206 75542 85807 58197 81578 79942 13793 8420 32911 78670 90793

output:

946612

result:

ok 1 number(s): "946612"

Test #29:

score: 0
Accepted
time: 28ms
memory: 3904kb

input:

15
-19411 -20105 -90206 18949 -39139 49737 34971 -72958 66306 75067 -39688 -52713 -62403 10814 -82166

output:

75067

result:

ok 1 number(s): "75067"

Test #30:

score: 0
Accepted
time: 24ms
memory: 3844kb

input:

15
-50522 64266 -60252 91796 -12338 29457 -60883 27833 -56388 63831 -13936 85229 -10590 -53294 -30029

output:

91796

result:

ok 1 number(s): "91796"

Test #31:

score: 0
Accepted
time: 19ms
memory: 3756kb

input:

14
21864 3995 11329 -54641 3290 62434 84236 13172 -37803 15668 52521 -17267 5271 17005

output:

181074

result:

ok 1 number(s): "181074"

Test #32:

score: 0
Accepted
time: 75ms
memory: 3852kb

input:

16
87906 33256 66708 92130 -93974 81186 81818 29420 90224 -21004 60067 23177 71078 503 67118 10202

output:

679815

result:

ok 1 number(s): "679815"

Test #33:

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

input:

14
-9800 -24965 -31025 92942 53446 9853 70196 37380 82648 -82472 -14731 49523 -38880 54296

output:

248411

result:

ok 1 number(s): "248411"

Test #34:

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

input:

10
75721 38266 -1028 -54009 64905 -90792 -71865 -21644 -35923 29982

output:

75721

result:

ok 1 number(s): "75721"

Test #35:

score: 0
Accepted
time: 31ms
memory: 3800kb

input:

15
46524 -5375 80174 -76289 54628 67732 91754 49901 -55289 3879 -73858 21824 -50736 46574 -12224

output:

189219

result:

ok 1 number(s): "189219"

Test #36:

score: 0
Accepted
time: 71ms
memory: 3824kb

input:

16
24474 38900 76720 33678 43889 20692 -30474 54229 -57898 13963 63065 45575 81706 89743 49125 61757

output:

609144

result:

ok 1 number(s): "609144"

Test #37:

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

input:

7
93664 -68014 39364 -83881 -79054 67994 89332

output:

93664

result:

ok 1 number(s): "93664"

Test #38:

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

input:

3
31510 64114 20248

output:

115872

result:

ok 1 number(s): "115872"

Test #39:

score: 0
Accepted
time: 55ms
memory: 3928kb

input:

16
-4771 -57558 53661 96749 -27899 96355 11037 48685 -79706 -67802 -16550 -54604 19804 -86097 20829 62158

output:

96749

result:

ok 1 number(s): "96749"

Test #40:

score: 0
Accepted
time: 20ms
memory: 3868kb

input:

14
23100 81349 81136 75654 41124 62771 86000 76734 87941 -79512 26553 -6096 -6293 22901

output:

573362

result:

ok 1 number(s): "573362"

Test #41:

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

input:

12
11580 36432 10078 98029 17015 31501 -53386 8894 81094 96306 43524 87779

output:

468846

result:

ok 1 number(s): "468846"

Test #42:

score: 0
Accepted
time: 37ms
memory: 3796kb

input:

15
-14769 55659 -3652 57393 23410 34625 36078 -10607 85650 36106 63324 71631 -80028 -42496 27404

output:

339728

result:

ok 1 number(s): "339728"

Test #43:

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

input:

2
96032 -79560

output:

96032

result:

ok 1 number(s): "96032"

Test #44:

score: 0
Accepted
time: 12ms
memory: 3832kb

input:

14
-10406 -75637 20667 -60861 -24037 -27672 48255 -62603 -13300 74328 16467 -188 82137 46315

output:

82137

result:

ok 1 number(s): "82137"

Test #45:

score: 0
Accepted
time: 26ms
memory: 3816kb

input:

15
-60537 -76493 -17309 -57622 90077 -50594 32123 -40848 91917 93303 -79448 22518 47771 18689 -79275

output:

93303

result:

ok 1 number(s): "93303"

Test #46:

score: 0
Accepted
time: 75ms
memory: 3900kb

input:

16
-86202 79572 12741 50730 48953 63238 59478 72696 88840 -93178 5160 42238 32761 99976 72985 62290

output:

612278

result:

ok 1 number(s): "612278"

Test #47:

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

input:

12
68729 -61967 -67621 36669 27426 87891 88900 80232 -20355 -55049 40490 13777

output:

239122

result:

ok 1 number(s): "239122"

Test #48:

score: 0
Accepted
time: 28ms
memory: 3816kb

input:

15
-96152 -93482 -24627 -34909 88912 -94485 -71027 -96657 -3114 47662 62500 -58183 -36534 33970 -27670

output:

88912

result:

ok 1 number(s): "88912"

Test #49:

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

input:

14
34677 55187 276 87707 -62858 -17301 -45948 -92383 9018 59477 -37345 51760 -94996 5279

output:

87707

result:

ok 1 number(s): "87707"

Test #50:

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

input:

3
-90969 99356 73931

output:

99356

result:

ok 1 number(s): "99356"

Test #51:

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

input:

12
89758 51022 77845 83124 -7142 43742 53732 30888 -29314 62905 88852 90648

output:

636060

result:

ok 1 number(s): "636060"

Test #52:

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

input:

6
-38469 -16017 -28949 90823 -4651 1076

output:

90823

result:

ok 1 number(s): "90823"

Test #53:

score: 0
Accepted
time: 31ms
memory: 3844kb

input:

15
4398 -2335 4536 2432 -4096 -1305 -97526 3784 -4281 -4398 1014 3325 -260 4819 3265

output:

5449

result:

ok 1 number(s): "5449"

Test #54:

score: 0
Accepted
time: 58ms
memory: 3928kb

input:

16
-4177 4477 1319 -3436 -93603 1364 -1147 2053 4048 2678 4795 2859 3742 788 883 3915

output:

12081

result:

ok 1 number(s): "12081"

Test #55:

score: 0
Accepted
time: 29ms
memory: 3800kb

input:

15
4715 1912 4265 2940 4117 -220 -4772 747 -1601 -81697 3858 1735 -2912 2727 2535

output:

10023

result:

ok 1 number(s): "10023"

Test #56:

score: 0
Accepted
time: 32ms
memory: 3872kb

input:

15
2089 2924 968 -1612 -3816 4711 4946 -587 50 3058 -87243 4483 4078 2897 -1581

output:

11304

result:

ok 1 number(s): "11304"

Test #57:

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

input:

16
-994 -701 2671 -4764 -96279 3247 -3235 3212 2803 1142 2352 -546 -3546 140 2361 1152

output:

3494

result:

ok 1 number(s): "3494"

Test #58:

score: 0
Accepted
time: 66ms
memory: 3752kb

input:

16
1229 284 858 3769 2276 709 1931 -4315 444 4618 2820 1575 1201 4037 -97300 -3886

output:

8775

result:

ok 1 number(s): "8775"

Test #59:

score: 0
Accepted
time: 4ms
memory: 3836kb

input:

13
102 2495 -1120 4120 3167 -2070 4481 -91701 -2054 4915 -2093 -4917 2394

output:

4915

result:

ok 1 number(s): "4915"

Test #60:

score: 0
Accepted
time: 66ms
memory: 3816kb

input:

16
1757 2104 3996 2002 1711 -744 3259 -4587 1438 -2607 4681 -1242 4978 3346 2165 -88370

output:

11129

result:

ok 1 number(s): "11129"

Test #61:

score: 0
Accepted
time: 55ms
memory: 3840kb

input:

16
221 2371 -623 -3922 1855 306 -1558 3851 2800 973 -3256 -2238 3716 1909 -98755 -4680

output:

3851

result:

ok 1 number(s): "3851"

Test #62:

score: 0
Accepted
time: 17ms
memory: 3904kb

input:

14
1779 -2891 -3818 -1425 1072 -2811 -99553 -1130 3316 -3203 1210 2433 1741 -4258

output:

3316

result:

ok 1 number(s): "3316"

Test #63:

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

input:

16
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1

output:

-1

result:

ok 1 number(s): "-1"

Test #64:

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

input:

16
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

output:

0

result:

ok 1 number(s): "0"