include<bits/stdc++.h>
using namespace std; bool comp(pair<int,int>&a,pair<int,int>&b){ return a.second>=b.second; } int main(){ freopen("reststops.in", "r", stdin); freopen("reststops.out", "w", stdout); int length,points,rj,rb; cin>>length>>points>>rj>>rb; vector<pair<int,int>>v(points); for(int i=0;i<points;i++){ int a,b;cin>>a>>b; v[i]=make_pair(a,b); } sort(v.begin(),v.end(),comp); int sum=0; int pos=0; for(int i=0;i<points;i++){ if(v[i].first>pos){ sum+=(rj-rb)*(v[i].first-pos)*v[i].second; pos=v[i].first; } } cout<<sum<<endl; } here is my code I don't understand why my approach fails could anyone explain it? Thanks.








Again I made a stupid mistake there is signed integer overflow in my code using long long instead of int is enough for debuging.