| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 771324 | Ahmed57 | Salesman (IOI09_salesman) | C++17 | 98 ms | 33984 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
//BIT Fenwick tree
struct fenwick{
long long bit[200001]={0} , n = 200000;
void build(){
for(int i = 0;i<=200000;i++)bit[i] = -1e18;
}
void add(int e,long long v){
while(e<=n){
bit[e]=max(bit[e],v);
e+=e&-e;
}
}
long long sum(int e){
long long res = -1e18;
while(e>=1){
res=max(res,bit[e]);
e -= e&-e;
}
return res;
}
};
fenwick s1,s2;
long long n,u,d,s;
void update(int i,int val){
s1.add(i,val+d*i);
s2.add(200001-i,val-u*i);
}long long get(int i){
return max(s2.sum(200001-i)+u*i,s1.sum(i)-d*i);
}
//end BIT
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
s1.build();s2.build();
cin>>n>>u>>d>>s;
vector<pair<int,int>> v[200001];
for(int i = 0;i<n;i++){
long long a,b,c;
cin>>a>>b>>c;
v[a].push_back({b,c});
}
update(s,0);
long long ma = 0;
for(int i = 0;i<=200000;i++){
if(v[i].empty())continue;
sort(v[i].begin(),v[i].end());
long long cur[v[i].size()] ;
long long maxD[v[i].size()] ;
long long maxU[v[i].size()];
for(int j = 0;j<v[i].size();j++){
cur[j] = -1e18 , maxD[j] =-1e18 , maxU[j] = -1e18;
cur[j] = get(v[i][j].first)+v[i][j].second;
}
long long tempD = -1e18,tempU = -1e18;
for(int j = 0;j<v[i].size();j++){
maxD[j] = max(maxD[j],tempD-d*v[i][j].first+v[i][j].second);
tempD = max(tempD,cur[j]+d*v[i][j].first);
}
for(int j = v[i].size()-1;j>=0;j--){
maxU[j] = max(maxU[j],tempU+u*v[i][j].first+v[i][j].second);
tempU = max(tempU,cur[j]-u*v[i][j].first);
}
for(int j = 0;j<v[i].size();j++){
cur[j] = max({cur[j],maxD[j],maxU[j]});
update(v[i][j].first,cur[j]);
}
}
cout<<max(get(s),0ll)<<endl;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
