[Question]
  [
You work at a bakery and every day you make exactly 100 bagels. However your customers are not as reliable and every day a random number of bagels will be ordered. So sometimes you will run out of bagels and sometimes you will have leftovers.
Now leftover bagels will still be good for 1 more day. After a day on the shelves they have to be tossed. But until then you can still sell them. So you keep them for the next day. Customers will *prefer* fresh bagels so if you haven't run out of fresh bagels they will get a fresh bagel. Only when you are out of fresh bagels will they ask for a day-old bagel.
So for example if you have have 25 bagels left over one day and the next day 100 bagels are ordered, you don't sell any of the old bagels so you throw them out and have 0 leftover bagels the next day.
Your task is to write a program or function which takes a non-empty list of non-negative integers representing how many orders were placed in a given time:
e.g.
```
[106,25,134,99,85,12]
```
means that on the first day 106 bagels were ordered, on the second day 25 bagels were ordered and then 134 etc.
Your task is to calculate how many bagels were sold in the described period. You should assume that at the start of the period there will be no leftover bagels available.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so answers will be scored in bytes with fewer bytes being the goal.
## Test cases
```
[100,100,100] -> 300
[372,1920,102] -> 300
[25,25,25] -> 75
[25,100,120] -> 225
[0,200] -> 200
[0,175,75] -> 250
[75,150,150] -> 300
[0,101,199]-> 201
[200,0] -> 100
```
  
[Answer]
# [Perl 5](https://www.perl.org/) + `-p -MList::Util+min`, 28 bytes
```
$\+=min$_,100+$-;$-=100-$_}{
```
[Try it online!](https://tio.run/##K0gtyjH9/18lRts2NzNPJV7H0MBAW0XXWkXXFsjSVYmvrf7/38iUC8jhMjQy@JdfUJKZn1f8X7fgv66vT2ZxiZVVaElmjjZQMwA "Perl 5 ‚Äì Try It Online")
## Explanation
Adds the `min`imum of `$_` (implicit input via `-p`) or `100+$-` (where `$-` starts as `0`) to `$\` (which is automatically output at the end of all lines of input).
`$-` is set to `100-$_`, which is safe because `$-` can never be negative.
[Answer]
# [BQN](https://mlochbaum.github.io/BQN/), 17 bytes[SBCS](https://github.com/mlochbaum/BQN/blob/master/commentary/sbcs.bqn)
```
+¬¥‚ä¢‚åä100+¬∑¬ª0‚åà100‚ä∏-
```
[Run online!](https://mlochbaum.github.io/BQN/try.html#code=RiDihpAgK8K04oqi4oyKMTAwK8K3wrsw4oyIMTAw4oq4LQoKRsKo4p+oMTAw4oC/MTAw4oC/MTAwLDM3MuKAvzE5MjDigL8xMDIsMjXigL8yNeKAvzI1LDI14oC/MTAw4oC/MTIwLDDigL8yMDAsMOKAvzE3NeKAvzc1LDc14oC/MTUw4oC/MTUwLDDigL8xMDHigL8xOTnin6k=)
-1 from ovs.
## Explanation
```
{+¬¥ùï©‚åä100+¬ª0‚åà100-ùï©}
            100-ùï© subtract input from 100
          0‚åà      maximum with 0
         ¬ª        shift right, prepending a 0
     100+         add 100. This is the number of bagels available on a day.
   ùï©‚åä             minimum with input
 +¬¥               sum the minimums
```
[Answer]
# Brainfuck, 148 bytes
```
,[->[-]>[-<+>]>++++++++++[-<++++++++++>],[>>>+<<<-<[->>+>>-<<<<[->>>+<<<]]>>>[-<<<+>>>]>[-<<<<<[->>>+<<<[->>>>+<<<<]]>>>>[-<<<<+>>>>]>]<<<]<<<]>>>>.
```
First is inputed length of array, then the values. Sadly I can't find any site which supports input&output as decimal numbers. Best I got is [this site](https://copy.sh/brainfuck/) where you can input escape squences like `\3\100\100\100`, but the output is ASCII, so you will need to convert it to decimal. (Please let me know about any sites supporting decimal in comments)
## Explanation
**Memory map**: `arrayLength old fresh order output temp flag`
```
,[-                          loop through all elements of array
  >[-]                       reset old count
  >[-<+>]                    set old count to the remaining amount from fresh
  >++++++++++[-<++++++++++>] set fresh to 100
  ,[                         while there is order
    >>>+                     set flag
    <<<-                     reduce order size
    <[                       check if there are any fresh
      -                      reduce amount of fresh
      >>+                    increase output
      >>-                    unset flag
      <<<<[->>>+<<<]         copy fresh to temp variable so condition can exit
    ]
    >>>[-<<<+>>>]            copy from temp back to fresh
    >[                       check if flag is set (if previous condition wasnt executed it acts as else)
      -                      unset flag
      <<<<<[                 check if there are any old
        -                    reduce amount of old
        >>>+                 increase output
        <<<[->>>>+<<<<]      copy old to temp variable so condition can exit
      ]
      >>>>[-<<<<+>>>>]       copy from temp back to old
      >
    ]<<<
  ]<<<
]
```
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), ~~57~~ ~~55~~ 54 bytes
```
x=>x.map(i=>[s+=i>a?a:i,a=i>99?100:200-i],s=0,a=100)|s
```
[Try it online!](https://tio.run/##RY3BisIwEIbv@xTixWSd1mSklCqJt32BPZayjDWVSGy7jSsu7Lt3kyoUMmHmG775L3QnXw@2vyVtdzJjo8aH0o/0Sj2zSpd@raymA@0sUOiK4iCF2KEQia3AKxFoAPzPj/vBfP/YwbBl45c8HQydPqwzn79tzQSsHN1sK1dx0TuqDduw9J0nOv6bM7AvIDhypeuu9Z0zqevOrGHmTo4R5zC3Sq2PnI9liIVXVYtEL7ZCvJXbHEEWGCnOFDOY3kTybAKTik8VMTAB@LqE0QnbPIP86WAWSBhlJmLNl2OQDIlFNXnyHw "JavaScript (Node.js) ‚Äì Try It Online")
Badly golfed maybe...
[Answer]
# [Haskell](https://www.haskell.org/), 42 bytes
```
sum.(zipWith(min.max 100.(-)200)=<<(100:))
```
[Try it online!](https://tio.run/##VY/BCoMwDIbvfYocW@ikjRRx6CPsvIPI6EGxzIqsHYy9vEvL3BCaQ7/8@f9ksuE@zPO2jW14@oK/3Xp1ceLeLYW3L9BKFfwkUCnRNg2n71mILQ4hBmgZdMA7YvJbvYSSlAwk8bJCqWtMDTw00Mj8CFbmz7IHJg/EHSuJ2RV/w6SpjKzSMJodEtFGpToEpWhNO9TZQe9RlJN0Out6xrx1SzoGvF0vN@Drwy0RChhThSggn8u2Dw "Haskell ‚Äì Try It Online")
Since there's now a Haskell answer I thought I'd toss mine in the ring.
[Answer]
# Excel, 66 bytes
```
=LET(o,A:A,a,100+INDEX((100-o)*(o<100),ROW(o)-1),SUM(IF(o<a,o,a)))
```
Input is in the range `A:A` with each day's order in a cell by itself. Output is wherever the formula is.
The `LET()` function allows you to define variables and later reference them by that variable name. The terms come in pairs (`variable, value`) except the last term which is just the output value.
* `o,A:A` defines `o` (orders) to be the entirety of column A. This technically limits you to about 2,870 years of bagel orders. I consider this to be acceptable.
* `a,100+INDEX((100-o)*(o<100),ROW(o)-1)` defines `a` (available) and does most of the heavy lifting so let's break it down into pieces.
	+ `100` is how many bagels are made fresh each day.
	+ `(100-o)` is how many leftover fresh bagels there are each day.
	+ `*(o<100)` filters out negatives (more orders than fresh so no leftovers).
	+ `ROW(o)-1` tells us that we're going to be looking at the data for the previous day.
	+ In plain(er) text: `100+INDEX([leftover fresh]*[not negative],[from yesterday])`.
	+ All together, you could read it as `[fresh] + [yesterday's fresh leftovers]`.
* `IF(o<a,o,a)` returns either the number of orders (if it was less than what was available) or just what was available.
* `SUM(IF(~))` adds it all up.
[![Result](https://i.stack.imgur.com/6Fsz0.png)](https://i.stack.imgur.com/6Fsz0.png)
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 14 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
—Çs-Dd*—Ç+—Ç≈°√∏‚Ç¨√üO
```
Port of [@Razetime's BQN answer](https://codegolf.stackexchange.com/a/241377/52210).
[Try it online](https://tio.run/##ASsA1P9vc2FiaWX//9GCcy1EZCrRgivRgsWhw7jigqzDn0///1swLDEwMSwxOTld) or [verify all test cases](https://tio.run/##yy9OTMpM/V9Waa@k8KhtkoKSfaXL/4tNxbouKVoXm7QvNh1deHjHo6Y1h@f7/9f5Hx1taGCgA8WxOtHG5kY6hpZGIK4RkGtkqgNGECZYmRFImYGOkQGENjQ31TEHyQNpQ1MDEIaIGxgCDbIEaQTqMoiNBQA).
**Explanation:**
```
                #  e.g. input = [0,101,199]
—Çs-             # Subtract the values in the (implicit) input-list from 100
                #  STACK: [100,-1,-99]
   D            # Duplicate this list
                #  STACK: [100,-1,-99],[100,-1,-99]
    d           # Check for each that they're non-negative (>=0)
                #  STACK: [100,-1,-99],[1,0,0]
     *          # Multiply the values at the same positions
                #  STACK: [100,0,0]
      —Ç+        # Add 100 to each
                #  STACK: [200,100,100]
        —Ç≈°      # Prepend 100
                #  STACK: [100,200,100,100]
          √∏     # Create pairs with the (implicit) input-list,
                # ignoring the additional trailing item
                #  STACK: [[0,100],[101,200],[199,100]]
           ‚Ç¨√ü   # Get the minimum of each pair
                #  STACK: [0,101,100]
             O  # Sum those minima
                #  STACK: 201
                # (after which the result is output implicitly)
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), ~~37~~ 36 bytes
```
Tr[i=c=100;Min[2c-c~Min~i,i=#]&/@#]&
```
[Try it online!](https://tio.run/##LYzBCgMhDETv/sZCT1kaU0SWYukPFArtTXoQ6VIPu4fFm@iv2yhCJrwhM9lc/H03F4N3dTX1fdhgvJGI10fYLfnZF4YSIJjpczrfedXnEfZop/m2Nlte3u0licQlGMog0kUTyIWap@ZJQZ/BPUk9iUA4QGoFukcYpMKmcUHJ75be5ipmkesf "Wolfram Language (Mathematica) ‚Äì Try It Online")
[Answer]
# C(gcc -O0), ~~115~~ ~~109~~ ~~84~~ ~~82~~ 78 bytes.
```
m,l,g;f(a,n)int*a;{m=l=0;for(g=100;n--;++a)m+=fmin(g+l,*a),l=*a<g?g-*a:0;m=m;}
```
[Try it online!](https://tio.run/##HY5BDoIwFET3nKLRmFD4NQUWRj/Vg6iLn2IrSVsM4IpwdWt1dpN5MxktrNYxenBg0eQEgfdhLggXr5ySaIYxt6qSEoMQWJbEfamM70NuSwcFcXCqoNZerCjoJNErj2vc9kG7d/dg7TR3/bB/nrO0yjylHl8ylvTzNI7V9a6W5lBDdawlVLJe8R@/xgSYfLPrbmEDLD1LLLCGc8zWLMb40caRnaJw/gs)
The function takes two arguments, a pointer to the array and the size of the array.
*-25 bytes thanks to AZTECCO*
*-4 bytes thanks to ceilingcat*
Can I golf it further?
[Answer]
# [Python](https://www.python.org), 56 bytes
```
lambda a:sum(map(min,[200-min(r,100)for r in[100]+a],a))
```
[Attempt This Online!](https://ato.pxeger.com/run?1=NU1bCsIwEPz3FPlMMMImUvoAT1LzEbGhgSYNMVU8iz8F0Wt4jt7GpFHYYWd2Z3Yfb3cP_WjnpzocX1NQu2qpBmlOZ4lkc5kMNtJhoy1tOcAuEuwpAyBq9MgjbdsoxFYKKgnJ-c-t10OHWOO8tgEr3F3lgLV1U8CE_F3z0qco_UFs2n3JKat5kjxKXtC1Ml1tPNmAcsidlQUt0z52VkBCngOLh-oUjCkQ-eEX)
If it weren't for Python 2 padding arguments to `map` with `None`s, we could abuse its global ordering like so:
```
lambda a:sum(map(min,[200-min(r,100)for r in[a]+a],a))
```
because `a` will always be "larger" than `100`.
As it is, we have to work around it with `a+[0]))` for [58](https://ato.pxeger.com/run?1=NU1BCsIwELz7ihxTuoVNpFQLviTmENHQQJuGmCK-xUtBxC_4lf7GpFHYYWZ3Z2cfb3cP3Wj5_NSH42sKutotba-G01kR1V6ngQ7K0cFYEByxioJ6YIiFHj3xxFihZKkkqFKgLIqc8Ll1pr8Q1jpvbCCaGuumQP_reelEjIAf5EZsGw5sz1PLY8trWCvL1caTDYFjZtbU0KR9ZFZjQp4ji0H7dBivUOaHXw).
---
## [Python](https://www.python.org), 58 bytes
```
lambda a,S=100:sum(min(r,100-S+(S:=min(r,100)))for r in a)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=PU1BCoMwELz3FTluaIQkRawBX-HRekipwYBGSWNL39KLUNpv9B3-pomRwg67szsz-_yMD9cOZn6p4vSenEqOi-hkf75IJElZMErFdeqh1wYs8Swp91CK4s8xxmqwyCJtkMQx4XtvddcgJkarjQMFzU12oM04OfD6TTUvbeUDyIZ6Vx0yTljOA-We8pSsFcdVxoOMEk5jZ1lKsnD3naU0IO4p80F5MHoXrePDHw)
[Answer]
# [R](https://www.r-project.org/), ~~51~~ 48 bytes
```
function(n,`~`=pmin)sum(c(n,0)~100-c(0,n-100~0))
```
[Try it online!](https://tio.run/##VY5LCsMwDETX7SkM3Vggg6xgTKC9S8BgyCJuaZutr@7InywCEog30oy@JaqnUSXuKfzXd9IJl7y8Ptua4LdvOgggyJbIBE2YjEyZAEoUSWYcDXB7qInoXvnkGe3MVeCLwA5bCRTq3QmbCXcT5o4JudlWNM5lyTv045xdp4Kso9qXrJpu5Y359LA9TaKGraSWAw "R ‚Äì Try It Online")
Ports [Razetime's BQN answer](https://codegolf.stackexchange.com/a/241377/67312).
-3 bytes thanks to pajonk.
[Answer]
# [J](http://jsoftware.com/), 19 bytes
```
+/@:<.100>.0,200-}:
```
[Try it online!](https://tio.run/##VY1BCoAwEAPvvmKPilqzK6W0qPgXsYgXX@Dba1XEFjaHDJtkD8GPjupudoNiYFJoBGhPF9ZlO6j0FOmnqvhgb4TYyk3lp6Lfy8iTlSQLEmSWjSaThKJljVvZFzhO2qQ7FqMKFw "J ‚Äì Try It Online")
* `}:`: Remove the last number.
* `200` `-`: Subtract each number from 200.
* `0` `,`: Prepend 0.
* `100` `>.`: Take the maximum of each number with 100. This produces the number of available bagels for each day.
* `<.`: Take the minimum of that and the original values...  
`@:`: and then (using composition)...  
`+/`: take the sum of the values.  
(This whole thing is a hook.)
[Answer]
# [Python 3.8 (pre-release)](https://docs.python.org/3.8/), 63 62 bytes
```
f=lambda o,*v,l=1:min(o,99+l)+(len(v)and f(*v,l=max(1,101-o)))
```
[Try it online!](https://tio.run/##TY/RCoMwDEXf/Yo8tlsGTaW4DvwS8cHhZAVtRcvYvt6l1cGgeejJvTfJ/InP4MvrvGzbUI/ddO87CHh64VjTbXJeBLT2PMqzGB9evGTnexhE7k/dWxCSokuQUm7xscYVamgK0ZBSeFSLUColkWlZaSSrE9Z/WBvMj1FlfiS7dXJrs0OFOqfpw8b9ymBlsmRH/CejUv3Fp3G8prXZS/sATk8aypq2GMICwmGQ4DzkQ24FzIvzkSmf6yT3ti8 "Python 3.8 (pre-release) ‚Äì Try It Online")
Takes the input as a vararg list
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 22 bytes
```
Ôº©Œ£Ôº•Œ∏‚åä‚ü¶Œπ‚åà‚ü¶¬π‚Å∞‚Å∞‚àßŒ∫‚Åª¬≤‚Å∞‚Å∞¬ßŒ∏‚äñŒ∫
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRMM5sbhEI7g0V8M3sUCjUEfBNzMvMxfIjc4EshMrIGxDAwMdBce8FI1ssILSYg0jsEiJZ15KagVIm0tqclFqbmpeSSpQkSYQxAIhCFj//x8dbaBjaGCoY2hpGRv7X7csBwA "Charcoal ‚Äì Try It Online") Link is to verbose version of code. Explanation:
```
   Œ∏                    Input array
  Ôº•                     Map over orders
    ‚åä‚ü¶                  Minimum of
      Œπ                 Today's order and
       ‚åà‚ü¶               Maximum of
         ¬π‚Å∞‚Å∞            Literal integer `100` and
             Œ∫          Current index
            ‚àß           Logical And
               ¬≤‚Å∞‚Å∞      Literal integer `100`
              ‚Åª         Subtract
                  ¬ßŒ∏‚äñŒ∫  Previous day's order
 Œ£                      Take the sum
Ôº©                       Cast to string
                        Implicitly print
```
[Answer]
# APL+WIN, 24 bytes
Prompts for input
```
+/b‚åä100+¬Ø1‚Üì0,0‚åàn‚Üê100-b‚Üê‚éï
```
[Try it online! Thanks to Dyalog Classic](https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v@ob6qvz6O2CcZcQJanP5BlyPWooz3tv7Z@0qOeLkMDA@1D6w0ftU020DF41NORB1JgYKCbBKSBGv4DlXL9T@MCCilAMVcal7G5kYKhpRGIawTkGpkqgBGECVZmBFJmoGBkAKENzU0VzEHyQNrQ1ACEIeIGhkCDLEEagboMAA "APL (Dyalog Classic) ‚Äì Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), ~~57~~ 55 bytes
```
(0!)
r!(x:t)|x>100=0!t+min(100+r)x|j<-100-x=x+j!t
_!x=0
```
[Try it online!](https://tio.run/##VZBBbsMgEEX3PsU4KxBYAiLLShVygnTVpWNFVmQ3SW0X2VRl4bOXDrh1G4mR0Psz/w9c6@mt6Trf6pMnIqXJmBL3ZOnsDlIILVLL@ttA8M5G6ub7PsNr5rRj99Qm59Rp4fv6NoCGvjbPZzAf9sWOxwHKBMh0ff8E20yWMrY5DRvGfuHYTBAgAMIFEWic0ToqSz9OQAIziRY8yEBhn5UIAUiJm/CfqjhshaB8EbaF4nKngqIeFZXzeJAW@T8YbVSwUWrlgqvorP7msavIeRHmVb5SRDIXoR7TwgISN9lFE7nmYVjoxFBaIesaG/5Dt/GdUCX@69J29evks4sx3w "Haskell ‚Äì Try It Online")
*saved 2 Bytes thanks to @Wheat Wizard*
[Answer]
# x86-64 machine code, 24 bytes
```
31 c0 99 97 91 ad 01 c7 83 e8 64 01 c2 78 02 29 d7 99 21 c2 e2 ef 97 c3
```
Fixed.  
[Try it online!](https://tio.run/##bVTvb9owEP2M/4oT1bZkMgjoT2Cd1NFO6zRtUvulUtcPJnGCN8dObQeYEP/62DkhNGVEJCQ@v3fv3l0S5XknjaLNhtkMArhrB6SbSj1lEqYs5dKS6m9EWkttgLMl9RfA4whurh7gEnpd0oriZ2geGLuuY8tolgKPRQ3EGC4xlXLcdAuB5Cp1sxAWws1KyqAX7mDR8hBs8tDYvcUjBPaOIzy/cMNpmWghpISZljG4GQdVZFNuQCfbOsFihAJTsZdOrBwdpGuwdCStVKBVXKh0j1byxOk53lf8KE/q2Mav@L5pVqmJCmO4cjVcgVBO@/JQUTxnKqr5c40R3CEU3NzfIimL46a5SHoVv67QxGgBLmnvAiJsMa362O/1KsR9MXWGRa5cSYzOqsy50XFRZlYdjOySLfeSldGK/39URyLuF9r7W@SNyr8WWQ4iQaHMvbOgeMqcmHMIMm143RI2Z0KyqeR@m6orCesayqrjrZDgB9ZsFsLy8KUeb4OdaeMShl3b6tlW6L3wokaHpvez77If4bLBJY1IFUyF861Fd7wZat@MT8J5AXD1/XoMGfvNbcnBnwt8nfysYsF1pRR6oGvJ5XDoHKxsaJjoAici1gtVKfYqqlkvuz9Brz2omgzmMKH6A05k3B586e6xlKiqxXBbSAeBp7m@DXfDhjjD3Z4Vd9wVRnVJ2IZwTPgSp09Be9KGFcK2nQr8raIQaWWdp4P3LByvCTkSKpJFzOGDdbHQ3dlHQqxDAyKwzhS@Rdy6iKFpJZ0al2j2ePGE8DpmH5/wW7Iiq2O6whbS7ble03Lp@HxA@8OBXxvUa4NTWv4azyVqUKEGdNWjgxcKjJyf0vPddnzon/b82djR62OaYY1HNK2iZ17Vmc/XPz6hwyG9wDtUQtZj4qvJmFBBSFakleAnNKhMYgV6/tbBaOeADUmrlRtEJEH7jfip2rS213XRXNdlIXZgvdn8jRLJUrvpZGcneMFP96X/Ksh/)
Following the standard calling convention for Unix-like systems (from the System V AMD64 ABI), this takes the length in RDI and the address of an array of 32-bit integers in RSI.
Assembly:
```
.global bagels
bagels:
    xor eax, eax    # EAX = 0.
    cdq             # EDX = 0.
    xchg edi, eax   # Exchange EDI (length) with EAX (0).
    xchg ecx, eax   # Exchange ECX with EAX (length).
                    #   Here, EDI will hold the number of bagels sold, and EDX
sl:                 #    will hold -l, with l being the number of leftover bagels.
    lodsd           # Load the current number n into EAX, advancing the pointer in ESI.
    add edi, eax    # Add the number ordered to EDI.
    sub eax, 100    # Subtract 100 from EAX, producing n-100.
    add edx, eax    # Add n-100 to EDX, producing n-100-l.
    js skip         # Jump if that's negative (more bagels available than ordered).
    sub edi, edx    # (Otherwise) Subtract the shortfall n-100-l from EDI.
skip:
    cdq             # Fill EDX with the sign bit of EAX.
    and edx, eax    # Bitwise AND; makes EDX equal n-100 if it's negative, 0 otherwise.
    loop sl         # Count down from the length in ECX, looping that many times.
    xchg edi, eax   # Switch the result (in EDI) into EAX.
    ret             # Return.
```
[Answer]
# [Java (JDK)](http://jdk.java.net/), 73 bytes
```
a->{int s=0,l=0,h=100;for(var o:a){s+=h+l<o?h+l:o;l=o<h?h-o:0;}return s;}
```
[Try it online!](https://tio.run/##ZVDBasMwDL33K0ShkKyOcTJCadK09DLYYafuVjrw2qRxl8TBVgql5Ns92@QyBn6Sn6QnCd34nUe3y48RbS8Vws1yOqBo6Es@@xerhu6MQnYueW641vDBRQfPGUA/fDfiDBo5WneX4gKtzQUHVKK7Hk/A1VWHvhTgU753@DY124gOj6ctVFAYHm2floIuGGks6iJmLK@kCu5cgcx4@NTLol42G7mzNpN5U8hNvasjmbF8VCUOqgOdjyb3g6wSvBRLjZD9WQLAD7YxxR9QwN55TTWqkreBE1DdNwKD@fGLRevTch6GtOW9Xz6wKK@lyrKeK11aFlKUvkUQ5lP/w0Nj2VI5IO3tFbAK5gudweKy6ObEr0Sgorzvm8deu6Z@lXDSjzOH0Rh7AjLBvK4SEq8TRxKTpMQ/9/EFCTOMJMzZeJWSVWqsjVPm4GIstuK1sRWE/QI "Java (JDK) ‚Äì Try It Online")
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 56 bytes
```
f(b)=sum(i=1,#b,min(b[i],100+if(i>1,max(0,100-b[i-1]))))
```
[Try it online!](https://tio.run/##TY3BCsIwDEDvfoXgpcUUkpRSdqg/MnpYD5MeKkMR/PuZpkMMySEvecm2PKu7b/u@mmLT691MTQSXAq0@TJlrBkK81tXUG0FbPgY7cDJxlK1EN2dBcFS2KXnEk1AfGWjijvkPcwDNjmI4iNqs9plZKQKPczw8WYgBonocFElPAXup6H@LSPJ5GjJ9AQ "Pari/GP ‚Äì Try It Online")
[Answer]
# [Kotlin](https://kotlinlang.org), ~~115~~ 101 bytes
shaved off 14 bytes thanks to a helpful user
```
{var s=0;var l=0;for(d in it){var t=Math.min(d,100);t+=Math.min(d-t,l);s+=t;l=100-Math.min(d,100)};s}
```
[Try it online!](https://tio.run/##pZPBToQwEIbvPsWEU5sF0xYREbuJ8eTB@AzVBSV2i4GuiVl5C@PJp/NFsF0QCW4Csk3a0mmZr//M9CnXMlP1iyjgTjwk8krI@40UOi/gHNBlUYjXi2ullxi8JZgPXm/t2ZKT2M7SzGleoBVkCjKNd5ua3wj9eLzOFFq5lBAc60XP5GlX4rhccB1Lbra9wekqLqs63ShYC2PD2yMw7bnIlEaOTkoNFBwcQ5aiwY2RsNe9TZHx4rYdY/s3cA6@WTRuAJDz9fn@ZtxAIsukb/2w1j9ENkb0Q@YCjRgxI2EWeiDRHyOywIWmtxItEcJgNvFkCtFGFShrw2qIjM0nBmNEw2JdCn80si6qUu0jNtb9xNMJRBoanWE/qiyYn8dwjGhpNCC7oYvqIZVzNkUjobZco9/XwQidTYxGK8dWzTCP9B8aq/ob "Kotlin ‚Äì Try It Online")
#### Ungolfed:
```
fun bagelCalculator1(arg: Array<Int>) : Int
{
    var sold = 0
    var left = 0
    for(demand in arg)
    {
        var soldToday = min(demand,100)
                          // V the deficit V
        soldToday += min(demand-soldToday, left)
        sold += soldToday
        left = 100-min(demand,100)
    }
    return sold
}
```
[Answer]
# [PHP](https://php.net/), 79 bytes
```
function b($a){foreach($a as$o){$t+=min(100+$d,$o);$d=max(0,100-$o);}return$t;}
```
And now I want a bagel :)
[Try it online!](https://tio.run/##bZDPCoMwDMbvewqRHip2o@2QIk72INsOnX@oB9viKgzEZ@9SGduhQgLh@yVfQqyy/nK1yh66RpnkiW@MUvLNR3ZK7zqtfuwsOGElD5BHkBdkiz2wGfLYkBJO91QmCiJiJ1BZQUPuzVAGx5Xxetj97/f9rBs3GA0IyWzpzdTJRkGdyBcy2YJcXo@DxnByjloCUoXaepRvvP3kGIR16tw8aeSq1fsP "PHP ‚Äì Try It Online")
[Answer]
# [Pip](https://github.com/dloscutoff/pip), ~~25~~ 23 bytes
```
MN{H[ah+yYMX[h-a0]]}MSg
```
Takes the list of orders-per-day as separate command-line arguments. [Attempt This Online!](https://ato.pxeger.com/run?1=m724ILNgwYKlpSVpuhbbff2qPaITM7QrI30jojN0Ew1iY2t9g9MhslBFW6MNDcx0jEx1DI1NdCwtdSyALKNYqCQA) Or, [verify all test cases](https://ato.pxeger.com/run?1=m724ILNgWbSSbo5S7KbqSAMFjaCAdE09JQVdOwUlPY2lpSVpuhbbff2qPaITM7QrI30jojN0Ew1iY2t9g9MhsjerNWsVfEMVorkUog0NDKyhOBbINTY3sja0NALxjUB8I1NrMIKywSqNwCoNrI0MoAxDc1Nrc7ASIMPQ1ACEoTIGhkDjLMG6gVqBorEQJyxYAKEB).
### Explanation
```
                         ; We store the number of leftovers in y (initially = 0)
                      g  ; List of cmdline args
                    MS   ; Map this function and sum the results:
MN                       ; Apply min to the result of
  {                }     ; This function:
   H                     ;   All but the last element of
    [             ]      ;   This list:
     a                   ;     Function arg (today's number of orders),
      h+y                ;     100 plus yesterday's leftovers,
         Y               ;     and yank the new number of leftovers:
          MX[    ]       ;       Take the max of
             h-a         ;       100 minus function arg
                0        ;       and 0
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 11 bytes
```
»∑2√∞_¬´≈ª+·∏∑·πñ¬´S
```
[Try it online!](https://tio.run/##y0rNyan8///EdqPDG@IPrT66W/vhju0Pd047tDr4/@F2zcj//6MNDQx0oDhWJ9rY3EjH0NIIxDUCco1MdcAIwgQrMwIpM9AxMoDQhuamOuYgeSBtaGoAwhBxA0OgQZYgjUBdBrEA "Jelly ‚Äì Try It Online")
Another handful of ports of [Razetime's BQN](https://codegolf.stackexchange.com/a/241377/85334).
`»∑2` could hypothetically be golfed to `¬≥` if this is used as a function in a program with no command-line arguments, but the existing Jelly corpus seems to discourage this. Modifying the programs to use STDIN has yielded no savings (but thanks to emanresu A for reminding me).
```
»∑2√∞            With 100 as the left argument to a dyadic chain:
    ¬´          Take the minimum of each element of the input and 100,
   _           and subtract each minimum from 100.
     ≈ª         Prepend a 0,
      +·∏∑       add 100 to each,
        ·πñ      remove the last element,
         ¬´     take the pairwise minima with the input,
          S    and sum.
```
# [Jelly](https://github.com/DennisMitchell/jelly), 11 bytes
```
»∑2…ì¬´·πñ·∫°≈ª+…ì¬´S
```
[Try it online!](https://tio.run/##y0rNyan8///EdqOTkw@tfrhz2sNdC4/u1gZxgv8fbteM/P8/2tDAQAeKY3Wijc2NdAwtjUBcIyDXyFQHjCBMsDIjkDIDHSMDCG1obqpjDpIH0oamBiAMETcwBBpkCdII1GUQCwA "Jelly ‚Äì Try It Online")
# [Jelly](https://github.com/DennisMitchell/jelly), 11 bytes
```
»∑2√∞·∏§_¬´·πñ‚Å∏;¬´S
```
[Try it online!](https://tio.run/##y0rNyan8///EdqPDGx7uWBJ/aPXDndMeNe6wPrQ6@P/hds3I//@jDQ0MdKA4Vifa2NxIx9DSCMQ1AnKNTHXACMIEKzMCKTPQMTKA0IbmpjrmIHkgbWhqAMIQcQNDoEGWII1AXQaxAA "Jelly ‚Äì Try It Online")
[Answer]
# [Go](https://go.dev), 106 bytes
```
func(a[]int)(s int){l,h:=0,100
for _,o:=range a{if h+l<o{s+=h+l}else{s+=o}
if o<h{l=h-0}else{l=0}}
return}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=bVHdTsMgGI23PAXuqmTMAEtTt4x38N4YQ5ayVikstPWG9Em8aUx8Gd9gPo3QVtfaJvwezuF8B94_Tqa93J7F8VWcUliIXIO8OBtb3a1kUa0AeBMWSv5ZV3Jzf3mRtT5G4vEp1xWKShgmp3C25wRTQoA0Fj5js-dWaH-dcLmE2VodjCvX3C-aVJVpWJsG-CNzyJzi2Yb0uOKkaYBNq9rqpnf8vvkKll1hEYIOPFjvqXTUleC8Jx56g-UCiPCWEPRPtU0YpjsWGOwqm6CLOhbjrl01fwjCSbxA78pgZCL4xRBmbKYhmI2j9FsUxjmTJrF3HZMHxPPjGd8f0ZiEflWMsMXA4S2of5TdxGSAQlV0ltmHG8fttihkRmD40rbt5x8)
Port of [Olivier's Java solution](https://codegolf.stackexchange.com/a/241536/77309).
[Answer]
# [///](https://esolangs.org/wiki////), 63 bytes
```
/b|/|bbbbb// /bbbb||//b1///b\||1/||//1///b*/*s//*/\/// *//sb// 
```
[Try it online!](https://tio.run/##HYuhDcBADMR4pwgOsbLPk0aqVFAWerunnzfwyeDqu@t9qrmgSaEcwJiVIIOtJQWTpxwvcNYOc6h5dERYDP0D "/// ‚Äì Try It Online")
Takes input appended to the program, as space-separated unary numbers using `1`s; produces output in unary using `s`s.
Or, run a [modified version](https://tio.run/##VZA7bsMwDIZ3nYKzF0pKVde7b@DVSwwF6FBAg7ZA6Bnapo/kLrlTj@D8pBW7FUz@30fJ8CO/7PPzIc8zvxqWshyZHcfE7NEROwnkgyYgLAB6rARs7wh@WhnSbZLkASn@GejERDYUhaK@wlS4TLJEiIVK0Y207I@lJF5GddJwkwUaHnVAjfQ8qWTuB8mhr9AP6@Jh7P@P@Pd64c2h501hP6tBvu8C/qoM/FwQdFICfAgg35GIN/1wSSN0xM8/zs5aqmV2rSfXeRFvfCC9BPSAt8aSt9JdG6gNBt0FKyUz63BzZ3CC7HwD "/// ‚Äì Try It Online") with added pre-processing and post-processing to use decimal numbers in input and output.
## Explanation
```
/b|/|bbbbb/
/ /bbbb||/
```
The first substitution modifies the second substitution's replacement string: each `|` multiplies the number of `b`s by 5 as it passes through them, resulting in `||bbb*‚Ä¶(100)‚Ä¶*bbb`.
Then, the second substitution replaces each space with that string. In addition to the spaces between the input numbers, there is one more space from the end of the program (just before the input), so the string appears at the start of every day, providing the 100 bagels (as `b`s) made for the day and a separator `||`.
```
/b1//
```
Use bagels to fulfil orders made on the same day, removing both.
```
/b\||1/||/
```
Use bagels to fulfil orders made on the next day, removing both. The backslash prevents this code from being modified by the first substitution.
```
/1//
```
Remove unfulfilled orders.
```
/b*/*s/
/*/\//
/ */
```
The last of these three pieces will have already been modified by the second substitution in the program, to `/||bbb*‚Ä¶(100)‚Ä¶*bbb*/`. It is further modified here, becoming `/||*sss*‚Ä¶(100)‚Ä¶*sss/` and then `/||/sss*‚Ä¶(100)‚Ä¶*sss/`, and then executed, replacing each day separator `||` with a hundred `s`s, again producing the number of bagels made that day.
```
/sb//
```
Cancel out bagels made with bagels unsold, leaving the number of bagels sold in `s`s.
[Answer]
# TI-Basic, 26 bytes
```
sum(min(Ans,·¥á2+augment({0},max(0,·¥á2-ŒîList(cumSum(Ans)-Ans
```
Takes input in `Ans`.
]