170652025-05-20 18:28:55algoproAutózáscpp17Forditási hiba
// UUID: 0ef86548-9c6e-4b46-89a4-c71e5e3dfa5f
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    ios::sync_with_stdio(0);cin.tie(0);
	int n,k;cin>>n>>k;
    vector<int>cost(n+2),dis(n+2,0),pref(n+2,0),p(n+2,0);
    for(int i=1;i<=n;i++){
        cin>>dis[i]>>cost[i];
        pref[i+1]=pref[i]+dis[i];
    }
    deque<int>deq;
    for(int i=1;i<=n+1;i++){
        while(!deq.empty() && pref[i]-pref[deq.front()]>=k)deq.pop_front();
        p[i]=deq.front();
        while(!deq.empty() && cost[deq.back()]>=cost[i])deq.pop_back();
        deq.push_back(i);
    }
    //for(int i=1;i<=n+1;i++)cout<<p[i]<<' ';
    vector<int>t;
    int c=n+1;
    while(c!=1){
        t.push_back(c);
        c=p[c];
    }
    t.push_back(1);
    reverse(t.begin(),t.end());
    //for(int x:t)cout<<x<<' ';
    int pay=0, tank=0;
    vector<pair<int,int>>ans;
    for(int i=0;i<t.size()-1;i++){
        if(cost[t[i+1]]<cost[t[i]]){
            ans.push_back({t[i],pref[t[i+1]]-pref[t[i]]-tank});
            pay+=(pref[t[i+1]]-pref[t[i]]-tank)*cost[t[i]];
            tank=max(0,tank-(pref[t[i+1]]-pref[t[i]]));
        }
        else{
            ans.push_back({t[i],k-tank});
            pay+=(k-tank)*cost[t[i]];
            tank=k-(pref[t[i+1]]-pref[t[i]]);
        }
    }
    cout<<pay<<' '<<ans.size()<<'\n';
    for(pair<int,int> x:ans)cout<<x.first<<' '<<x.second<<'\n';
}
Forditási hiba
open /var/local/lib/isolate/432/box/a.out: no such file or directory
main.cpp: In function 'int main()':
main.cpp:37:21: error: no matching function for call to 'max(int, long long int)'
   37 |             tank=max(0,tank-(pref[t[i+1]]-pref[t[i]]));
      |                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/12/bits/specfun.h:45,
                 from /usr/include/c++/12/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/12/bits/stdc++.h:41,
                 from main.cpp:2:
/usr/include/c++/12/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/12/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
main.cpp:37:21: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   37 |             tank=max(0,tank-(pref[t[i+1]]-pref[t[i]]));
      |                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/12/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/12/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
main.cpp:37:21: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   37 |             tank=max(0,tank-(pref[t[i+1]]-pref[t[i]]));
      |                  ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/12/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/12/bits/stdc++.h:65:
/usr/include/c++/12/bits/stl_algo.h:5746:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5746 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/12/bits/stl_algo.h:5746:5: note:   template argu...