# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
86764 | Mercenary | 금 캐기 (IZhO14_divide) | C++11 | 70 ms | 10584 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define pb push_back
#define brokenheart "TEST"
using namespace std;
typedef long long ll;
typedef long double ld;
const int maxn = 1e5 + 5;
#define int ll
int n;
int x[maxn] , r[maxn] , g[maxn] , dis[maxn];
int bit[maxn] , cost[maxn] , c[maxn] , sum[maxn];
vector<pair<int,int>> v;
void enter()
{
cin >> n;
for(int i = 1 ; i <= n ; ++i)
cin >> x[i] >> g[i] >> r[i];
for(int i = 1 ; i < n ; ++i)
dis[i] = x[i + 1] - x[i];
for(int i = 1 ; i < n ; ++i){
cost[i] = cost[i - 1] + dis[i] - r[i];
v.pb({cost[i],i});
}
v.pb({0,0});
sort(v.begin(),v.end());
for(int i = 1 ; i <= n ; ++i)
sum[i] = sum[i - 1] + g[i];
int cnt = 1;
c[v[0].second] = 1;
vector<pair<int,int>> v1;
v1.push_back(v[0]);
for(int i = 1 ; i < v.size() ; ++i)
{
if(v[i].first == v[i - 1].first)c[v[i].second] = cnt;
else c[v[i].second] = ++cnt ,v1.push_back(v[i]);
}
v = v1;
}
void update(int pos , int x)
{
for( ; pos < maxn ; pos += pos & -pos)
bit[pos] = min(bit[pos],x);
}
int query(int pos)
{
int res = maxn;
for( ; pos > 0 ; pos &= pos - 1)
res = min(res , bit[pos]);
return res;
}
void solve()
{
fill_n(bit , maxn , maxn);
ll res = 0;
for(int i = 1 ; i <= n ; ++i)
{
int pos = upper_bound(v.begin(),v.end(),make_pair(r[i] - cost[i - 1] , 0ll)) - v.begin();
int ans = query(pos);
if(ans != maxn)res = max(res , sum[i] - sum[ans]);
if(i != n)update(c[i] , i - 1);
res = max(res , g[i]);
}
cout << res;
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
if(fopen(brokenheart".INP","r"))
freopen(brokenheart".INP","r",stdin) ,
freopen(brokenheart".OUT","w",stdout);
enter();
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |