結果
| 問題 |
No.507 ゲーム大会(チーム決め)
|
| コンテスト | |
| ユーザー |
kotamanegi
|
| 提出日時 | 2017-04-21 23:18:19 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,020 bytes |
| コンパイル時間 | 855 ms |
| コンパイル使用メモリ | 89,640 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 17:42:59 |
| 合計ジャッジ時間 | 2,973 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 2 WA * 17 |
ソースコード
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define LONG_INF 10000000000000000
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
long long n, m;
vector<long long> a;
int judge(long long now) {
int reco[200000] = {};
int ok_cnt = -1;
long long nya = 0;
for (int i = 0;i < n;++i) {
if (reco[i] == false) {
int top = n - 1;
int bot = 0;
reco[i] = true;
while (top - bot > 1) {
int mid = top + bot;
mid /= 2;
if (reco[mid] == false && a[mid] >= now - a[i]) bot = mid;
else top = mid;
}
if (reco[bot] == false && a[bot] >= now - a[i]) {
reco[bot] = true;
if (a[bot] == now - a[i]) {
ok_cnt++;
}
}
else if (reco[top] == false && a[top] >= now - a[i]) {
reco[top] = true;
if (a[top] == now - a[i]) {
ok_cnt++;
}
}
else {
if (i - max(ok_cnt, 0) - nya <= m) {
return true;
}
else return false;
}
}
else {
nya++;
}
}
if (n - max(ok_cnt, 0) -nya <= m) {
return true;
}
else return false;
}
int main() {
cin >> n >> m;
REP(i, n) {
long long hoge;
cin >> hoge;
a.push_back(hoge);
}
long long k = a[0];
sort(a.begin(), a.end(), greater<long long>());
//binary_search
long long top = 3000000000;
long long bot = 0;
while (top - bot > 1) {
long long mid = (top + bot) / 2;
if (judge(mid)) {
top = mid;
}else{
bot = mid;
}
}
if (judge(top)) {
if (top - k <= a[0]) {
cout << top - k << endl;
}
else cout << -1 << endl;
return 0;
}
else {
if (bot - k <= a[0]) {
cout << bot - k << endl;
}
else cout << -1 << endl;
return 0;
}
}
kotamanegi