Submission #88754

# Submission time Handle Problem Language Result Execution time Memory
88754 2018-12-08T13:17:53 Z nikolapesic2802 Arranging Tickets (JOI17_arranging_tickets) C++14
0 / 100
9 ms 8312 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a) {
	os << '{';
	for(int i=0;i<sz(a);i++)
	{
		if(i>0&&i<sz(a)-1)
			os << ", ";
		os << a[i];
	}
	os << '}';
    return os;
}
const int N=2e5+5;
vector<vector<pair<int,int> > > interval(N);
vector<ll> sum(N),temp(N);
int n;
bool test(ll m)
{
    //printf("Testiram %i\n",m);
    fill(all(temp),0);
    ll cnt=0;
    priority_queue<pair<int,int> > q;
    for(int i=1;i<=n;i++)
    {
        temp[i]+=temp[i-1];
        for(auto p:interval[i])
            q.push(p);
        ll now=sum[i]+temp[i];
        //printf("NOW! %lld %i %lld %lld\n",now,i,sum[i],temp[i]);
        while(!q.empty()&&now>m)
        {
            int y,c;
            tie(y,c)=q.top();
            //printf("%i %i %i\n",y,c,now-m);
            ll v=min((ll)c,(ll)now-m);
            //printf("%lld\n",v);
            q.pop();
            if(y<=i)
                continue;
            cnt+=v;
            temp[i]-=v;
            temp[y]+=v;
            now-=v;
            if(v<c)
                q.push({y,c-v});
        }
        if(cnt>m||now>m)
            return false;
    }
    return true;
}
int main()
{
    int m;
    scanf("%i %i",&n,&m);
    for(int i=0;i<m;i++)
    {
        int a,b,c;
        scanf("%i %i %i",&a,&b,&c);
        if(a>b)
            swap(a,b);
        interval[a].pb({b,c});
        sum[a]+=c;
        sum[b]-=c;
    }
    ll maxV=0;
    for(int i=1;i<=n;i++)
        sum[i]+=sum[i-1],maxV=max(maxV,sum[i]);
    ll l=0,r=maxV;
    while(l<r)
    {
        ll mid=(l+r)>>1;
        if(test(mid))
            r=mid;
        else
            l=mid+1;
    }
    printf("%lld\n",l);
    return 0;
}

Compilation message

arranging_tickets.cpp: In function 'int main()':
arranging_tickets.cpp:73:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i %i",&n,&m);
     ~~~~~^~~~~~~~~~~~~~~
arranging_tickets.cpp:77:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i %i %i",&a,&b,&c);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 8312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 8312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 8312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 8312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 8312 KB Output isn't correct
2 Halted 0 ms 0 KB -