Submission #966803

#TimeUsernameProblemLanguageResultExecution timeMemory
966803AliyyiakbarArt Exhibition (JOI18_art)C++17
100 / 100
141 ms14948 KiB
#include <iostream> #include <vector> #include <algorithm> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/hash_policy.hpp> #define int long long #define $AzH_TxdmN$ ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr); #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native") #pragma GCC optimize("Ofast") #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("fast-math") #define pb push_back #define ep emplace_back #define all(v) v.begin(),v.end() #define pii pair<int,int> using namespace std; using namespace __gnu_pbds; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> __indexed_set; typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> __indexed_multiset; const int sz = 5e5+9; const int MOD = 1e9+7; const int INF = 1e18; pii a[sz]; int n,k; void solve() { cin>>n; for (int i = 1; i <= n; ++i) { cin>>a[i].first>>a[i].second; } sort(a+1,a+1+n); int res = 0,curr = 0,currmn = INF,currmx = -INF,nwmn,nwmx; for (int i = 1; i <= n; ++i) { nwmn = min(currmn,a[i].first); nwmx = max(currmx,a[i].first); if (curr+a[i].second-(nwmx-nwmn) < a[i].second) { curr = a[i].second; currmn = a[i].first; currmx = a[i].first; } else { currmn = nwmn; currmx = nwmx; curr += a[i].second; } res = max(res,curr - (currmx-currmn)); } cout<<res<<'\n'; } signed main() { $AzH_TxdmN$ int t = 1; //cin>>t; while (t--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...