Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <list>
- #include <algorithm>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- int main ()
- {
- //Deklaracja zmiennych
- vector<int> ciag;
- int x, wynik, sufiks;
- int a=0;
- srand(time(0));
- cin>>x;
- //Wczytywanie do vectora
- while(x){ //działa póki x!=0
- ciag.push_back(a);
- a=a+(rand()%5+1);
- x--;
- }
- //Szukanie przywódcy ciągu O(n)
- wynik=0;
- sufiks=0;
- for (int i=0; i<ciag.size()-1; i++){
- sufiks=max(ciag[i]+sufiks, 0);
- wynik=max(sufiks, wynik);
- }
- cout<<wynik<<endl;
- //Wypisywanie ciagu
- /*
- for(int i=0; i<ciag.size()-1; ++i){
- cout << ciag[i] << " ";
- }*/
- return 0;
- }
Add Comment
Please, Sign In to add comment