Submission #875644

#TimeUsernameProblemLanguageResultExecution timeMemory
875644RequiemCake 3 (JOI19_cake3)C++17
24 / 100
4014 ms17936 KiB
#include<bits/stdc++.h> #define int long long #define pb push_back #define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); #define MOD 1000000007 #define INF 1e18 #define fi first #define se second #define FOR(i,a,b) for(int i=a;i<=b;i++) #define FORD(i,a,b) for(int i=a;i>=b;i--) #define sz(a) ((int)(a).size()) #define endl '\n' #define pi 3.14159265359 #define TASKNAME "cake3" #define all(a) a.begin(),a.end() template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; } template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; } using namespace std; typedef pair<int,int> ii; typedef pair<int,ii> iii; typedef vector<int> vi; const int MAXN = 2e5 + 9; int n,m,a[MAXN],ans=INF; ii p[MAXN]; struct Info{ int cnt=0,sum=0; }; Info st[MAXN<<2]; vector<int> listval; void update(int node,int l,int r,int pos,int val){ if (l==r){ st[node].cnt += val; st[node].sum = listval[l-1] * st[node].cnt; return; } int mid = (l+r)>>1; if (pos<=mid) update(node<<1,l,mid,pos,val); else update(node<<1|1,mid+1,r,pos,val); st[node].cnt = st[node<<1].cnt + st[node<<1|1].cnt; st[node].sum = st[node<<1].sum + st[node<<1|1].sum; } int getkth(int node,int l,int r,int k){ if (l==r){ return k * listval[l-1]; } int mid = (l+r)>>1; if (st[node<<1|1].cnt >= k) return getkth(node<<1|1,mid+1,r,k); else return st[node<<1|1].sum + getkth(node<<1,l,mid,k-st[node<<1|1].cnt); } int getval(int x){ return lower_bound(all(listval),x) - listval.begin() + 1; } main() { fast; if (fopen(TASKNAME".inp","r")){ freopen(TASKNAME".inp","r",stdin); freopen(TASKNAME".out","w",stdout); } cin>>n>>m; for(int i=1;i<=n;i++){ cin>>p[i].fi>>p[i].se; listval.pb(p[i].fi); } sort(listval.begin(),listval.end()); listval.erase(unique(all(listval)),listval.end()); sort(p+1,p+1+n,[](const ii &a,const ii &b){ return a.se < b.se; }); int ans = -INF; for(int i=1;i<=n;i++){ for(int j=i;j<=n;j++){ update(1,1,sz(listval),getval(p[j].fi),1); if (j-i+1 >= m){ int cur = getkth(1,1,sz(listval),m) - (p[j].se - p[i].se) * 2; maximize(ans, cur); } } for(int j=i;j<=n;j++){ update(1,1,sz(listval),getval(p[j].fi),-1); } } cout<<ans<<endl; }

Compilation message (stderr)

cake3.cpp:53:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   53 | main()
      | ^~~~
cake3.cpp: In function 'int main()':
cake3.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         freopen(TASKNAME".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
cake3.cpp:58:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |         freopen(TASKNAME".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...