結果
| 問題 | No.3459 Defeat Slimes |
| コンテスト | |
| ユーザー |
harurun
|
| 提出日時 | 2026-02-28 14:38:15 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 487 ms / 3,000 ms |
| コード長 | 2,096 bytes |
| 記録 | |
| コンパイル時間 | 9,137 ms |
| コンパイル使用メモリ | 584,668 KB |
| 実行使用メモリ | 14,004 KB |
| 最終ジャッジ日時 | 2026-02-28 14:38:44 |
| 合計ジャッジ時間 | 22,727 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge7 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#ifndef ONLINE_JUDGE
#include "header.hpp"
#else
#include <bits/stdc++.h>
#include <atcoder/all>
#include <boost/multiprecision/cpp_int.hpp>
using cpp_int=boost::multiprecision::cpp_int;
#include <boost/multiprecision/cpp_dec_float.hpp>
template<unsigned size>using cpp_float=boost::multiprecision::number<boost::multiprecision::cpp_dec_float<size>>;
template<unsigned size>using cpp_double=boost::multiprecision::number<boost::multiprecision::cpp_dec_float<size,long long>>;
#endif
using namespace std;
using ll=long long;
inline void yn(bool x){if(x){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}}
#define double_out(x) fixed << setprecision(x)
template<class T> inline void erase_duplicate(vector<T>& A){sort(A.begin(),A.end());A.erase(unique(A.begin(),A.end()),A.end());}
inline ll powll(ll x,ll n){ll r=1;while(n>0){if(n&1){r*=x;};x*=x;n>>=1;};return r;}
using namespace std;
using ll=long long;
struct CLX{
ll C,L,X;
bool operator<(CLX clx)const{
return L<clx.L;
}
};
struct CX{
ll C, X;
bool operator<(CX cx)const{
return X<cx.X;
}
};
int main(){
ll N,Y,Z;
cin>>N>>Y>>Z;
vector<CLX> clx(N);
for(ll i=0;i<N;i++){
cin>>clx[i].C>>clx[i].L>>clx[i].X;
}
sort(clx.begin(),clx.end());
ll ans=0;
priority_queue<CX> pq;
ll idx=0;
while(idx<N && clx[idx].L<=Y){
pq.push({clx[idx].C,clx[idx].X});
idx++;
}
while(!pq.empty() && Y<Z){
while(idx<N && clx[idx].L<=Y){
pq.push({clx[idx].C,clx[idx].X});
idx++;
}
auto [c,x]=pq.top();
pq.pop();
// cerr<<c<<" "<<x<<" "<<Y<<endl;
ll ZZ=Z;
if(idx<N){
ZZ=min(ZZ, clx[idx].L);
}
ll cnt=(ZZ-Y+x-1)/x;
if(cnt>c){
Y+=x*c;
ans+=c;
}else{
Y+=x*cnt;
ans+=cnt;
c-=cnt;
if(c>0){
pq.push({c,x});
}
}
}
// cerr<<"Y: "<<Y<<endl;
if(Y<Z){
cout<<-1<<endl;
}else{
cout<<ans<<endl;
}
}
harurun