結果

問題 No.974 最後の日までに
ユーザー 👑 kmjpkmjp
提出日時 2020-01-18 02:17:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,815 bytes
コンパイル時間 3,427 ms
コンパイル使用メモリ 176,780 KB
実行使用メモリ 8,380 KB
最終ジャッジ日時 2023-09-08 12:31:04
合計ジャッジ時間 11,021 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 113 ms
7,040 KB
testcase_26 AC 111 ms
6,892 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 114 ms
6,848 KB
testcase_30 WA -
testcase_31 AC 113 ms
6,776 KB
testcase_32 AC 114 ms
6,868 KB
testcase_33 AC 129 ms
6,984 KB
testcase_34 WA -
testcase_35 AC 113 ms
6,956 KB
testcase_36 AC 113 ms
6,816 KB
testcase_37 WA -
testcase_38 AC 114 ms
6,868 KB
testcase_39 AC 113 ms
6,956 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 113 ms
6,888 KB
testcase_47 AC 113 ms
6,932 KB
testcase_48 AC 112 ms
6,936 KB
testcase_49 AC 112 ms
6,872 KB
testcase_50 AC 112 ms
6,816 KB
testcase_51 AC 113 ms
6,884 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[52],B[52],C[52];

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});
		}
		else {
			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;
	}
	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