Submission #144771

#TimeUsernameProblemLanguageResultExecution timeMemory
144771mariadincaCover (COCI18_cover)C++14
120 / 120
11 ms760 KiB
#include <iostream> #define x first #define y second #include <algorithm> using namespace std; long long n, m, i, j, k, ymin, ymax, verticala, verticalaanterioara, sol[20002], sum; pair<long long, long long> v[20002], d[20002]; int main(){ cin>>n; m = n; for(i=1;i<=n;i++){ cin>>v[i].x>>v[i].y; v[++m].x = v[i].x, v[m].y = -v[i].y; v[++m].x = -v[i].x, v[m].y = -v[i].y; v[++m].x = -v[i].x, v[m].y = v[i].y; } sort(v+1, v+m+1); for(i=1;i<=m;i++){ if(v[i].x > 0) break; ymax = 0; ymin = v[i].y; for(j=i;v[j].x == v[i].x;j++) if(v[j].y > 0) ymax = v[j].y; verticala = max(ymax, -ymin); /// deci dreptunghiul curent are aria egala cu -4*verticala*v[i].x if(verticala > verticalaanterioara){ verticalaanterioara = verticala; d[++k].x = -2*v[i].x; d[k].y = 2*verticala; } i = j; } for(i=1;i<=k;i++){ sol[i] = d[1].x*d[i].y; for(j=1;j<=i;j++){ sol[i] = min(sol[i], sol[j-1] + d[j].x*d[i].y); } } cout<<sol[k]; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...