代码逻辑和操作有问题吗?

img

img


我的代码输出一直报错,我找不出问题我觉得没错, 请指出是逻辑问题还是代码错误谢谢。

我以前做过和这题类似的题目,代码稍等
思路:贪心问题,肯定先用大的面值,这样张叔更少

动态规划,获取每个人的工资最小的钞票张数

#include <iostream>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main() {
  int n, a[100];
  while(cin>>n) {
    int s = 0; 
    if(n == 0) break;
    
    for(int i=0; i<n; i++) {
      cin>>a[i];
    }
    
    for(int i=0; i<n; i++) { 
      if(i < n) {  // 防止越界
        s += a[i]/100 + a[i]%100/50 + a[i]%50/10 + a[i]%10/5 + a[i]%5/2 + a[i]%2;  
      }
    }
    
    cout << s << endl;
  }

  return 0;
}