結果
問題 |
No.972 選び方のスコア
|
ユーザー |
|
提出日時 | 2020-01-17 23:04:51 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,784 bytes |
コンパイル時間 | 2,998 ms |
コンパイル使用メモリ | 87,152 KB |
実行使用メモリ | 6,528 KB |
最終ジャッジ日時 | 2024-06-25 23:57:02 |
合計ジャッジ時間 | 4,887 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 WA * 6 |
ソースコード
#include<iostream> #include<string> #include<iomanip> #include<cmath> #include<vector> #include<algorithm> using namespace std; #define int long long #define endl "\n" constexpr long long INF = (long long)1e18; constexpr long long MOD = 1'000'000'007; string yn(bool f){return f?"Yes":"No";} string YN(bool f){return f?"YES":"NO";} int N; vector<int> a, sum; bool check(int m, int x){ int y = x / 2; // if(m == 0) return true; if(x%2) { if(m > min(y, N - y - 3)) { return false; } else { int a = sum[y] - sum[y - m]; int b = sum[N] - sum[N - m]; if(a <= b) return true; else return false; } } else { if(m > min(y, N - y - 2)) { return false; } else { int a = sum[y] - sum[y - m]; int b = sum[N] - sum[N - m]; if(a <= b) return true; else return false; } } } signed main(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(10); int ans = 0; cin>>N; a.resize(N); sum.resize(N+1); for(int i = 0; i < N; i++){ cin>>a[i]; a[i] <<= 1; // cout<<"i = "<<i<<" a "<<a[i]<<endl; } sort(a.begin(), a.end()); for(int i = 0; i < N; i++){ sum[i+1] = a[i] + sum[i]; } for(int i = 0; i < N * 2 - 1; i++){ int l = 0, h = N, m = 0; while(l + 1 < h){ m = (l + h) >> 1; if(check(m, i)){ l = m; } else { h = m; } } // cout<<"i = "<<i<<" l = "<<l<<endl; int temp = 0; int A = sum[i/2] - sum[i/2 - l]; int B = sum[N] - sum[N - l]; // cout<<"A = "<<A<<" B = "<<B<<endl; // cout<<" "<<a[i/2] <<" + "<< a[(i + 1)/2]<<endl; // cout<<" "<< i / 2 <<" [] "<< (i + 1)/2<<endl; temp = A + B - l * (a[i/2] + a[(i + 1)/2]); // cout<<temp<<endl; // cout<<endl; ans = max(ans, temp); } cout<<ans/2<<endl; return 0; }