Problem p02402 (C++) — buggy submission, verdict: Time Limit Exceeded

/**
 * ????°????????????§??????????¨????

n ????????´??° ai(i=1,2,...n)
?????\\?????????????????????????°????????????§??????????¨????????±???????????????°????????????????????????????????????

Input
??????????????´??°?????° n ???????????????????????????????????? n ????????´??°
ai
????????????????????§?????????????????????

Output
????°????????????§??????????¨????????????????????????§????????????????????????????????????

Constraints
0<n???10000
???1000000???ai???1000000

Sample Input
5
10 1 5 4 17
Sample Output
1 17 37
 */

#include <algorithm>
#include <iostream>
#include <numeric>
#include <sstream>
#include <vector>

int main(int argc, char const *argv[]) {
  unsigned int n = 1;
  std::string Param;

  while (true) {

    getline(std::cin, Param);
    std::istringstream iss(Param);
    iss >> n;

    if (n < 1 || n > 10000) {
      std::cout << "Error: 1 <= n <= 10000" << std::endl;
    } else {
      break;
    }
  }

  // unsigned int Ai[n];
  std::vector<int> Ai(n, 0);
  while (true) {
    bool isValid = true;

    getline(std::cin, Param);
    std::istringstream iss(Param);
    for (size_t i = 0; i < n; i++) {
      iss >> Ai[i];
      if (Ai[i] < -1000000 || Ai[i] > 1000000) {
        std::cout << "Error: -1000000 <= Ai <= 1000000" << std::endl;
        isValid = false;
        break;
      } else {
        isValid = true;
      }
    }
    if (isValid == true) {
      break;
    }
  }
  std::cout << *(std::min_element(Ai.begin(), Ai.end())) << " "
            << *(std::max_element(Ai.begin(), Ai.end())) << " "
            << std::accumulate(Ai.begin(), Ai.end(), (long long int)0)
            << std::endl;

  return 0;
}

Error: TLE

Fixed submission:

/**
 * ????°????????????§??????????¨????

n ????????´??° ai(i=1,2,...n)
?????\\?????????????????????????°????????????§??????????¨????????±???????????????°????????????????????????????????????

Input
??????????????´??°?????° n ???????????????????????????????????? n ????????´??°
ai
????????????????????§?????????????????????

Output
????°????????????§??????????¨????????????????????????§????????????????????????????????????

Constraints
0<n???10000
???1000000???ai???1000000

Sample Input
5
10 1 5 4 17
Sample Output
1 17 37
 */

#include <algorithm>
#include <iostream>
#include <numeric>
#include <sstream>
#include <vector>

int main(int argc, char const *argv[]) {
  unsigned int n = 1;
  std::string Param;

  while (true) {

    getline(std::cin, Param);
    std::istringstream iss(Param);
    iss >> n;

    if (n < 1 || n > 10000) {
      std::cout << "Error: 1 <= n <= 10000" << std::endl;
    } else {
      break;
    }
  }

  // unsigned int Ai[n];
  std::vector<int> Ai(n, 0);
  while (true) {
    bool isValid = true;

    getline(std::cin, Param);
    std::istringstream iss(Param);
    for (size_t i = 0; i < n; i++) {
      iss >> Ai[i];
      if (Ai[i] < -1000000 || Ai[i] > 100000) {
        std::cout << "Error: -1000000 <= Ai <= 1000000" << std::endl;
        isValid = false;
        break;
      }
    }
    if (isValid == true) {
      break;
    }
  }
  std::cout << *(std::min_element(Ai.begin(), Ai.end())) << " "
            << *(std::max_element(Ai.begin(), Ai.end())) << " "
            << std::accumulate(Ai.begin(), Ai.end(), 0) << std::endl;

  return 0;
}