Saverix339

Untitled

Mar 27th, 2021 (edited)
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cstdlib>
  5. #include <vector>
  6. using namespace std;
  7.  
  8.  
  9. #define MAXN 300000
  10.  
  11. int main() {
  12.     freopen("input.txt","r",stdin);
  13.     freopen("output.txt","w",stdout);
  14.  
  15. int n, p, a;
  16.     cin>>n;
  17.     int carrello[n];
  18.     for (a=0; a<n;a++){
  19.         cin>>carrello[a];
  20.     }
  21.     int totale;
  22.     sort(carrello, carrello + n);
  23.     p=0;
  24.     while (p<n) {
  25.         p++;
  26.         totale=totale+carrello[p];
  27.         p++;
  28.         totale=totale+carrello[p];
  29.         p++;
  30.     }
  31.     cout<<totale;
  32.     return 0;
  33. }
Add Comment
Please, Sign In to add comment