fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <numeric>
  4. using namespace std;
  5.  
  6. int main() {
  7. long long noOfways =0;
  8. auto dist =0;
  9. vector<int> noChocolets {2,5,8,12,4,2,13};
  10.  
  11. for(auto iter = noChocolets.begin()+1;iter!=noChocolets.end();iter++)
  12. {
  13. dist+=*(iter)-*(iter-1);
  14. noOfways+= dist;
  15. }
  16. cout <<noOfways << endl;
  17.  
  18. dist =0;
  19. noOfways =0;
  20. accumulate(noChocolets.begin()+1, noChocolets.end(), noChocolets[0],
  21. [&](long long left, long long right){
  22. dist += right-left;
  23. noOfways+= dist;
  24. return right;
  25. });
  26. cout <<noOfways;
  27. return 0;
  28. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
32
32