結果
問題 | No.198 キャンディー・ボックス2 |
ユーザー | 👑 kmjp |
提出日時 | 2015-04-29 00:01:49 |
言語 | C++11 (gcc 11.4.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,267 bytes |
コンパイル時間 | 1,417 ms |
コンパイル使用メモリ | 145,984 KB |
実行使用メモリ | 8,752 KB |
最終ジャッジ日時 | 2023-09-18 14:27:44 |
合計ジャッジ時間 | 9,840 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 994 ms
7,656 KB |
testcase_01 | TLE | - |
testcase_02 | AC | 73 ms
4,376 KB |
testcase_03 | AC | 57 ms
4,380 KB |
testcase_04 | AC | 73 ms
4,376 KB |
testcase_05 | AC | 88 ms
4,380 KB |
testcase_06 | AC | 73 ms
4,380 KB |
testcase_07 | AC | 58 ms
4,380 KB |
testcase_08 | AC | 87 ms
4,380 KB |
testcase_09 | AC | 25 ms
4,380 KB |
testcase_10 | AC | 24 ms
4,376 KB |
testcase_11 | AC | 28 ms
4,380 KB |
testcase_12 | AC | 27 ms
4,376 KB |
testcase_13 | AC | 88 ms
4,376 KB |
testcase_14 | AC | 17 ms
4,380 KB |
testcase_15 | AC | 17 ms
4,380 KB |
testcase_16 | AC | 21 ms
4,376 KB |
testcase_17 | AC | 25 ms
4,376 KB |
testcase_18 | AC | 28 ms
4,376 KB |
testcase_19 | AC | 32 ms
4,380 KB |
testcase_20 | AC | 66 ms
4,380 KB |
testcase_21 | AC | 74 ms
4,376 KB |
testcase_22 | AC | 81 ms
4,380 KB |
testcase_23 | AC | 88 ms
4,376 KB |
testcase_24 | AC | 51 ms
4,376 KB |
testcase_25 | AC | 96 ms
4,380 KB |
testcase_26 | AC | 96 ms
4,380 KB |
testcase_27 | AC | 95 ms
4,380 KB |
testcase_28 | AC | 96 ms
4,380 KB |
testcase_29 | TLE | - |
ソースコード
#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)) //------------------------------------------------------- ll B; int N; ll C[20]; ll sum; ll ret[140000]; ll step(ll tar) { ll ov=0,fl=0; int j; if(tar<0) return 1LL<<60; FOR(j,N) if(C[j]>tar) ov += C[j]-tar; FOR(j,N) if(C[j]<tar) fl += tar-C[j]; if(fl<=ov+B) return ov+fl; return 1LL<<60; } void solve() { int i,j,k,l,r,x,y; string s; cin>>B>>N; ll sum=B; FOR(i,N) cin>>C[i], sum+=C[i]; for(i=0;i<=10000;i++) ret[i]=step(i*100000); ll L=0,R=0; for(i=0;i<=10000;i++) { if(ret[L]>ret[i]) L=i; if(ret[R]>=ret[i]) R=i; } ll M=(L+R)*100000/2; ll mi=1LL<<60; for(ll i=L*100000-2000000;i<=R*100000+2000000;i++) mi=min(mi,step(i)); cout<<mi<<endl; } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); solve(); return 0; }