結果
問題 | No.448 ゆきこーだーの雨と雪 (3) |
ユーザー | Ashurnasirpal |
提出日時 | 2018-02-06 19:34:06 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,188 bytes |
コンパイル時間 | 1,495 ms |
コンパイル使用メモリ | 172,392 KB |
実行使用メモリ | 28,500 KB |
最終ジャッジ日時 | 2024-07-19 01:32:08 |
合計ジャッジ時間 | 7,369 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
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 | AC | 179 ms
15,184 KB |
testcase_18 | AC | 23 ms
5,376 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 230 ms
19,532 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 29 ms
5,376 KB |
testcase_32 | AC | 34 ms
5,456 KB |
testcase_33 | WA | - |
testcase_34 | AC | 278 ms
19,148 KB |
testcase_35 | WA | - |
testcase_36 | AC | 256 ms
20,564 KB |
testcase_37 | WA | - |
testcase_38 | AC | 268 ms
19,152 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll,ll>; const ll inf = numeric_limits<ll>::max()/3; int n; ll k; vector< P > tasks; bool detect(ll m){ ll last = -inf; for(int i = 0;i < n;++i){ if(tasks[i].second > m){ if(tasks[i].first - last < k) return false; last = tasks[i].first; } } return true; } int main(void){ cin >> n >> k; tasks.clear(); // find dmax (by bsearch) ll tot = 0; set< ll > diff_set; vector< ll > diff_vec; diff_set.insert(0LL); for(int i = 0;i < n;++i){ ll t,d; cin >> t >> d; tasks.push_back(P(t,d)); diff_set.insert(d); tot += d; } for(auto d : diff_set){ diff_vec.push_back(d); } int l = -1,r = (int)diff_vec.size()-1; while(r - l > 1){ int mid = (l+r)/2; //cout << diff_vec[mid] << " " << detect(diff_vec[mid]) << endl; if(detect(diff_vec[mid])) r = mid; else l = mid; } ll dmax = diff_vec[r]; // remove unavalilable tasks vector< ll > used; used.push_back(-inf); for(int i = 0;i < n;++i){ if(tasks[i].second > dmax){ used.push_back(tasks[i].first); tot -= tasks[i].second; } } used.push_back(inf); vector< P > tasks2; int j = 1; for(int i = 0;i < n;++i){ while(j < (int)used.size()-1 && used[j] < tasks[i].first) ++j; if(used[j-1] + k <= tasks[i].first && tasks[i].first <= used[j] - k){ tasks2.push_back(tasks[i]); } } // find optimal sum vector< P > dp; dp.push_back(P(0,0)); for(int i = 0;i < (int)tasks2.size();++i){ int j = (upper_bound(dp.begin(), dp.end(), P(tasks2[i].first, inf)) - dp.begin()) - 1; dp.push_back(P(tasks2[i].first + k, dp[j].second + tasks2[i].second)); /* for(int i = 0;i < (int)dp.size();++i){ printf("(%lld, %lld) ",dp[i].first,dp[i].second); } cout << endl; */ } ll res = 0; for(int i = 0;i < (int)dp.size();++i){ res = max(res,dp[i].second); } cout << dmax << endl; cout << tot - res << endl; /* for(int i = 0;i < (int)tasks2.size();++i){ cout << tasks2[i].first << " " << tasks2[i].second << endl; } */ return 0; }