제출 #1123796

#제출 시각아이디문제언어결과실행 시간메모리
1123796LTTrungCHLFeast (NOI19_feast)C++20
100 / 100
169 ms12180 KiB
///***LTT***/// /// ->NHAT QUOC GIA<- /// #include<bits/stdc++.h> //#pragma GCC optimize ("O3") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("popcnt") //#define int long long #define endl "\n" #define F first #define S second #define pb push_back using namespace std; //vector <int> lg2; //void LOG_ARR(int n){ // lg2.resize(n + 3); // for (int i = 1;i <= n;++i){ // lg2[i] = __lg(i); // } //} const long long oo = 1e9+7; const int N = 3 * 1e5 + 10; int n, k; long long a[N]; pair <long long, int> dp[N][2]; pair <long long, int> gendp(long long lambda){ for (int i = 1;i <= n;++i){ for (int j = 0;j <= 1;++j){ dp[i][j] = {0, 0}; } } dp[1][1] = {a[1] - lambda,1}; for (int i = 2;i <= n;++i){ dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]); dp[i][1] = max(make_pair(dp[i - 1][0].F - lambda + a[i], dp[i - 1][0].S + 1), make_pair(dp[i - 1][1].F + a[i], dp[i - 1][1].S) ); } return max(dp[n][0], dp[n][1]); } void solve(){ cin >> n >> k; for (int i = 1;i <= n;++i){ cin >> a[i]; } long long l = 0, r = 1e18; long long res = 0; while (l <= r){ long long mid = (l + r)/2; if (gendp(mid).S >= k){ l = mid + 1; res = mid; } else r = mid - 1; } pair <long long, int> ans = gendp(res); // cout << ans.F <<"\n"; cout << ans.F + res * ans.S ; return; } int main(){ ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); if (fopen("npt.inp", "r")){ freopen("npt.inp", "r", stdin); freopen("npt.out", "w", stdout); } // int t; // cin >> t; // while(t--){ solve(); // } ///////// return 0; }

컴파일 시 표준 에러 (stderr) 메시지

feast.cpp: In function 'int main()':
feast.cpp:62:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         freopen("npt.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen("npt.out", "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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...