結果

問題 No.974 最後の日までに
ユーザー 👑 kmjpkmjp
提出日時 2020-01-18 02:21:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 1,859 bytes
コンパイル時間 1,880 ms
コンパイル使用メモリ 175,860 KB
実行使用メモリ 10,544 KB
最終ジャッジ日時 2024-04-14 21:52:57
合計ジャッジ時間 11,002 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 143 ms
9,004 KB
testcase_01 AC 156 ms
9,132 KB
testcase_02 AC 156 ms
9,140 KB
testcase_03 AC 150 ms
9,776 KB
testcase_04 AC 151 ms
10,416 KB
testcase_05 AC 148 ms
9,780 KB
testcase_06 AC 150 ms
9,264 KB
testcase_07 AC 149 ms
8,884 KB
testcase_08 AC 150 ms
9,396 KB
testcase_09 AC 148 ms
9,652 KB
testcase_10 AC 147 ms
9,776 KB
testcase_11 AC 147 ms
9,132 KB
testcase_12 AC 147 ms
9,516 KB
testcase_13 AC 156 ms
9,904 KB
testcase_14 AC 157 ms
9,516 KB
testcase_15 AC 157 ms
10,036 KB
testcase_16 AC 159 ms
9,908 KB
testcase_17 AC 152 ms
9,520 KB
testcase_18 AC 153 ms
9,136 KB
testcase_19 AC 153 ms
9,776 KB
testcase_20 AC 153 ms
10,412 KB
testcase_21 AC 152 ms
9,520 KB
testcase_22 AC 151 ms
9,520 KB
testcase_23 AC 151 ms
9,140 KB
testcase_24 AC 152 ms
9,008 KB
testcase_25 AC 124 ms
10,416 KB
testcase_26 AC 124 ms
9,776 KB
testcase_27 AC 152 ms
9,012 KB
testcase_28 AC 152 ms
10,544 KB
testcase_29 AC 124 ms
9,140 KB
testcase_30 AC 158 ms
9,652 KB
testcase_31 AC 124 ms
9,520 KB
testcase_32 AC 124 ms
9,136 KB
testcase_33 AC 152 ms
9,644 KB
testcase_34 AC 154 ms
9,392 KB
testcase_35 AC 124 ms
8,748 KB
testcase_36 AC 123 ms
8,880 KB
testcase_37 AC 155 ms
9,136 KB
testcase_38 AC 124 ms
10,540 KB
testcase_39 AC 123 ms
9,136 KB
testcase_40 AC 144 ms
9,392 KB
testcase_41 AC 144 ms
9,004 KB
testcase_42 AC 158 ms
9,388 KB
testcase_43 AC 157 ms
9,264 KB
testcase_44 AC 158 ms
9,660 KB
testcase_45 AC 157 ms
9,012 KB
testcase_46 AC 124 ms
9,264 KB
testcase_47 AC 125 ms
10,292 KB
testcase_48 AC 123 ms
9,516 KB
testcase_49 AC 124 ms
10,160 KB
testcase_50 AC 124 ms
9,008 KB
testcase_51 AC 125 ms
9,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int W;
ll A[55],B[55],C[55];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>W;
	FOR(i,W) cin>>A[i]>>B[i]>>C[i];
	
	vector<pair<ll,ll>> cand[2];
	int mask;
	FOR(mask,1<<25) if((mask&(mask>>1))==0) {
		
		if(mask%2==0) {
			ll m=-C[26],s=B[26];
			for(i=27;i<52;i++) {
				if(mask&(1<<(i-26))) {
					i++;
					m-=C[i];
					s+=B[i];
				}
				else {
					m+=A[i];
				}
			}
			cand[1].push_back({m,s});
		}
		ll m=0,s=0;
		for(i=26;i<52;i++) {
			if(mask&(1<<(i-26))) {
				i++;
				m-=C[i];
				s+=B[i];
			}
			else {
				m+=A[i];
			}
		}
		cand[0].push_back({m,s});
	}
	FOR(i,2) {
		sort(ALL(cand[i]));
		vector<pair<ll,ll>> CC;
		FORR(c,cand[i]) {
			while(CC.size() && CC.back().second<=c.second) CC.pop_back();
			CC.push_back(c);
		}
		cand[i]=CC;
		//cout<<i<<endl;
		//FORR(c,CC) cout<<c.first<<" "<<c.second<<endl;
	}
	ll ret=0;
	FOR(mask,1<<26) if((mask&(mask>>1))==0) {
		ll m=0,s=0;
		FOR(i,26) {
			if(mask&(1<<i)) {
				if(i==25) break;
				i++;
				m-=C[i];
				s+=B[i];
			}
			else {
				m+=A[i];
			}
		}
		i=26-i;
		x=lower_bound(ALL(cand[i]),make_pair(-m,0LL))-cand[i].begin();
		if(x<cand[i].size()) ret=max(ret,s+cand[i][x].second);
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0