Created
December 4, 2014 17:50
-
-
Save yipo/78dabdcd7c657f48cad4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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