Submission #833134

#TimeUsernameProblemLanguageResultExecution timeMemory
833134josanneo22Feast (NOI19_feast)C++17
22 / 100
28 ms8024 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define ar array
long long maxSubArraySum(vector<long long> a, int size)
{
	long long max_so_far = LLONG_MIN, max_ending_here = 0;
	int starting_index = 0, ending_index = 0, s = 0;
	for (int i = 0; i < size; i++) {
		max_ending_here = max_ending_here + a[i];
		if (max_so_far < max_ending_here) {
			max_so_far = max_ending_here; starting_index = s; ending_index = i;
		}

		if (max_ending_here < 0) {
			max_ending_here = 0;
			s = i + 1;
		}
	}
	return max_so_far;
}
void solve(){
	int n,k; cin>>n>>k;
	vector<int> a(n); for(int i=0;i<n;i++) cin>>a[i];
	cout<<max(0LL,maxSubArraySum(a,n))<<'\n';
}
signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	clock_t tStart = clock();
	int local=0,multi=0,debug=1,tt=1;
	if(local){
	    freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
	}	
	if(multi) cin>>tt;
	for(int i=1;i<=tt;i++){
		if(debug && multi && local) cout<<"样例 "<<i<<'\n';
		solve();
 	}
	fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
}

Compilation message (stderr)

feast.cpp: In function 'long long int maxSubArraySum(std::vector<long long int>, long long int)':
feast.cpp:15:6: warning: variable 'starting_index' set but not used [-Wunused-but-set-variable]
   15 |  int starting_index = 0, ending_index = 0, s = 0;
      |      ^~~~~~~~~~~~~~
feast.cpp:15:26: warning: variable 'ending_index' set but not used [-Wunused-but-set-variable]
   15 |  int starting_index = 0, ending_index = 0, s = 0;
      |                          ^~~~~~~~~~~~
feast.cpp: In function 'int main()':
feast.cpp:39:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |      freopen("input.txt","r",stdin);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:40:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |      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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...