이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll MAXN=1e5+6;
const ll INF=1e17;
struct event
{
int c,f,v;
int type;
bool operator<(event const& other)const
{
if(f!=other.f)return f>other.f;
if(type!=other.type)return type==1;
return v<other.v;
}
};
vector<event>e;
ll dp[MAXN];
ll n,m;
void solve()
{
cin>>n;
for(int i=0;i<n;i++)
{
int x,y,z;
cin>>x>>y>>z;
e.push_back({x,y,z,1});
}
cin>>m;
for(int i=0;i<m;i++)
{
int x,y,z;
cin>>x>>y>>z;
e.push_back({x,y,z,-1});
}
sort(e.begin(),e.end());
for(int i=1;i<MAXN;i++)dp[i]=-INF;
for(int i=0;i<e.size();i++)
{
if(e[i].type==1)
{
for(int j=MAXN-e[i].c-1;j>=0;j--)
{
dp[j+e[i].c]=max(dp[j+e[i].c],dp[j]-e[i].v);
}
}
else
{
for(int j=e[i].c;j<MAXN;j++)
{
dp[j-e[i].c]=max(dp[j-e[i].c],dp[j]+e[i].v);
}
}
}
ll ans=-INF;
for(int i=0;i<MAXN;i++)
{
ans=max(ans,dp[i]);
}
cout<<ans<<endl;
}
int main()
{
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
clo.cpp: In function 'void solve()':
clo.cpp:38:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<event>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int i=0;i<e.size();i++)
| ~^~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |