Submission #89131

# Submission time Handle Problem Language Result Execution time Memory
89131 2018-12-10T13:05:25 Z nikolapesic2802 Arranging Tickets (JOI17_arranging_tickets) C++14
0 / 100
10 ms 8184 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 use, ll up)
{
    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>up)
        {
            int y,c;
            tie(y,c)=q.top();
            q.pop();
            ll v=min((ll)c,(ll)(now-up+1)/2);
            if(y<=i)
                continue;
            cnt+=v;
            temp[i]-=2*v;
            temp[y]+=2*v;
            now-=2*v;
            if(v<c)
                q.push({y,c-v});
        }
        if(cnt>use||now>up)
            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;
    ll ans=-1;
    while(l<r)
    {
        ll mid=(l+r)>>1;
        if(test(maxV-m,2*m-maxV)||test(maxV-m+1,2*m-maxV-1))
            r=mid-1,ans=mid;
        else
            l=mid+1;
    }
    printf("%lld\n",ans);
    return 0;
}

Compilation message

arranging_tickets.cpp: In function 'int main()':
arranging_tickets.cpp:70: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:74: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 10 ms 8184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 8184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 8184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 8184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 8184 KB Output isn't correct
2 Halted 0 ms 0 KB -