12832022-03-29 20:43:02k_balintAutózáscpp14Accepted 100/10068ms29416 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int c=3e5+5;

int n,k,fuel;
ll pref[c],prc[c];
int best[c];

ll tot;
vector<pair<int,int>> ans;

stack<int> s;
ll dist(int i, int j){
    return pref[j]-pref[i];
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin>>n>>k;

    for(int i=1;i<=n;i++){
        cin>>pref[i+1]>>prc[i];
        pref[i+1]+=pref[i];
    }
    prc[n+1]=-1;

    s.push(n+1);
    for(int i=n;i>=1;i--){
        while(prc[i]<prc[s.top()]){
            s.pop();
        }
        best[i]=s.top();
        s.push(i);
    }

    int cur=1; fuel=0;
    while(cur <= n){
        int d=dist(cur,best[cur]);
        if(d > k){
            //if(cur==3) cout << d << endl;
            int nw=k-fuel;
            if(nw>0){
                fuel+=nw;
                tot+=prc[cur]*nw;
                ans.push_back(make_pair(cur,nw));
            }
            fuel-=dist(cur,cur+1);
            ++cur;
        }
        else{
            int nw=d-fuel;
            if(nw>0){
                fuel+=nw;
                tot+=prc[cur]*nw;
                ans.push_back(make_pair(cur,nw));
            }
            fuel-=dist(cur,best[cur]);
            cur=best[cur];
        }
    }

    cout << tot << ' ' << ans.size() << '\n';

    for(pair<int,int> x:ans){
        cout << x.first <<  ' ' << x.second << '\n';
    }
}
SubtaskSumTestVerdictTimeMemory
base100/100
1Accepted0/02ms1832 KiB
2Accepted0/052ms15392 KiB
3Accepted5/51ms3632 KiB
4Accepted5/51ms3636 KiB
5Accepted5/51ms3644 KiB
6Accepted5/51ms3648 KiB
7Accepted5/51ms3648 KiB
8Accepted5/51ms3656 KiB
9Accepted5/51ms3656 KiB
10Accepted5/51ms3704 KiB
11Accepted5/513ms6628 KiB
12Accepted5/518ms8580 KiB
13Accepted5/517ms8704 KiB
14Accepted5/532ms13360 KiB
15Accepted5/545ms16724 KiB
16Accepted5/543ms16652 KiB
17Accepted5/541ms17968 KiB
18Accepted5/539ms18688 KiB
19Accepted5/564ms25360 KiB
20Accepted5/564ms26196 KiB
21Accepted5/568ms28548 KiB
22Accepted5/567ms29416 KiB