結果
| 問題 |
No.844 split game
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-09 18:27:54 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,752 bytes |
| コンパイル時間 | 2,081 ms |
| コンパイル使用メモリ | 182,116 KB |
| 実行使用メモリ | 9,984 KB |
| 最終ジャッジ日時 | 2024-09-13 15:43:02 |
| 合計ジャッジ時間 | 7,837 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 WA * 26 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
const ll INF = 1e18;
const int MOD = 1000000007;
int main(){
int n,m,a;
cin >> n >> m >> a;
vector<vector<ll>> section(m,vector<ll>(3,0));
vector<int> before(m,-1);
vector<P> dp(m+1);
rep(i,m){
ll l,r,p;
cin >> l >> r >> p;
--l;
section[i][0] = r;
section[i][1] = l;
section[i][2] = p;
}
sort(section.begin(),section.end());
rep(i,m){
int l = -1,r = i;
while(r - l > 1){
int mid = (l+r)/2;
if(section[mid][0] <= section[i][1]) l = mid;
else r = mid;
}
before[i] = l;
}
dp[0] = P(0,0);
for(int i=1;i<=m;i++){
dp[i] = dp[i-1];
if(before[i-1] == -1){
ll res = section[i-1][2];
int c = 2;
if(section[i-1][1] == 0) --c;
if(section[i-1][0] == n) --c;
res -= a * c;
if(res >= dp[i].first){
dp[i] = P(res,section[i-1][0]);
}
}
else{
ll res = dp[before[i-1]+1].first + section[i-1][2];
int c = 2;
if(dp[before[i-1]+1].second == section[i-1][1]) --c;
if(section[i-1][0] == n) --c;
res -= c * a;
if(res >= dp[i].first){
dp[i] = P(res,section[i-1][0]);
}
}
}
//rep(i,m) cout << section[i][0] << " " << section[i][1] << " " << section[i][2] << endl;
//rep(i,m) cout << before[i] << " " << endl;
//rep(i,m+1) cout << dp[i].first << " " << dp[i].second << endl;
cout << dp[m].first << endl;
return 0;
}