Submission #89137

# Submission time Handle Problem Language Result Execution time Memory
89137 2018-12-10T13:21:27 Z nikolapesic2802 Arranging Tickets (JOI17_arranging_tickets) C++14
100 / 100
1870 ms 12532 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+100;
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();
            if(y<=i)
                continue;
            ll v=min((ll)c,(ll)(now-up+1)/2);
            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-mid,2*mid-maxV)||test(maxV-mid+1,2*mid-maxV-1))
            r=mid;
        else
            l=mid+1;
    }
    printf("%lld\n",l);
    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 Correct 11 ms 8312 KB Output is correct
2 Correct 9 ms 8316 KB Output is correct
3 Correct 12 ms 8316 KB Output is correct
4 Correct 9 ms 8316 KB Output is correct
5 Correct 12 ms 8388 KB Output is correct
6 Correct 9 ms 8532 KB Output is correct
7 Correct 9 ms 8532 KB Output is correct
8 Correct 9 ms 8532 KB Output is correct
9 Correct 9 ms 8532 KB Output is correct
10 Correct 9 ms 8532 KB Output is correct
11 Correct 9 ms 8532 KB Output is correct
12 Correct 10 ms 8532 KB Output is correct
13 Correct 10 ms 8532 KB Output is correct
14 Correct 10 ms 8532 KB Output is correct
15 Correct 9 ms 8532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 8312 KB Output is correct
2 Correct 9 ms 8316 KB Output is correct
3 Correct 12 ms 8316 KB Output is correct
4 Correct 9 ms 8316 KB Output is correct
5 Correct 12 ms 8388 KB Output is correct
6 Correct 9 ms 8532 KB Output is correct
7 Correct 9 ms 8532 KB Output is correct
8 Correct 9 ms 8532 KB Output is correct
9 Correct 9 ms 8532 KB Output is correct
10 Correct 9 ms 8532 KB Output is correct
11 Correct 9 ms 8532 KB Output is correct
12 Correct 10 ms 8532 KB Output is correct
13 Correct 10 ms 8532 KB Output is correct
14 Correct 10 ms 8532 KB Output is correct
15 Correct 9 ms 8532 KB Output is correct
16 Correct 13 ms 8532 KB Output is correct
17 Correct 11 ms 8532 KB Output is correct
18 Correct 11 ms 8532 KB Output is correct
19 Correct 11 ms 8532 KB Output is correct
20 Correct 11 ms 8544 KB Output is correct
21 Correct 11 ms 8544 KB Output is correct
22 Correct 10 ms 8544 KB Output is correct
23 Correct 10 ms 8544 KB Output is correct
24 Correct 11 ms 8544 KB Output is correct
25 Correct 12 ms 8544 KB Output is correct
26 Correct 12 ms 8544 KB Output is correct
27 Correct 11 ms 8544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 8312 KB Output is correct
2 Correct 9 ms 8316 KB Output is correct
3 Correct 12 ms 8316 KB Output is correct
4 Correct 9 ms 8316 KB Output is correct
5 Correct 12 ms 8388 KB Output is correct
6 Correct 9 ms 8532 KB Output is correct
7 Correct 9 ms 8532 KB Output is correct
8 Correct 9 ms 8532 KB Output is correct
9 Correct 9 ms 8532 KB Output is correct
10 Correct 9 ms 8532 KB Output is correct
11 Correct 9 ms 8532 KB Output is correct
12 Correct 10 ms 8532 KB Output is correct
13 Correct 10 ms 8532 KB Output is correct
14 Correct 10 ms 8532 KB Output is correct
15 Correct 9 ms 8532 KB Output is correct
16 Correct 13 ms 8532 KB Output is correct
17 Correct 11 ms 8532 KB Output is correct
18 Correct 11 ms 8532 KB Output is correct
19 Correct 11 ms 8532 KB Output is correct
20 Correct 11 ms 8544 KB Output is correct
21 Correct 11 ms 8544 KB Output is correct
22 Correct 10 ms 8544 KB Output is correct
23 Correct 10 ms 8544 KB Output is correct
24 Correct 11 ms 8544 KB Output is correct
25 Correct 12 ms 8544 KB Output is correct
26 Correct 12 ms 8544 KB Output is correct
27 Correct 11 ms 8544 KB Output is correct
28 Correct 15 ms 8572 KB Output is correct
29 Correct 15 ms 8572 KB Output is correct
30 Correct 16 ms 8572 KB Output is correct
31 Correct 15 ms 8572 KB Output is correct
32 Correct 16 ms 8572 KB Output is correct
33 Correct 17 ms 8572 KB Output is correct
34 Correct 14 ms 8572 KB Output is correct
35 Correct 16 ms 8572 KB Output is correct
36 Correct 16 ms 8572 KB Output is correct
37 Correct 13 ms 8572 KB Output is correct
38 Correct 12 ms 8572 KB Output is correct
39 Correct 13 ms 8572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 8312 KB Output is correct
2 Correct 9 ms 8316 KB Output is correct
3 Correct 12 ms 8316 KB Output is correct
4 Correct 9 ms 8316 KB Output is correct
5 Correct 12 ms 8388 KB Output is correct
6 Correct 9 ms 8532 KB Output is correct
7 Correct 9 ms 8532 KB Output is correct
8 Correct 9 ms 8532 KB Output is correct
9 Correct 9 ms 8532 KB Output is correct
10 Correct 9 ms 8532 KB Output is correct
11 Correct 9 ms 8532 KB Output is correct
12 Correct 10 ms 8532 KB Output is correct
13 Correct 10 ms 8532 KB Output is correct
14 Correct 10 ms 8532 KB Output is correct
15 Correct 9 ms 8532 KB Output is correct
16 Correct 13 ms 8532 KB Output is correct
17 Correct 11 ms 8532 KB Output is correct
18 Correct 11 ms 8532 KB Output is correct
19 Correct 11 ms 8532 KB Output is correct
20 Correct 11 ms 8544 KB Output is correct
21 Correct 11 ms 8544 KB Output is correct
22 Correct 10 ms 8544 KB Output is correct
23 Correct 10 ms 8544 KB Output is correct
24 Correct 11 ms 8544 KB Output is correct
25 Correct 12 ms 8544 KB Output is correct
26 Correct 12 ms 8544 KB Output is correct
27 Correct 11 ms 8544 KB Output is correct
28 Correct 15 ms 8572 KB Output is correct
29 Correct 15 ms 8572 KB Output is correct
30 Correct 16 ms 8572 KB Output is correct
31 Correct 15 ms 8572 KB Output is correct
32 Correct 16 ms 8572 KB Output is correct
33 Correct 17 ms 8572 KB Output is correct
34 Correct 14 ms 8572 KB Output is correct
35 Correct 16 ms 8572 KB Output is correct
36 Correct 16 ms 8572 KB Output is correct
37 Correct 13 ms 8572 KB Output is correct
38 Correct 12 ms 8572 KB Output is correct
39 Correct 13 ms 8572 KB Output is correct
40 Correct 425 ms 12200 KB Output is correct
41 Correct 450 ms 12232 KB Output is correct
42 Correct 334 ms 12232 KB Output is correct
43 Correct 408 ms 12232 KB Output is correct
44 Correct 404 ms 12232 KB Output is correct
45 Correct 415 ms 12232 KB Output is correct
46 Correct 425 ms 12232 KB Output is correct
47 Correct 103 ms 12232 KB Output is correct
48 Correct 114 ms 12232 KB Output is correct
49 Correct 104 ms 12232 KB Output is correct
50 Correct 112 ms 12532 KB Output is correct
51 Correct 95 ms 12532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 8312 KB Output is correct
2 Correct 9 ms 8316 KB Output is correct
3 Correct 12 ms 8316 KB Output is correct
4 Correct 9 ms 8316 KB Output is correct
5 Correct 12 ms 8388 KB Output is correct
6 Correct 9 ms 8532 KB Output is correct
7 Correct 9 ms 8532 KB Output is correct
8 Correct 9 ms 8532 KB Output is correct
9 Correct 9 ms 8532 KB Output is correct
10 Correct 9 ms 8532 KB Output is correct
11 Correct 9 ms 8532 KB Output is correct
12 Correct 10 ms 8532 KB Output is correct
13 Correct 10 ms 8532 KB Output is correct
14 Correct 10 ms 8532 KB Output is correct
15 Correct 9 ms 8532 KB Output is correct
16 Correct 13 ms 8532 KB Output is correct
17 Correct 11 ms 8532 KB Output is correct
18 Correct 11 ms 8532 KB Output is correct
19 Correct 11 ms 8532 KB Output is correct
20 Correct 11 ms 8544 KB Output is correct
21 Correct 11 ms 8544 KB Output is correct
22 Correct 10 ms 8544 KB Output is correct
23 Correct 10 ms 8544 KB Output is correct
24 Correct 11 ms 8544 KB Output is correct
25 Correct 12 ms 8544 KB Output is correct
26 Correct 12 ms 8544 KB Output is correct
27 Correct 11 ms 8544 KB Output is correct
28 Correct 15 ms 8572 KB Output is correct
29 Correct 15 ms 8572 KB Output is correct
30 Correct 16 ms 8572 KB Output is correct
31 Correct 15 ms 8572 KB Output is correct
32 Correct 16 ms 8572 KB Output is correct
33 Correct 17 ms 8572 KB Output is correct
34 Correct 14 ms 8572 KB Output is correct
35 Correct 16 ms 8572 KB Output is correct
36 Correct 16 ms 8572 KB Output is correct
37 Correct 13 ms 8572 KB Output is correct
38 Correct 12 ms 8572 KB Output is correct
39 Correct 13 ms 8572 KB Output is correct
40 Correct 425 ms 12200 KB Output is correct
41 Correct 450 ms 12232 KB Output is correct
42 Correct 334 ms 12232 KB Output is correct
43 Correct 408 ms 12232 KB Output is correct
44 Correct 404 ms 12232 KB Output is correct
45 Correct 415 ms 12232 KB Output is correct
46 Correct 425 ms 12232 KB Output is correct
47 Correct 103 ms 12232 KB Output is correct
48 Correct 114 ms 12232 KB Output is correct
49 Correct 104 ms 12232 KB Output is correct
50 Correct 112 ms 12532 KB Output is correct
51 Correct 95 ms 12532 KB Output is correct
52 Correct 1870 ms 12532 KB Output is correct
53 Correct 1218 ms 12532 KB Output is correct
54 Correct 1336 ms 12532 KB Output is correct
55 Correct 1392 ms 12532 KB Output is correct
56 Correct 1270 ms 12532 KB Output is correct
57 Correct 1704 ms 12532 KB Output is correct
58 Correct 1460 ms 12532 KB Output is correct
59 Correct 719 ms 12532 KB Output is correct