Skip to content

Instantly share code, notes, and snippets.

@yipo
Created December 4, 2014 17:50
Show Gist options
  • Save yipo/78dabdcd7c657f48cad4 to your computer and use it in GitHub Desktop.
Save yipo/78dabdcd7c657f48cad4 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main() {
int n,x,sum=0;
cin>>n;
while (n--) {
cin>>x;
sum+=x;
}
cout<<sum<<endl;
return 0;
}
// https://paiza.jp/poh/enkoi-second/9cb00b03
#include <iostream>
using namespace std;
int main() {
int n,sum=0;
cin>>n;
while (n--) {
int a,b,price;
cin>>a>>b>>price;
if (a>b) sum+=(a-b)*price;
}
cout<<sum<<endl;
return 0;
}
// https://paiza.jp/poh/enkoi-third/0cd3b20d
#include <vector>
#include <iostream>
using namespace std;
int max_subarray(const vector<int> &array, int t) {
int n=array.size();
int sum=0;
for (int i=0;i<t;i++) sum+=array[i];
int max=sum;
for (int i=t;i<n;i++) {
sum-=array[i-t],sum+=array[i];
if (sum>max) max=sum;
}
return max;
}
int main() {
int t,n;
cin>>t>>n;
vector<int> array(n);
for (int i=0;i<n;i++) cin>>array[i];
cout<<max_subarray(array, t)<<endl;
return 0;
}
// https://paiza.jp/poh/enkoi-ending/fa81edcd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment