Untitled
unknown
plain_text
6 months ago
678 B
5
Indexable
#include <bits/stdc++.h> using namespace std; #define int long long int int maxSubarraySum(vector<int> &arr) { int res = arr[0]; int maxEnding = arr[0]; for (int i = 1; i < arr.size(); i++) { maxEnding = max(maxEnding + arr[i], arr[i]); res = max(res, maxEnding); } return res; } int32_t main() { int x; cin>>x; int n; cin>>n; vector<int> arr(n); int sum =0; for(int i=0;i<n;i++){ int x; cin>>x; sum+=x; arr[i]=x; } vector<int> small(n); for(int i=0;i<n;i++){ small[i] = arr[i]/x; } cout<<max(maxSubarraySum(arr)*x,maxSubarraySum(small))<<endl; }
Editor is loading...
Leave a Comment