結果
| 問題 |
No.507 ゲーム大会(チーム決め)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-03-30 14:35:54 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,205 bytes |
| コンパイル時間 | 1,962 ms |
| コンパイル使用メモリ | 197,872 KB |
| 実行使用メモリ | 17,848 KB |
| 最終ジャッジ日時 | 2025-03-30 14:36:05 |
| 合計ジャッジ時間 | 11,095 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | TLE * 1 -- * 1 |
| other | -- * 19 |
コンパイルメッセージ
main.cpp: In function ‘void openfile()’:
main.cpp:20:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
20 | freopen("prize.in","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:21:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
21 | freopen("prize.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<48||ch>57){if(ch=='-')f=-1;ch=getchar();}
while(ch>=48&&ch<=57)x=(x<<1)+(x<<3)+(ch&15),ch=getchar();
return x*f;
}
inline void write(int x)
{
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+48);
return;
}
inline void openfile()
{
freopen("prize.in","r",stdin);
freopen("prize.out","w",stdout);
}
constexpr int M=1e5+4;
int n,m,num[M];
multiset<int>s;
inline bool check(int x)
{
s.clear();
int np=num[1]+num[x];
for(int i=2;i<=n;++i)
{
if(i==1||i==x)continue;
s.insert(num[i]);
}
int rk=0;
while(!s.empty())
{
int t=*s.rbegin();
auto it=s.end();
s.erase(--it);
it=s.upper_bound(np-t);
if(it==s.end())break;
++rk;
s.erase(it);
}
return rk<m;
}
int main()
{
openfile();
n=read(),m=read();
for(int i=1;i<=n;++i)num[i]=read();
sort(num+2,num+n+1);
int l=1,r=n+1,ans=n+1;
while(l+1<r)
{
int mid=l+r>>1;
if(check(mid))ans=mid,r=mid;
else l=mid;
}
if(r==n+1)puts("-1");
else write(num[ans]);
return 0;
}