Submission #1215854

#TimeUsernameProblemLanguageResultExecution timeMemory
1215854Madhav_1608Hacker (BOI15_hac)C++20
100 / 100
233 ms31752 KiB
#include <iostream> #include <stack> #include <queue> #include <string> #include <algorithm> #include <vector> #include <map> #include <set> #include <climits> #include <cmath> #include <unordered_map> #include <unordered_set> #include <numeric> #include <iomanip> #include <cstring> #include <stdio.h> #include <assert.h> #include <complex> #include <array> #include <utility> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<string> vs; typedef vector<long long> vll; typedef pair<ll,ll> pll; #define double long double #define F first #define S second const double eps = 1e-12; #define FOR(i,a,b) for(long long i=a;i<b;i++) #define all(v) v.begin(),v.end() template <typename I> void print(vector<I> &v){ FOR(i,0,v.size()){cout << v[i] << " ";} cout << "\n"; } ll gcd(ll a,ll b){ if(a==0){return b;} else if(b==0){return a;} else if(a<b){return gcd(b%a,a);} else{return gcd(a%b,b);} } ll lcm(ll a,ll b){ return (a/gcd(a,b))*b; } void setIO(string name = "") { freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output freopen((name + ".out").c_str(), "w", stdout); } void init_code(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif } void solve(){ // store very big numbers may mean log2. // A comparator must return false for two equal objects. Not doing so results in undefined behavior. ll n; cin >> n; vll v(n); FOR(i,0,n) cin >> v[i]; vll a(2*n); vll prefix(2*n+1,0); FOR(i,0,n){ a[i] = v[i]; a[i+n] = v[i]; } FOR(i,0,2*n){ prefix[i+1] = prefix[i]+a[i]; } multiset<ll> S; ll sz = n/2; ll ans = INT_MAX; FOR(i,sz,n){ S.insert(prefix[i]-prefix[i-sz]); } FOR(i,n,2*n+1){ ans = min(ans,*S.rbegin()); S.insert(prefix[i]-prefix[i-sz]); S.erase(S.find(prefix[i-n+sz]-prefix[i-n])); } ll sumi = 0; FOR(i,0,n) sumi+=v[i]; cout << (sumi-ans) << "\n"; } signed main(){ //setIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // init_code(); ll t=1; // cin >> t; while(t--){ solve(); } return 0; }

Compilation message (stderr)

hac.cpp: In function 'void setIO(std::string)':
hac.cpp:48:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |     freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hac.cpp:49:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     freopen((name + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hac.cpp: In function 'void init_code()':
hac.cpp:53:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |     freopen("input.txt","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
hac.cpp:54:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |     freopen("output.txt","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...