답안 #344308

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
344308 2021-01-05T13:07:45 Z aryanc403 Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
187 ms 19168 KB
/* in the name of Anton */

/*
  Compete against Yourself.
  Author - Aryan Choudhary (@aryanc403)
*/

#ifdef ARYANC403
    #include "/home/aryan/codes/PastCodes/template/header.h"
#else
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
    #pragma GCC optimize ("-ffloat-store")
    #include<iostream>
    #include<bits/stdc++.h>
    #define dbg(args...)
#endif

using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) ((lli)(x).size())
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;


const auto start_time = std::chrono::high_resolution_clock::now();
void aryanc403()
{
#ifdef ARYANC403
auto end_time = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
#endif
}

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
// const lli maxN = 1000000007L;

    lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
    lli m;
    string s;
    vi a;
    //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{

    cin>>n;
    a.clear();a.reserve(n);
    priority_queue<lli> pq;
    lli c=0;
    a.pb(0);
    fo(i,n)
    {
        cin>>l>>r;
        a.pb(a.back()+l-r);
    }

    dbg(a);
    const lli m=a.back();
    for(auto x:a)
    {
        if(x<0)
        {
            c-=x;
            x=0;
        }
        else if(x>m)
        {
            c+=x-m;
            x=m;
        }
        pq.push(x);
        pq.push(x);
        const lli v=pq.top();pq.pop();
        c+=abs(x-v);
    }

    cout<<c<<endl;

}   aryanc403();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 13 ms 2020 KB Output is correct
5 Correct 24 ms 3548 KB Output is correct
6 Correct 82 ms 9672 KB Output is correct
7 Correct 150 ms 19168 KB Output is correct
8 Correct 136 ms 17188 KB Output is correct
9 Correct 128 ms 16560 KB Output is correct
10 Correct 112 ms 14244 KB Output is correct
11 Correct 115 ms 14360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 13 ms 2020 KB Output is correct
5 Correct 24 ms 3548 KB Output is correct
6 Correct 82 ms 9672 KB Output is correct
7 Correct 150 ms 19168 KB Output is correct
8 Correct 136 ms 17188 KB Output is correct
9 Correct 128 ms 16560 KB Output is correct
10 Correct 112 ms 14244 KB Output is correct
11 Correct 115 ms 14360 KB Output is correct
12 Correct 39 ms 5032 KB Output is correct
13 Correct 104 ms 13252 KB Output is correct
14 Correct 147 ms 19108 KB Output is correct
15 Correct 137 ms 17316 KB Output is correct
16 Correct 157 ms 16548 KB Output is correct
17 Correct 135 ms 14292 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 2 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 620 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 13 ms 2020 KB Output is correct
12 Correct 24 ms 3548 KB Output is correct
13 Correct 82 ms 9672 KB Output is correct
14 Correct 150 ms 19168 KB Output is correct
15 Correct 136 ms 17188 KB Output is correct
16 Correct 128 ms 16560 KB Output is correct
17 Correct 112 ms 14244 KB Output is correct
18 Correct 115 ms 14360 KB Output is correct
19 Correct 39 ms 5032 KB Output is correct
20 Correct 104 ms 13252 KB Output is correct
21 Correct 147 ms 19108 KB Output is correct
22 Correct 137 ms 17316 KB Output is correct
23 Correct 157 ms 16548 KB Output is correct
24 Correct 135 ms 14292 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 41 ms 5100 KB Output is correct
33 Correct 102 ms 13252 KB Output is correct
34 Correct 187 ms 18980 KB Output is correct
35 Correct 171 ms 16676 KB Output is correct
36 Correct 145 ms 17188 KB Output is correct
37 Correct 165 ms 19128 KB Output is correct
38 Correct 140 ms 15452 KB Output is correct
39 Correct 129 ms 14484 KB Output is correct
40 Correct 119 ms 14276 KB Output is correct
41 Correct 121 ms 14340 KB Output is correct
42 Correct 129 ms 14296 KB Output is correct
43 Correct 147 ms 14244 KB Output is correct
44 Correct 145 ms 19000 KB Output is correct
45 Correct 145 ms 14648 KB Output is correct
46 Correct 125 ms 13184 KB Output is correct
47 Correct 1 ms 512 KB Output is correct