Submission #200117

#TimeUsernameProblemLanguageResultExecution timeMemory
200117aloo123Stove (JOI18_stove)C++14
0 / 100
5 ms376 KiB
#include <iostream> #include <algorithm> #define ll long long #define ld long double #define f first #define s second #define mp make_pair #define pb push_back #define vll vector<ll> #define pll pair<ll,ll> using namespace std; const ll N = 5e5+100; const ll MOD = 1e9+7; ll pre[N]; ll maxx[N]; int main() { ios_base::sync_with_stdio(0); //cin.tie(0); ll n; cin>>n; pll a[n+1]; for(int i =1;i<=n;i++)cin>>a[i].f >> a[i].s; sort(a+1,a+n+1); for(int i =1;i<=n;i++){ pre[i] = pre[i-1] + a[i].s; } for(int i =1;i<=n;i++){ maxx[i] = max(maxx[i-1],a[i].f-pre[i-1]); } ll ans = 0; for(int j =1;j<=n;j++){ ans = max(ans,(pre[j]-a[j].f) + (maxx[j])); } cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...