# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
92658 | SamAnd | Trading (IZhO13_trading) | C++17 | 443 ms | 22696 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <algorithm>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
const int N=300003;
struct ban
{
int l,r,x;
};
bool operator<(const ban& a,const ban& b)
{
int ansa,ansb;
if(a.l<b.l)
{
ansb=b.x;
ansa=a.x+(b.l-a.l);
}
else
{
ansb=b.x+(a.l-b.l);
ansa=a.x;
}
return ansa<ansb;
}
int n, m;
int a[N];
vector<ban> b[N];
int main()
{
//freopen("trading.in","r",stdin);
//freopen("trading.out","w",stdout);
cin>>n>>m;
for(int i=0;i<m;++i)
{
ban t;
cin>>t.l>>t.r>>t.x;
b[t.l].push_back(t);
}
priority_queue<ban> q;
for(int i=1;i<=n;++i)
{
ban t;
for(int j=0;j<b[i].size();++j)
{
t=b[i][j];
q.push(t);
}
bool z=false;
do
{
if(q.empty())
{
z=true;
break;
}
t=q.top();
if(t.r<i)
q.pop();
else
break;
}while(1);
if(z)
{
cout<<0<<' ';
continue;
}
cout<<t.x+(i-t.l)<<' ';
}
cout<<endl;
return 0;
}
/*
5 2
1 3 2
2 4 6
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |